View all functions

CategoryLogical: Tests
GPUYes

What does the islogical function do in MATLAB / RunMat?

tf = islogical(x) returns a logical scalar that is true when x is stored as MATLAB logical data (either a scalar logical or an N-D logical array). All other value kinds, including doubles, integers, characters, structs, and objects, return false.

How does the islogical function behave in MATLAB / RunMat?

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

Examples of using the islogical function in MATLAB / RunMat

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

islogical Function GPU Execution Behaviour

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 residency in RunMat (Do I need gpuArray?)

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.

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.

See Also

isreal, isfinite, isnan, gpuArray, gather

Source & Feedback