gt — Compute element-wise greater-than comparisons in MATLAB and RunMat.
gt(A, B) (or A > B) compares inputs element-wise for strict greater-than relations. Scalar expansion and output-shape behavior follow MATLAB semantics.
Syntax
tf = gt(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 result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:gt:InvalidInput | Operands contain unsupported types or mixed numeric/string domains. | gt: mixing numeric and string inputs is not supported |
RunMat:gt:SizeMismatch | Operands are not broadcast-compatible. | gt: array sizes are not compatible for broadcasting |
RunMat:gt:ComplexNotSupported | At least one operand is complex. | gt: complex numbers are not supported |
How gt works
- 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' > 60). - 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.
Does RunMat run gt on the GPU?
When both operands are gpuArray values and the active acceleration provider implements the elem_gt 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.
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
Determine Whether One Scalar Exceeds Another
flag = gt(42, 17)Expected output:
flag =
1Filter Matrix Elements Greater Than a Threshold
M = [1 2 3; 4 5 6];
mask = gt(M, 3)Expected output:
mask =
2×3 logical array
0 0 0
1 1 1Apply Greater-Than With Implicit Expansion
v = [1 3 5 7];
mask = gt(v, [2 6])Expected output:
mask =
1×4 logical array
0 0 1 1Compare Character Data to Numeric Codes
letters = ['A' 'B' 'C'];
isAfterB = gt(letters, 66)Expected output:
isAfterB =
1×3 logical array
0 0 1Compare String Arrays Lexicographically
names = ["alice" "charlie" "bob"];
later = gt(names, "bob")Expected output:
later =
1×3 logical array
0 1 0Run gt Directly On gpuArray Inputs
G1 = gpuArray([1 4 7]);
G2 = gpuArray([0 5 6]);
deviceResult = gt(G1, G2);
hostResult = gather(deviceResult)Expected output:
deviceResult =
1×3 gpuArray logical array
1 0 1
hostResult =
1×3 logical array
1 0 1Using gt with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how gt changes the result.
Run a small gt example, explain the result, then change one input and compare the output.
FAQ
Does gt 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 gt?⌄
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_gt, 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 gt 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 gt is executed, line by line, in Rust.
- View the source for gt 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.