allfinite — Return true when every element of the input is finite.
tf = allfinite(A) returns a scalar logical indicating whether every element of A is finite. It is equivalent to applying isfinite to the whole input and reducing the mask with all(...,'all').
Syntax
tf = allfinite(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input value to test for finite elements. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when every element of the input is finite. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:allfinite:InvalidInput | Input is not numeric, logical, char, or string. | allfinite: expected numeric, logical, char, or string input |
RunMat:allfinite:InternalError | A GPU provider, gather, download, or internal shape operation fails. | allfinite: internal error |
How allfinite works
- Numeric scalars return
truefor finite values andfalseforNaNorInf. - Numeric arrays return a scalar logical over all elements; empty numeric arrays return
true. - Complex inputs return
trueonly when every real and imaginary component is finite. - Sparse inputs inspect stored nonzero values; implicit zeros are finite.
- Logical and character arrays return
true. - String scalars and nonempty string arrays return
false; empty string arrays returntrue. - Cell arrays, structs, objects, and function handles are rejected with
RunMat:allfinite:InvalidInput.
Does RunMat run allfinite on the GPU?
allfinite is a scalar predicate over the full input. gpuArray inputs use provider-side isfinite plus all reduction when available; the scalar logical result is returned on the CPU. Providers without those hooks fall back to host gather and reduction.
Examples
Check a finite matrix
tf = allfinite([1 2; 3 4])Expected output:
tf =
1Detect nonfinite values
tf = allfinite([1 NaN Inf])Expected output:
tf =
0Check complex values
tf = allfinite([1+2i 3-4i])Expected output:
tf =
1Using allfinite with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how allfinite changes the result.
Run a small allfinite example, explain the result, then change one input and compare the output.
FAQ
How is allfinite(A) different from isfinite(A)?⌄
isfinite returns an element-wise logical mask. allfinite returns a single logical scalar for the whole input.
Are empty arrays all finite?⌄
Yes. The result follows MATLAB-style all identity behavior: reducing an empty finite mask gives true.
How does allfinite handle complex numbers?⌄
A complex value is finite only when both its real and imaginary components are finite.
Related Logical functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how allfinite is executed, line by line, in Rust.
- View the source for allfinite 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.