View all functions

CategoryLogical: Tests
GPUYes

What does the isnumeric function do in MATLAB / RunMat?

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) returns true, including complex scalars.
  • Real and complex numeric arrays return true regardless of dimensionality or residency on the CPU or GPU.
  • gpuArray values rely on provider metadata: numeric handles return true, while logical masks constructed on the GPU return false.
  • Logical values, characters, strings, tables, cell arrays, structs, objects, and function handles return false.
  • The result is always a logical scalar.

Examples of using the isnumeric function in MATLAB / RunMat

Checking if a scalar double is numeric

tf = isnumeric(42);

Expected output:

tf =
     1

Detecting numeric matrices

A = [1 2 3; 4 5 6];
tf = isnumeric(A);

Expected output:

tf =
     1

Testing complex numbers for numeric storage

z = 1 + 2i;
tf = isnumeric(z);

Expected output:

tf =
     1

Logical arrays are not numeric

mask = logical([1 0 1]);
tf = isnumeric(mask);

Expected output:

tf =
     0

Character 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 =
     0

Evaluating 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 =
     0

isnumeric Function GPU Execution Behaviour

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 in RunMat (Do I need gpuArray?)

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.

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.

See Also

islogical, isreal, isfinite, gpuArray, gather

Source & Feedback