isnumeric — Test numeric storage type in MATLAB and RunMat.
tf = isnumeric(x) returns true when x stores numeric data (real or complex) and false otherwise. Classification behavior follows MATLAB semantics.
Syntax
tf = isnumeric(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input value to test. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when input uses numeric storage. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:isnumeric:InternalError | Internal gather/dispatch path fails. | isnumeric: internal error |
How isnumeric works
- 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.
Does RunMat run isnumeric on the GPU?
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 memory and 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
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 =
0Using isnumeric with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isnumeric changes the result.
Run a small isnumeric example, explain the result, then change one input and compare the output.
FAQ
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.
Related Logical functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isnumeric is executed, line by line, in Rust.
- View the source for isnumeric 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.