islogical — Test logical storage type in MATLAB and RunMat.
tf = islogical(x) returns true when x uses logical storage and false otherwise. Classification behavior follows MATLAB semantics.
Syntax
tf = islogical(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input value to test. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when input uses logical storage. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:islogical:InternalError | Internal gather/dispatch path fails. | islogical: internal error |
How islogical works
- Logical scalars (
true,false) returntrue. - Instances of
logicalarrays returntrue, regardless of dimensionality. - Numeric, complex, string, character, struct, cell, and object inputs return
false. gpuArrayvalues returntruewhen their residency metadata marks them as logical; the builtin never gathers device buffers just to answer the query unless metadata is absent.- The result is always a logical scalar.
Does RunMat run islogical on the GPU?
When RunMat Accelerate is active, islogical first asks the registered acceleration provider for the logical_islogical hook. Providers that implement the hook respond using device metadata without copying data back to the CPU. If the hook is missing, RunMat consults its own residency metadata and only gathers device buffers as a last resort, ensuring that the builtin always succeeds while minimizing host↔device transfers.
GPU memory and residency
You typically do not need to call gpuArray manually. RunMat's auto-offload planner keeps logical masks resident on the GPU when downstream expressions benefit from device execution. Explicit gpuArray and gather calls remain available for compatibility with MATLAB code that manages residency explicitly.
Examples
Checking a logical scalar
flag = islogical(true)Expected output:
flag =
1Verifying a logical array constructed with logical
mask = logical([1 0 1 0]);
is_mask_logical = islogical(mask)Expected output:
is_mask_logical =
1Numeric arrays are not logical
values = [1 2 3];
is_logical = islogical(values)Expected output:
is_logical =
0Character arrays return false
chars = ['R' 'u' 'n'];
is_char_logical = islogical(chars)Expected output:
is_char_logical =
0gpuArray comparisons yield logical gpuArrays
G = gpuArray([1 2 3]);
mask = G > 1;
tf = islogical(mask)Expected output:
tf =
1Containers and structs are not logical
items = {true, 1};
person = struct("name", "Ada");
tf_cell = islogical(items);
tf_struct = islogical(person)Expected output:
tf_cell =
0
tf_struct =
0Using islogical with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how islogical changes the result.
Run a small islogical example, explain the result, then change one input and compare the output.
FAQ
Does islogical ever return an array?⌄
No. The builtin always returns a logical scalar, even when the input is an array.
Does islogical convert numeric data to logical?⌄
No. It only reports whether the storage is already logical. Use the logical builtin to convert numeric data explicitly.
How does islogical behave with gpuArray inputs?⌄
If the provider exposes logical_islogical, the check happens entirely on the GPU. When the hook is absent, RunMat consults residency metadata and, if needed, gathers the value to host memory to inspect its storage kind.
Are character or string arrays considered logical?⌄
No. Character vectors, string scalars, and string arrays are not logical values and therefore return false.
Do cell arrays or structs ever count as logical?⌄
No. Containers such as cell arrays, structs, tables, and objects always return false.
Does a logical gpuArray gathered back to the host stay logical?⌄
Yes. When residency metadata marks the handle as logical, gathering produces a host logical array, and islogical continues to report true.
Related Logical functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how islogical is executed, line by line, in Rust.
- View the source for islogical 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.