RunMat
GitHub

class — Return class names for values in MATLAB and RunMat.

class(x) returns the class name for value x as a string scalar. Use it for diagnostics, branching, and display logic with MATLAB- and RunMat-compatible class labels.

Syntax

name = class(A)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput value to inspect.

Returns

NameTypeDescription
nameStringScalarClass name for the input value.

How class works

  • Real or complex double-precision inputs (including empty numeric arrays) report "double". Integer scalars or tensors report their narrow class such as "int16" or "uint8".
  • Logical scalars and arrays report "logical". Character arrays return "char", while string scalars or arrays return "string".
  • Cell arrays, structs, and user-defined classdef objects report "cell", "struct", or the class name that defined the object.
  • Function handles and anonymous closures both report "function_handle". Listeners return "event.listener".
  • gpuArray values report "gpuArray" without gathering data. Use classUnderlying if you need the element type of the device array.
  • Handle objects, including deleted handles, return the class name that introduced the handle. Metadata-only values such as classref("Point") report "meta.class".

Does RunMat run class on the GPU?

class is an introspection-only builtin. When the input resides on the GPU, RunMat reads the residency metadata, returns the class name immediately, and leaves the data in place. No kernels are launched and no buffers are copied back to the CPU, so providers do not need to expose any hooks.

GPU memory and residency

You do not need to call gpuArray purely to query a value’s class. The auto-offload planner keeps tensors on the GPU whenever profitable, and class simply returns the residency-aware class name without altering where the data lives. Explicit gpuArray and gather calls remain available for compatibility with MATLAB code that manages residency manually.

Examples

Check the class of a numeric scalar

c = class(42)

Expected output:

c = "double"

Inspect the class of a string array

names = ["Ada", "Grace", "Edsger"];
class_name = class(names)

Expected output:

class_name = "string"

Determine whether a cell array stays typed as a cell

cells = {1, "two", 3};
cell_class = class(cells)

Expected output:

cell_class = "cell"

Detect the class of gpuArray data without gathering

G = gpuArray(rand(4));
g_class = class(G)

Expected output:

g_class = "gpuArray"

Report the class name of a custom object

P = classref("Point").origin();
point_class = class(P)

Expected output:

point_class = "Point"

Using class with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how class changes the result.

Run a small class example, explain the result, then change one input and compare the output.

FAQ

Does class return a string or a character array?

class returns a string scalar, matching modern MATLAB behaviour. Convert the result with char(class(...)) if you need a legacy character row vector.

How do I check whether a value is numeric?

Use isa(x, "numeric") to handle floats, complex numbers, and integers. class reports the concrete class ("double", "int32", and so on).

Will class gather gpuArray inputs?

No. RunMat inspects metadata and returns "gpuArray" immediately; buffers stay on the device.

What does class return for handle objects?

class returns the object’s defining class name (for example "MyHandleClass"). Use isa(h, "handle") to test for handle semantics.

What happens if I pass a struct or cell array?

Structs return "struct" and cell arrays return "cell", matching MATLAB.

What is the class of function handles?

Both named function handles and anonymous closures report "function_handle".

Can I distinguish string and char arrays?

Yes. class("hello") yields "string" while class('hello') yields "char".

What about metadata objects such as classref?

Calling class(classref("Point")) returns "meta.class". Use the returned meta-class object to inspect properties or superclasses.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how class is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.