isinf — Determine which array elements are infinite.
isinf returns a same-shaped logical mask that identifies positive or negative infinity in real and complex values.
Syntax
tf = isinf(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Numeric, logical, character, or string input to classify element by element.
Returns
tf- Type
LogicalArray- Description
- Same-shaped logical mask that is true where either numeric component is infinite.
Errors
RunMat:isinf:InvalidInput- When
- Input is sparse or is not numeric, logical, character, or string data.
- Message
isinf: invalid input
RunMat:isinf:InternalError- When
- Internal mask construction, provider execution, or residency restoration fails.
- Message
isinf: internal error
RunMat:isinf:TooManyOutputs- When
- More than one output is requested.
- Message
isinf: too many output arguments
Values and classes
isinf(A) returns true where an element is positive or negative infinity. A complex element is true when either component is infinite; a NaN component does not by itself count as infinite.
Fixed-width integers, logical values, and character code points cannot be infinite and therefore produce false masks. String scalars return false and string arrays produce same-shaped false masks. Sparse and unrelated container values are rejected.
Shape, residency, and fusion
The result is a logical scalar for scalar input and a same-shaped logical array for nonscalar or empty input.
Resident floating input uses the exact owner's logical_isinf operation. A typed unsupported result may gather once and restore the logical output to that owner. Integer input needs no payload download because its class determines an all-false result. Compatible elementwise expressions may fuse.
Examples
Classify an infinite scalar
tf = isinf(1 / 0)Expected output:
tf = trueFind positive and negative infinity
A = [1 Inf; -Inf NaN];
tf = isinf(A)Expected output:
tf = [false true; true false]Classify either complex component
Z = complex([1 Inf NaN], [Inf 0 2]);
tf = isinf(Z)Expected output:
tf = [true true false]Classify character code points
tf = isinf(['R' 'u' 'n'])Expected output:
tf = [false false false]Classify fixed-width integers exactly
A = [intmin('int64'), int64(0), intmax('int64')];
tf = isinf(A)Expected output:
tf = [false false false]Keep the infinity mask resident
A = gpuArray(single([1 -Inf Inf]));
gtf = isinf(A);
tf = gather(gtf)Expected output:
gtf remains a gpuArray and tf = [false true true]Using isinf with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isinf changes the result.
Run a small isinf example, explain the result, then change one input and compare the output.
FAQ
Does NaN count as infinity?⌄
No. Only positive or negative infinity is true. A complex value can independently contain an infinite component and a NaN component.
How are logical, character, and string values classified?⌄
Logical values, character code points, and strings cannot contain infinity, so they produce false values with the corresponding shape.
Are integers converted?⌄
No. An integer class cannot contain infinity, so RunMat constructs the false mask directly.
Does a gpuArray result remain resident?⌄
Yes when the exact owner can execute the operation or restore the fallback result without losing explicit residency.
Can isinf participate in a fused expression?⌄
Yes. The placement and fusion planner can combine compatible elementwise work when the selected provider supports the complete region.
Related Logical functions
Source you can read
Every RunMat function's source is public. Read exactly how isinf is executed, line by line, in Rust.
- View the source for isinf 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.