isUnderlyingType — Test whether a value has a specified underlying MATLAB data type.
isUnderlyingType(X, typename) returns true when underlyingType(X) equals typename. The type name must be a string scalar or a character row vector.
Syntax
tf = isUnderlyingType(X, typename)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Input array or object to inspect. |
typename | StringScalar | Yes | — | Underlying data type name to test. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when X has the requested underlying type. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:isUnderlyingType:TypeNameInvalid | Second argument is not a string scalar or row character vector. | isUnderlyingType: TYPENAME must be a string scalar or character vector |
How isUnderlyingType works
- The predicate compares against the same canonical type names returned by
underlyingType, such as"double","single","logical","char","string","cell", and object class names. - The
typenameinput accepts a string scalar or a character row vector. Multi-element string arrays, multi-row character arrays, and non-text values throw a structured argument error. - gpuArray inputs are checked from handle metadata. Exact class-name metadata is preferred for uploaded integer and floating-point device arrays; provider precision is used as a fallback for handles that only expose F32/F64.
isUnderlyingType(X, typename)compares the requested type name exactly after trimming surrounding whitespace.
Does RunMat run isUnderlyingType on the GPU?
No provider hook is required. RunMat maps gpuArray class-name, logical, and precision metadata to the same names returned by underlyingType and compares that name exactly with the requested type.
GPU memory and residency
isUnderlyingType is metadata-only for gpuArray inputs. It returns a host logical scalar and preserves provider residency for the inspected buffer.
Examples
Check a single-precision array
A = single([1 2 3]);
tf = isUnderlyingType(A, "single")Expected output:
tf = logical(1)Reject a mismatched underlying type
tf = isUnderlyingType(true, "double")Expected output:
tf = logical(0)Check gpuArray element type without gathering
G = gpuArray(single([1 2 3]));
tf = isUnderlyingType(G, "single")Expected output:
tf = logical(1)Using isUnderlyingType with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isUnderlyingType changes the result.
Run a small isUnderlyingType example, explain the result, then change one input and compare the output.
FAQ
Is this the same as isa(X, typename)?⌄
No. isa tests the class or category of the value itself. isUnderlyingType tests the data type returned by underlyingType, which differs for gpuArray values.
What text forms are accepted for typename?⌄
Use a string scalar such as "double" or a character row vector such as 'double'. Non-scalar string arrays and multi-row character arrays are rejected.
Will this gather gpuArray data?⌄
No. The predicate reads class-name, logical, and precision metadata from the gpuArray handle and returns a host logical scalar.
Related Introspection functions
addprop · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · evalc · findprop · getcallinfo · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · onCleanup · stats · superclasses · underlyingType · verLessThan · version · which · who · whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isUnderlyingType is executed, line by line, in Rust.
- View the source for isUnderlyingType 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.