isinf — Return a logical mask indicating which elements of the input are ±Inf.
mask = isinf(x) returns a logical scalar or array indicating which elements of x are positive or negative infinity. The output matches MATLAB's semantics for scalars, matrices, higher-dimensional tensors, strings, logical arrays, and gpuArray values.
How isinf works in RunMat
- Numeric scalars return a logical scalar (
true/false). - Numeric arrays return a logical array of the same size, with
truewherever the corresponding element is+Infor-Inf. - Complex inputs report
truewhen either the real or the imaginary component is infinite. - Logical inputs return
falsebecause logical values (0 or 1) are finite by construction. - Character arrays return logical arrays of zeros (characters map to finite code points).
- String arrays return logical arrays of zeros, mirroring MATLAB behavior.
stringscalars (string objects) return a logical scalarfalse.- When the input is a
gpuArray, RunMat keeps the computation on the device if the active acceleration provider implements thelogical_isinfhook; otherwise the runtime gathers the data back to the host automatically.
How isinf runs on the GPU
When RunMat Accelerate is active, isinf looks for the provider hook logical_isinf. Providers that implement the hook execute the infinity test entirely on the GPU, producing a logical gpuArray result without any host transfers. If the hook is absent, RunMat gathers the input tensor back to the CPU, computes the mask on the host, and returns a regular logical array so the builtin always succeeds.
GPU memory and residency
You usually do **not** need to call gpuArray explicitly. RunMat's auto-offload planner keeps tensors on the GPU across fused expressions when that improves performance. You can still seed residency manually with gpuArray for compatibility with MATLAB scripts or when you want fine-grained control over data movement.
Examples
Checking if a scalar is infinite
result = isinf(1/0)Expected output:
result =
1Detecting infinities after division by zero
A = [1 0; 2 0];
quot = 1 ./ A;
mask = isinf(quot)Expected output:
mask =
2×2 logical array
0 1
0 1Flagging infinite components of a complex array
Z = [Inf+0i 1-Inf*1i 2+3i];
mask = isinf(Z)Expected output:
mask =
1×3 logical array
1 1 0Applying isinf to character data
chars = ['R' 'u' 'n'];
mask = isinf(chars)Expected output:
mask =
1×3 logical array
0 0 0Running isinf directly on the GPU
G = gpuArray([1 -Inf Inf]);
mask_gpu = isinf(G);
mask = gather(mask_gpu)Expected output:
mask =
1×3 logical array
0 1 1FAQ
Does isinf treat NaN values as infinite?
No. isinf only reports true for IEEE positive or negative infinity. NaN values return false, so you can combine isinf with isnan when you need to distinguish between the two.
What does isinf return for logical inputs?
Logical inputs always produce false because logical values are limited to 0 or 1, which are finite.
How does isinf handle complex numbers?
It returns true when either the real or the imaginary component is infinite, matching MATLAB semantics.
Does isinf move data between the CPU and GPU?
Only when necessary. If the selected provider implements logical_isinf, all work stays on the GPU. Otherwise, RunMat gathers the tensor to the host, computes the result, and delivers a logical array.
What happens with string or character inputs?
String scalars return false. Character arrays and string arrays return logical zeros with the same shape as the input.
Is there a performance difference between isinf, isnan, and isfinite?
Each predicate performs a single elementwise test. Performance is dominated by memory bandwidth, so they have comparable cost on both CPU and GPU.
Related functions to explore
These functions work well alongside isinf. Each page has runnable examples you can try in the browser.
isfinite, isnan, isreal, gpuArray, gather, isgpuarray, islogical, isnumeric
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isinf works, line by line, in Rust.
- View isinf.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.