What does the isa function do in MATLAB / RunMat?
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 does the isa function behave in MATLAB / 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.
isa Function GPU Execution Behaviour
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 residency in RunMat (Do I need gpuArray?)
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 of using the isa function in MATLAB / RunMat
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)
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".
See Also
class, isnumeric, islogical, isaUnderlying, gpuArray, gather