or — Compute element-wise logical disjunction.
or(A,B) and A | B return true where either corresponding operand is nonzero.
Syntax
tf = or(A, B)Inputs
A- Type
Any- Required
- Yes
- Description
- Logical, real numeric, table, timetable, or supported extension operand.
B- Type
Any- Required
- Yes
- Description
- Logical, real numeric, table, timetable, or supported extension operand.
Returns
tf- Type
Any- Description
- Logical result with the expanded array shape or the input tabular container.
Errors
RunMat:or:InvalidInput- When
- An operand is not supported logical, numeric, character, complex, table, timetable, or resident numeric data.
- Message
or: unsupported input type
RunMat:or:SizeMismatch- When
- Operand shapes are not compatible for implicit expansion, or tabular operands cannot be aligned.
- Message
or: input sizes are not compatible
Truth and shape semantics
or(A,B) converts corresponding elements to zero/nonzero truth values after compatible-size expansion, then returns true where either value is true. Zero is false; every nonzero real value, including NaN, is true. The result is logical and has the expanded shape.
All eight fixed-width integer classes are tested directly in their authoritative storage. Empty shapes propagate without adding elements.
Tables and accelerated execution
For tables and timetables, or operates on corresponding variables. Variable names, row names, and row times may appear in a different order; RunMat aligns them to the first input before evaluation and retains that input's container metadata.
A supported operation on inputs owned by the same provider remains resident. Unsupported provider routes gather exact values; explicitly requested residency is restored only after validating owner, device, shape, storage, and aliasing.
Complex and character operands are available in RunMat mode. The compatibility pin accepts the documented real numeric, logical, table, and timetable forms.
Examples
Combine scalar conditions
tf = or(true, false)Expected output:
tf = trueCombine numeric arrays
A = [1 0 2 0];
B = [3 4 0 0];
tf = or(A, B)Expected output:
tf = [true true true false]Expand a row across a column
tf = or([1; 0], [0 2 0])Expected output:
tf = [true true true; false true false]Treat NaN as nonzero
tf = or(NaN, 0)Expected output:
tf = trueApply disjunction to table variables
T = table([0; 2], [1; 0], 'VariableNames', {'A', 'B'});
R = or(T, 0)Expected output:
R is a table with logical variablesUse complex truth values in RunMat mode
tf = or([0+0i 1+0i], 0+2i)Expected output:
tf = [true true]Keep a supported result resident
A = gpuArray([0 2 0]);
B = gpuArray([1 0 0]);
G = or(A, B);
tf = gather(G)Expected output:
G remains resident and tf = [true true false]Using or with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how or changes the result.
Run a small or example, explain the result, then change one input and compare the output.
FAQ
What does or return?⌄
Scalar operands produce a logical scalar; array operands produce logical arrays; tabular operands retain their table or timetable container with logical variables.
How is NaN interpreted?⌄
NaN is nonzero and therefore true before the logical operation is applied.
Does implicit expansion apply?⌄
Yes. Singleton dimensions expand against compatible dimensions; incompatible array shapes report a size error.
Are integers converted to double?⌄
No. Integer zero/nonzero truth is read directly from each fixed-width class.
How are tables handled?⌄
The operation is applied variable by variable after aligning compatible tabular metadata. The result retains the first tabular input's class and metadata.
Can execution remain on a GPU?⌄
Yes when an exact owning provider supports the operation. Exact fallback preserves explicit gpuArray intent after validating the restored result.
Related Logical functions
Source you can read
Every RunMat function's source is public. Read exactly how or is executed, line by line, in Rust.
- View the source for or in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.