isa — Test whether a value belongs to a specified MATLAB class or abstract category.
isa(x, T) returns logical true when the value x is a member of the MATLAB class or abstract category identified by T. Use it to branch on numeric vs integer data, handle objects, GPU arrays, function handles, and user-defined classes.
How isa works in RunMat
- 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")returnstrueeven whenclass(obj)reports a subclass name. isaaccepts 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.
How isa runs 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 gpuArrayExpected 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)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".
Related functions to explore
These functions work well alongside isa. Each page has runnable examples you can try in the browser.
class, isnumeric, islogical, gpuArray, gather, ischar, isstring, which, who, whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isa works, line by line, in Rust.
- View isa.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.