ge — Compute element-wise greater-than-or-equal comparisons in MATLAB and RunMat.
ge(A, B) (or A >= B) compares inputs element-wise for greater-than-or-equal relations. Scalar expansion and output-shape behavior follow MATLAB semantics.
Syntax
tf = ge(A, B)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Left operand. |
B | Any | Yes | — | Right operand. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | Logical greater-than-or-equal result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:ge:InvalidInput | Operands contain unsupported types or mixed numeric/string domains. | ge: mixing numeric and string inputs is not supported |
RunMat:ge:SizeMismatch | Operands are not broadcast-compatible. | ge: array sizes are not compatible for broadcasting |
How ge works
- Numeric, logical, and character inputs compare element-wise using MATLAB's implicit expansion rules. All eight integer classes are supported without converting authoritative integer values through f64.
- Character arrays compare by Unicode code point; mixing them with numeric arrays behaves like comparing numeric codes (
'A' >= 65). - String scalars and string arrays compare lexically; implicit expansion works across string dimensions.
- Complex inputs compare their real parts; imaginary components do not participate in ordering.
- Mixed numeric/string inputs raise type errors.
- Categorical comparison is implemented through the categorical helper. String/cellstr, table, timetable, and complete right-hand object-overload parity remain pending.
Does RunMat run ge on the GPU?
When resident operands can use the provider's elem_ge hook without changing their value domain, RunMat executes on the device. Otherwise it gathers, performs an exact host comparison, and uploads a logical result to the original handle's owning provider.
GPU memory and residency
You usually do not need to call gpuArray explicitly. RunMat's native auto-offload planner keeps intermediate results on the GPU when fused expressions benefit from device execution. Explicit gpuArray and gather calls remain available for compatibility with MATLAB code that manages residency manually.
Examples
Test Whether One Scalar Is Greater Than or Equal To Another
flag = ge(42, 42)Expected output:
flag =
1Keep Matrix Elements Above or Equal To A Threshold
M = [1 2 3; 4 5 6];
mask = ge(M, 3)Expected output:
mask =
2×3 logical array
0 0 1
1 1 1Apply Greater-Equal With Implicit Expansion
v = [1 3 5 7];
mask = ge(v, 3)Expected output:
mask =
1×4 logical array
0 1 1 1Compare Character Data To Numeric Codes
letters = ['A' 'B' 'C'];
isAfterOrB = ge(letters, 66)Expected output:
isAfterOrB =
1×3 logical array
0 1 1Compare String Arrays Lexicographically With Equality Support
names = ["alice" "charlie" "bob"];
laterOrSame = ge(names, "bob")Expected output:
laterOrSame =
1×3 logical array
0 1 1Run ge Directly On gpuArray Inputs
G1 = gpuArray([1 4 6]);
G2 = gpuArray([1 5 6]);
deviceResult = ge(G1, G2);
hostResult = gather(deviceResult)Expected output:
deviceResult =
1×3 gpuArray logical array
1 0 1
hostResult =
1×3 logical array
1 0 1Using ge with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ge changes the result.
Run a small ge example, explain the result, then change one input and compare the output.
FAQ
Does ge return logical values?⌄
Yes. Scalars return true or false. Arrays return logical arrays, and gpuArray inputs return gpuArray logical outputs.
How are NaN values treated?⌄
Any comparison involving NaN returns false, matching MATLAB behaviour.
Can I compare complex numbers with ge?⌄
Yes. Ordering compares the real parts and ignores imaginary components.
How are strings compared?⌄
String scalars and arrays compare lexicographically using Unicode code points, with full support for implicit expansion against scalar strings.
Are character vectors treated as numbers or text?⌄
Character arrays participate as numeric code points when compared to numeric inputs, and they are converted to strings when compared against string scalars or arrays.
Do I need to gather results manually after a GPU comparison?⌄
No. Native comparisons return a resident logical result. Correctness fallbacks gather, compare on authoritative host storage, and upload the logical result to the owning provider.
Does implicit expansion apply to string arrays?⌄
Yes. String arrays support MATLAB-style implicit expansion, so you can compare against scalar strings without manual replication.
Can I fuse ge inside GPU expressions?⌄
Yes. The builtin registers element-wise fusion metadata so the planner can fuse comparisons with surrounding GPU-friendly operations.
Related Logical functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ge is executed, line by line, in Rust.
- View the source for ge in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.