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
A- Type
Any- Required
- Yes
- Description
- Value inspected without payload materialization.
type_name- Type
StringScalar- Required
- Yes
- Description
- Class or abstract type designator as string scalar or character row.
Returns
tf- Type
LogicalArray- Description
- Host logical scalar class/category membership result.
Errors
- When
- Second argument is not a string scalar or row character vector.
- Message
isa: TYPE must be a string scalar or character vector
Behavior
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") 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.
Resident inputs never need to be gathered. Only explicit user-visible residency matches "gpuArray"; internal automatic residency matches its underlying host class and categories.
GPU and residency
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.
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.
Returns host logical scalars and inspects resident metadata without launching kernels. Explicit gpuArray values expose wrapper identity; internal automatic residency exposes underlying host class/category semantics.
Legacy examples and displayed results
Checking whether a scalar is double precision
tf = isa(42, "double")
Expected display: 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 display: 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 display: 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 display: 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 display: 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 display: 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 display: tf_handle = logical(1)
tf_listener = logical(1)
Example
Inspect a type with an assertion
tf = isa(42,"double")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
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · func2str · functions · get.p · getcallinfo · getmethod · inputname · inputParser · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · which · who · whos
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.