What does the ge function do in MATLAB / RunMat?
ge(A, B) (or the infix A >= B) performs an element-wise greater-than-or-equal comparison. The result is a logical scalar when the broadcasted shape contains one element, or a logical array otherwise.
How does the ge function behave in MATLAB / RunMat?
- Numeric, logical, and character inputs compare element-wise using MATLAB's implicit expansion rules.
- 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 are not supported, matching MATLAB's behaviour.
- Mixed numeric/string inputs raise MATLAB-compatible type errors.
ge Function GPU Execution Behaviour
When both operands are gpuArray values and the active acceleration provider implements the elem_ge hook, RunMat executes the comparison entirely on the device and returns a gpuArray logical result. If the provider does not expose this hook, the runtime gathers the inputs to host memory automatically and performs the CPU comparison instead of failing.
Examples of using the ge function in MATLAB / RunMat
Test Whether One Scalar Is Greater Than or Equal To Another
flag = ge(42, 42);
Expected output:
flag =
1
Keep 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 1
Apply Greater-Equal With Implicit Expansion
v = [1 3 5 7];
mask = ge(v, [2 6]);
Expected output:
mask =
1×4 logical array
0 0 1 1
Compare Character Data To Numeric Codes
letters = ['A' 'B' 'C'];
isAfterOrB = ge(letters, 66);
Expected output:
isAfterOrB =
1×3 logical array
0 1 1
Compare String Arrays Lexicographically With Equality Support
names = ["alice" "charlie" "bob"];
laterOrSame = ge(names, "bob");
Expected output:
laterOrSame =
1×3 logical array
0 1 1
Run 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 1
GPU residency in RunMat (Do I need gpuArray?)
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.
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?
No. MATLAB does not define relational ordering for complex numbers, so RunMat raises a MATLAB-compatible error when complex inputs are supplied.
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. When both inputs are gpuArray values and the provider supports elem_ge, the result stays on the GPU. Otherwise, RunMat gathers inputs transparently and returns a host logical array.
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.
See Also
Source & Feedback
- The full source code for the implementation of the
gefunction is available at:crates/runmat-runtime/src/builtins/logical/rel/ge.rs - Found a bug or behavioural difference? Please open an issue with details and a minimal repro.