RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • all
    • any
    • bounds
    • cummax
    • cummin
    • cumprod
    • cumsum
    • cumtrapz
    • diff
    • gradient
    • max
    • maxk
    • mean
    • median
    • min
    • mink
    • movmax
    • movmean
    • movmedian
    • movmin
    • movprod
    • movstd
    • movsum
    • movvar
    • nnz
    • prod
    • rms
    • std
    • sum
    • trapz
    • var

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

any(X) returns logical true when at least one element in the selected slice of X is nonzero. By default, any reduces along the first non-singleton dimension and ignores NaN; dim, vecdim, and "all" follow the MATLAB-compatible contract, while explicit nanflag arguments are available only in RunMat mode.

Syntax

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

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Input 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:any:InvalidArgumentDimension/all/nanflag argument grammar is invalid.any: invalid reduction argument specification
RunMat:any:InvalidInputInput type is unsupported for any reduction.any: unsupported input type
RunMat:any:InternalReduction execution fails due to internal conversion, provider, or shape operations.any: internal reduction failure

How any works

  • Works with logical, numeric, complex, and character arrays; other types raise a descriptive error.
  • Accepts any(X, dim) to reduce along a single dimension or any(X, vecdim) to collapse multiple axes at once.
  • any(X, 'all') flattens the entire array into a single logical scalar.
  • Typed integer data and integer dim or vecdim selectors accept all eight built-in integer classes and always return logical results.
  • NaN values are ignored by default, including complex values with a NaN component.
  • RunMat mode adds explicit any(___, 'omitnan') and any(___, 'includenan') forms; MATLAB-compatible modes reject those flags.
  • Empty dimensions yield logical zeros with MATLAB-compatible shapes; empty arrays reduced with 'all' return false.
  • 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 any on the GPU?

RunMat Accelerate keeps inputs resident on the GPU whenever possible. Providers that expose reduce_any_dim (and optionally reduce_any) perform the OR-reduction on device buffers, and the runtime then downloads the tiny logical result back to the CPU (every any call returns a host logical array). 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 any 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 any column in a matrix is nonzero

A = [0 2 0; 0 0 0];
colHasData = any(A)

Expected output:

colHasData = [0 1 0]

Detecting whether any row contains a nonzero entry

B = [0 4 0; 1 0 0; 0 0 0];
rowHasData = any(B, 2)

Expected output:

rowHasData = [1; 1; 0]

Reducing across multiple dimensions with vecdim

C = reshape(1:24, [3 4 2]);
hasValues = reshape(any(C > 20, [1 2]), 1, 2)

Expected output:

0 1

Checking all elements with the 'all' option

D = [0 0; 0 5];
anyNonZero = any(D, 'all')

Expected output:

anyNonZero = true

Observing the default NaN behavior

E = [NaN 0 0; 0 0 0];
hasValues = any(E);
disp(hasValues)

Expected output:

0 0 0

Running any on GPU arrays with automatic fallback

G = gpuArray([0 1 0; 0 0 0]);
gpuResult = any(G, 2);
hostResult = gather(gpuResult);
disp(hostResult)

Expected output:

1
0

Evaluating any on character data

chars = ['a' 0 'c'];
hasPrintable = any(chars)

Expected output:

hasPrintable = 1

Using any with coding agents

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

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

FAQ

When should I use the any function?⌄

Use any whenever you need to know if any element of an array, row, column, or sub-array is nonzero or logical true.

Does any 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, any(X, 2) reduces each row). Provide a vector such as [1 3] to collapse multiple axes.

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

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

How are NaN values handled?⌄

They are ignored by default. RunMat mode additionally accepts explicit 'omitnan' and 'includenan' flags; MATLAB-compatible modes reject those extension forms.

Does any 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 any 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 zeros, while any(X, 'all') over an empty array evaluates to false.

How do GPU backends accelerate any?⌄

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

Related Math functions

Reduction

all · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8

Trigonometry

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

Structure

bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm

Signal

blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · decomposition · eig · eigs · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Optim

coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone

Ops

cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Symbolic

digits · int · limit · piecewise · sym · syms · vpa

Fft

fft · fft2 · fftn · fftshift · ifft · ifft2 · ifftn · ifftshift

Interpolation

griddedInterpolant · interp1 · interp1q · interp2 · pchip · ppval · spline

Discrete

lcm · primes

Ode

ode15s · ode23 · ode45

Poly

polyder · polyfit · polyint · polyval · roots

Open-source implementation

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

  • View the source for any 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How any works
  • Does RunMat run any on the GPU?
  • GPU memory and residency
  • Examples
  • Checking if any column in a matrix is nonzero
  • Detecting whether any row contains a nonzero entry
  • Reducing across multiple dimensions with vecdim
  • Checking all elements with the 'all' option
  • Observing the default NaN behavior
  • Running any on GPU arrays with automatic fallback
  • Evaluating any on character data
  • Using any with coding agents
  • FAQ
  • Related Math functions
  • Reduction
  • Elementwise
  • Trigonometry
  • Structure
  • Signal
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Discrete
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat