RunMat
GitHub

isa — Test class/category membership in MATLAB and RunMat.

isa(x, T) returns true when value x belongs to class or abstract category T. Supported class/category checks and type coercions follow MATLAB semantics.

Syntax

tf = isa(A, type_name)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput value to inspect.
type_nameStringScalarYesClass or abstract type name.

Returns

NameTypeDescription
tfLogicalArrayTrue when input belongs to the requested class/category.

Errors

IdentifierWhenMessage
Second argument is not a string scalar or row character vector.isa: TYPE must be a string scalar or character vector

How isa works

  • Exact class names (such as "double", "cell", "struct", "event.listener") match the value’s dynamic class. Comparisons are case-insensitive.
  • Abstract categories ("numeric", "float", "integer", "handle", "function_handle", "gpuArray", "listener") mirror MATLAB’s grouping rules.
  • Logical scalars, logical arrays, and logical gpuArray masks satisfy "logical" and do not register as "numeric". RunMat consults handle metadata rather than downloading device buffers.
  • Handle inheritance is respected: if a class derives from handle, isa(obj, "handle") returns true even when class(obj) reports a subclass name.
  • isa accepts either a string scalar or a character row vector as the class designator.
  • gpuArray inputs never need to be gathered; RunMat checks residency metadata to answer the query.

Does RunMat run isa on the GPU?

isa never launches GPU kernels. For gpuArray inputs RunMat inspects the GpuTensorHandle metadata to identify the device array and satisfy category checks such as "numeric" and "gpuArray". Because the builtin only returns a host logical scalar it does not participate in fusion, and providers do not need to expose additional hooks.

GPU memory and residency

You usually do NOT need to call gpuArray yourself in RunMat (unlike MATLAB).

In RunMat, the fusion planner keeps residency on GPU in branches of fused expressions. As such, when you call isa on a gpuArray result, the planner preserves the device buffer and isa answers the query using metadata only.

To preserve backwards compatibility with MathWorks MATLAB, and for when you want to explicitly bootstrap GPU residency, you can call gpuArray explicitly to move data to the GPU if you want to be explicit about the residency.

Since MathWorks MATLAB does not have a fusion planner, and they kept their parallel execution toolbox separate from the core language, as their toolbox is a separate commercial product, MathWorks MATLAB users need to call gpuArray to move data to the GPU manually whereas RunMat users can rely on the fusion planner to keep data on the GPU automatically.

Examples

Checking whether a scalar is double precision

tf = isa(42, "double")

Expected output:

tf = logical(1)

Testing numeric arrays against the numeric category

A = rand(3, 4);
is_numeric = isa(A, "numeric");
is_integer = isa(A, "integer")

Expected output:

is_numeric = logical(1)
is_integer = logical(0)

Confirming that gpuArray data counts as numeric

G = gpuArray(rand(1024, 1024));
tf_numeric = isa(G, "numeric");
tf_double = isa(G, "double");   % false — the class reports gpuArray

Expected output:

tf_numeric = logical(1)
tf_double = logical(0)

Determining whether a GPU mask is logical

G = gpuArray(rand(5) > 0.5);
is_mask = isa(G, "logical");
is_numeric = isa(G, "numeric")

Expected output:

is_mask = logical(1)
is_numeric = logical(0)

Validating handle subclasses

pt = pkg.TestHandle();          % derives from handle
tf_handle = isa(pt, "handle");
tf_exact = isa(pt, "pkg.TestHandle")

Expected output:

tf_handle = logical(1)
tf_exact = logical(1)

Comparing string scalars and character vectors

s = "RunMat";
c = 'RunMat';
tf_string = isa(s, "string");
tf_char = isa(c, "char")

Expected output:

tf_string = logical(1)
tf_char = logical(1)

Detecting function handles and listeners

fh = @sin;
tf_handle = isa(fh, "function_handle");
lst = addlistener(TestSource, "Changed", @disp);
tf_listener = isa(lst, "listener")

Expected output:

tf_handle = logical(1)
tf_listener = logical(1)

Using isa with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how isa changes the result.

Run a small isa example, explain the result, then change one input and compare the output.

FAQ

Does isa treat gpuArray values as numeric?

Yes for numeric device arrays. isa(gpuArray(rand(4)), "numeric") and isa(..., "float") return true, even though the concrete class is "gpuArray". Logical gpuArray masks skip the numeric categories and only satisfy "logical". Use isa(..., "double") when you specifically need host doubles.

How do I check for integer types?

Use the "integer" category. It matches MATLAB’s native integer classes (int8, uint16, and so on). For example isa(int32(5), "integer") returns true while isa(5, "integer") returns false.

Does isa understand handle inheritance?

Yes. If a class derives from handle, then the object passes the "handle" category check. The builtin walks parent classes registered with RunMat to mirror MATLAB semantics.

What kinds of strings can I pass as the type name?

Provide either a string scalar (double quotes) or a character row vector (single quotes). Multi-row character arrays and string arrays with more than one element throw a descriptive error.

How do I detect function handles or anonymous functions?

Both named function handles and closures pass isa(value, "function_handle").

Will isa gather gpuArray inputs or launch kernels?

No. The builtin is metadata-only and returns a host logical scalar without copying device buffers.

How are listeners treated?

Event listeners pass both isa(listener, "event.listener") and the compatibility alias isa(listener, "listener"). They also satisfy the "handle" category.

Does isa differentiate between string and char arrays?

Yes. String scalars pass "string" while character arrays pass "char". They are not interchangeable.

Can I use isa to test meta-class values?

Yes. Meta-class references created with classref return true for "meta.class".

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isa is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.