isnumeric — Return true when a value is stored as numeric data (real or complex).
tf = isnumeric(x) returns a logical scalar that is true when x stores numeric data and false otherwise. Numeric data includes doubles, singles, integers, and complex numbers, as well as dense numeric arrays that live on the CPU or GPU.
How does the isnumeric function behave in MATLAB / RunMat?
- Every built-in numeric class (
double,single, signed/unsigned integer types) returnstrue, including complex scalars. - Real and complex numeric arrays return
trueregardless of dimensionality or residency on the CPU or GPU. gpuArrayvalues rely on provider metadata: numeric handles returntrue, while logical masks constructed on the GPU returnfalse.- Logical values, characters, strings, tables, cell arrays, structs, objects, and function handles return
false. - The result is always a logical scalar.
GPU behavior
When RunMat Accelerate is active, isnumeric first checks provider metadata via the logical_islogical hook to determine whether a gpuArray handle was created as a logical mask. Providers that supply the hook can answer the query without copying data back to the host. When the hook is absent, RunMat consults its residency metadata and only gathers the value to host memory when the residency tag is missing, ensuring the builtin always succeeds.
GPU residency
You generally do **not** need to call gpuArray manually. RunMat's auto-offload planner keeps numeric tensors on the GPU across fused expressions whenever that improves performance. Explicit gpuArray and gather calls remain available for compatibility with MATLAB scripts that manage residency themselves.
Examples of using isnumeric in MATLAB / RunMat
Checking if a scalar double is numeric
tf = isnumeric(42)Expected output:
tf =
1Detecting numeric matrices
A = [1 2 3; 4 5 6];
tf = isnumeric(A)Expected output:
tf =
1Testing complex numbers for numeric storage
z = 1 + 2i;
tf = isnumeric(z)Expected output:
tf =
1Logical arrays are not numeric
mask = logical([1 0 1]);
tf = isnumeric(mask)Expected output:
tf =
0Character vectors and strings return false
chars = ['R' 'u' 'n'];
name = "RunMat";
tf_chars = isnumeric(chars);
tf_string = isnumeric(name)Expected output:
tf_chars =
0
tf_string =
0Evaluating gpuArray inputs
G = gpuArray(rand(4));
mask = G > 0.5;
tf_numeric = isnumeric(G);
tf_mask = isnumeric(mask)Expected output:
tf_numeric =
1
tf_mask =
0FAQ
Does isnumeric ever return an array?
No. The builtin always returns a logical scalar, even when the input is an array.
Are complex tensors considered numeric?
Yes. Real and complex tensors both return true, matching MATLAB semantics.
Does isnumeric gather GPU data back to the host?
Only when residency metadata is unavailable. Providers that expose type metadata let RunMat answer the query without host↔device transfers.
Do logical masks return true?
No. Logical scalars and logical arrays return false. Use islogical if you need to detect logical storage explicitly.
What about character vectors or string arrays?
They return false, just like in MATLAB. Characters and strings are text types rather than numeric arrays.
Do cell arrays or structs ever count as numeric?
No. Containers and objects always return false.
Is there a difference between CPU and GPU numeric arrays?
No. Both host and device numeric arrays return true; only logical GPU handles report false.
See also
islogical, isreal, isfinite, gpuArray, gather
Source & Feedback
- Source code: `crates/runmat-runtime/src/builtins/logical/tests/isnumeric.rs`
- Found a bug? Open an issue with a minimal reproduction.