RunMat
GitHub

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

NameTypeRequiredDefaultDescription
AAnyYesInput value to test.

Returns

NameTypeDescription
tfLogicalArrayTrue when input uses logical storage.

Errors

IdentifierWhenMessage
RunMat:islogical:InternalErrorInternal gather/dispatch path fails.islogical: internal error

How islogical works

  • Logical scalars (true, false) return true.
  • Instances of logical arrays return true, regardless of dimensionality.
  • Numeric, complex, string, character, struct, cell, and object inputs return false.
  • gpuArray values return true when 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 =
     1

Verifying a logical array constructed with logical

mask = logical([1 0 1 0]);
is_mask_logical = islogical(mask)

Expected output:

is_mask_logical =
     1

Numeric arrays are not logical

values = [1 2 3];
is_logical = islogical(values)

Expected output:

is_logical =
     0

Character arrays return false

chars = ['R' 'u' 'n'];
is_char_logical = islogical(chars)

Expected output:

is_char_logical =
     0

gpuArray comparisons yield logical gpuArrays

G = gpuArray([1 2 3]);
mask = G > 1;
tf = islogical(mask)

Expected output:

tf =
     1

Containers 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 =
     0

Using 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.

Bit

and · not · or · xor

Rel

eq · ge · gt · isequal · le · lt · ne

Logical

logical

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how islogical 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.