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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input value to inspect. |
type_name | StringScalar | Yes | — | Class or abstract type name. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when input belongs to the requested class/category. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | 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 and logical arrays satisfy
"logical"and do not register as"numeric". Internally auto-resident logical masks retain those host categories, while explicit gpuArray values expose the gpuArray wrapper instead. - 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.- Resident inputs never need to be gathered. Only explicit user-visible residency matches
"gpuArray"; internal automatic residency matches its underlying host class and categories.
Does RunMat run isa on the GPU?
isa never launches GPU kernels. Explicit gpuArray inputs satisfy only the public wrapper identity "gpuArray"; internal automatic residency remains transparent and satisfies its underlying host class and categories. Because the builtin returns a host logical scalar from metadata, it does not participate in fusion and providers need no 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)Checking explicit gpuArray wrapper identity
G = gpuArray(rand(1024, 1024));
tf_gpu = isa(G, "gpuArray");
tf_numeric = isa(G, "numeric")Expected output:
tf_gpu = logical(1)
tf_numeric = logical(0)Inspecting the underlying type of an explicit GPU mask
G = gpuArray(rand(5) > 0.5);
is_wrapper = isa(G, "gpuArray");
is_mask = isUnderlyingType(G, "logical")Expected output:
is_wrapper = logical(1)
is_mask = logical(1)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?⌄
An explicit gpuArray exposes its wrapper identity and matches "gpuArray", not the underlying numeric categories. RunMat's internal automatic residency remains transparent and matches the underlying host class and categories. Use isUnderlyingType to inspect an explicit gpuArray's element type.
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 Introspection functions
addprop · assignin · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · evalc · feval · findprop · getcallinfo · inputParser · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · notify · onCleanup · stats · str2func · superclasses · underlyingType · verLessThan · version · which · who · whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isa is executed, line by line, in Rust.
- View the source for isa 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.