le — Compute element-wise less-than-or-equal comparisons in MATLAB and RunMat.
le(A, B) (or A <= B) compares inputs element-wise for less-than-or-equal relations. Scalar expansion and output-shape behavior follow MATLAB semantics.
Syntax
tf = le(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 less-than-or-equal result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:le:InvalidInput | Operands contain unsupported types or mixed numeric/string domains. | le: mixing numeric and string inputs is not supported |
RunMat:le:SizeMismatch | Operands are not broadcast-compatible. | le: array sizes are not compatible for broadcasting |
How le 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' <= 65). - String scalars and string arrays compare lexically; implicit expansion works across string dimensions.
- Complex numeric inputs are ordered by their real components and return logical results.
- All integer classes can be compared, including mixed numeric classes, without first collapsing exact integer values through double precision.
- Categorical values use their categorical ordering when the categorical comparison path applies.
- Mixed numeric/string inputs raise MATLAB-compatible type errors.
Does RunMat run le on the GPU?
Compatible resident operand pairs use the exact common owner's validated elem_le path and return a resident logical result. If either operand is host-resident, the owners differ, or the provider path cannot represent the comparison safely, RunMat gathers resident inputs automatically, evaluates the full comparison semantics on the host, and restores the logical result to the first resident source provider. Explicit gpuArray inputs must remain resident or the call errors.
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
Check Whether A Scalar Value Meets A Maximum
flag = le(17, 42)Expected output:
flag =
1Create A Mask For Matrix Values Below Or Equal To A Threshold
M = [1 2 3; 4 5 6];
mask = le(M, 3)Expected output:
mask =
2×3 logical array
1 1 1
0 0 0Apply Less-Equal With Implicit Expansion
v = [1 3 5 7];
mask = le(v, [2 6])Expected output:
mask =
1×4 logical array
1 1 0 0Compare Character Data To Numeric Codes With Equality Support
letters = ['A' 'B' 'C'];
isBeforeOrB = le(letters, 66)Expected output:
isBeforeOrB =
1×3 logical array
1 1 1Compare String Arrays Lexicographically Allowing Equality
names = ["alice" "charlie" "bob"];
earlierOrSame = le(names, "bob")Expected output:
earlierOrSame =
1×3 logical array
1 0 1Run le Directly On gpuArray Inputs
G1 = gpuArray([1 4 7]);
G2 = gpuArray([2 4 8]);
deviceResult = le(G1, G2);
hostResult = gather(deviceResult)Expected output:
deviceResult =
1×3 gpuArray logical array
1 1 1
hostResult =
1×3 logical array
1 1 1Using le with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how le changes the result.
Run a small le example, explain the result, then change one input and compare the output.
FAQ
Does le 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 le?⌄
Yes. Relational ordering uses the real components of complex numeric values and returns logical results.
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. Compatible resident pairs use the provider's validated elem_le result. Mixed or unsupported cases gather transparently, compare on the host, and restore the logical result to the source provider; explicit gpuArray residency must be preserved.
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 le 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 le is executed, line by line, in Rust.
- View the source for le 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.