RunMat
GitHub

all — Test whether all elements are nonzero along a dimension in MATLAB and RunMat.

all(X) returns logical true when every element in the selected slice of X is nonzero. By default, all reduces along the first non-singleton dimension; optional dim, "all", and nanflag arguments follow MATLAB semantics.

Syntax

B = all(A)
B = all(A, dim)
B = all(A, "all")
B = all(A, nanflag)
B = all(A, dim, nanflag)
B = all(A, nanflag, dim)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput array.
dimAnyNo[]Dimension selector or vector of dimensions.
allStringScalarNo"all"Reduce across all dimensions.
nanflagStringScalarNo"includenan"NaN handling mode: "includenan" or "omitnan".

Returns

NameTypeDescription
BLogicalArrayLogical reduction result.

Errors

IdentifierWhenMessage
RunMat:all:InvalidArgumentDimension/all/nanflag argument grammar is invalid.all: invalid reduction argument specification
RunMat:all:InvalidInputInput type is unsupported for all reduction.all: unsupported input type
RunMat:all:InternalReduction execution fails due to internal conversion, provider, or shape operations.all: internal reduction failure

How all works

  • Works with logical, numeric, complex, and character arrays; other types raise a descriptive error.
  • Accepts all(X, dim) to reduce along a single dimension or all(X, vecdim) to collapse multiple axes at once.
  • all(X, 'all') flattens the entire array into a single logical scalar.
  • all(___, 'omitnan') ignores NaN values (including complex parts) when deciding whether a slice contains nonzero content; empty or all-NaN slices evaluate to true.
  • all(___, 'includenan') (default) treats NaN as logical true, matching MATLAB behaviour.
  • Empty dimensions yield logical ones with MATLAB-compatible shapes; empty arrays reduced with 'all' return true.
  • Results are always host-resident logical scalars or logical arrays, even when the input tensor lives on the GPU, because the runtime copies the compact output back to the CPU.

Does RunMat run all on the GPU?

RunMat Accelerate keeps inputs resident on the GPU whenever possible. Providers that expose reduce_all_dim (and optionally reduce_all) perform the AND-reduction on device buffers, and the runtime then downloads the tiny logical result back to the CPU. When those hooks are missing, RunMat gathers the input tensor and evaluates the reduction on the host instead, preserving MATLAB behaviour in all cases.

GPU memory and residency

You usually do not need to call gpuArray manually. The fusion planner keeps GPU-resident inputs on the device and only gathers the small logical results that all produces. If your workload already uses explicit gpuArray/gather calls for MATLAB compatibility, RunMat honours them and still produces correct logical outputs.

Examples

Checking if every column is nonzero

A = [1 2 3; 4 5 6];
colAllNonZero = all(A)

Expected output:

colAllNonZero = [1 1 1]

Verifying that each row contains only nonzero values

B = [1 0 3; 4 5 6; 0 7 8];
rowAllNonZero = all(B, 2)

Expected output:

rowAllNonZero = [0; 1; 0]

Collapsing multiple dimensions with vecdim

C = reshape(1:24, [3 4 2]);
allAlongDims = reshape(all(C > 0, [1 2]), 1, 2)

Expected output:

1 1

Reducing all elements to a single logical scalar

D = [2 4; 6 8];
everythingNonZero = all(D, 'all')

Expected output:

everythingNonZero = true

Ignoring NaN values while testing slices

E = [NaN 1 2; NaN 0 3];
withNaN = all(E);               % returns [1 0 1]
ignoringNaN = all(E, 'omitnan'); % returns [1 0 1]
disp(withNaN);
disp(ignoringNaN)

Expected output:

1 0 1
1 0 1

Evaluating all on GPU arrays

G = gpuArray([1 1 1; 1 1 1]);
gpuResult = all(G, 2);     % RunMat returns a host logical array
disp(gpuResult)

Expected output:

1
1

Testing all with character arrays

chars = ['a' 0 'c'];
allPrintable = all(chars);
disp(allPrintable)

Expected output:

0

Using all with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how all changes the result.

Run a small all example, explain the result, then change one input and compare the output.

FAQ

When should I use the all function?

Use all whenever you need to confirm that every element of an array, row, column, or sub-array is nonzero or logical true.

Does all always return logical values?

Yes. Results are logical scalars or logical arrays even when the computation involves GPU inputs.

How do I test a specific dimension?

Pass the dimension as the second argument (for example, all(X, 2) reduces each row). Provide a vector such as [1 3] to collapse multiple axes.

What does all(X, 'all') compute?

It reduces across every dimension of X and returns a single logical scalar indicating whether every element of the entire array is nonzero.

How are NaN values handled?

By default they count as nonzero ('includenan'). Add 'omitnan' to ignore them; if every element in a slice is NaN, the result becomes true.

Does all work with complex numbers?

Yes. Complex values are considered nonzero when either the real or imaginary component is nonzero. Complex values containing NaN obey the 'omitnan'/'includenan' rules.

Can I apply all to character arrays?

Yes. Characters compare against their Unicode code points; zero-valued code points are treated as false, and everything else is true.

What happens with empty inputs?

Empty reductions follow MATLAB semantics: dimensions of length zero produce logical ones, while all(X, 'all') over an empty array evaluates to true.

How do GPU backends accelerate all?

Providers may expose specialised AND-reduction kernels (reduce_all_dim, reduce_all) or use fused_reduction to remain on the device. When such hooks are absent, RunMat downloads the small output and computes on the host.

Reduction

any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh

Signal

blackman · conv · conv2 · deconv · filter · hamming · hann · sawtooth · sinc · square

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · pinv · rank · rcond

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how all is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.