View all functions

CategoryArray: Introspection
GPUYes

What does the isvector function do in MATLAB / RunMat?

isvector(A) returns logical true when the input is 1-by-N or N-by-1 (including scalars) and has at most two dimensions. The builtin mirrors MATLAB semantics across numeric arrays, logical arrays, characters, strings, cells, structs, objects, and GPU-resident tensors.

How does the isvector function behave in MATLAB / RunMat?

  • isvector is true for 1-by-N and N-by-1 arrays (with N ≥ 0), including scalars (1×1).
  • Arrays with more than two dimensions always return false, even when all trailing dimensions are singleton (for example, 1×1×1).
  • Empty arrays follow MATLAB rules: size 0×1 or 1×0 is a vector, but size 0×3 is not.
  • Character arrays, string arrays, cell arrays, structs, objects, and handle objects follow the same dimension check.
  • GPU tensors use metadata stored in their GpuTensorHandle. If metadata is missing, RunMat gathers once to inspect dimensions.
  • Sparse matrices currently follow dense semantics; when sparse support lands, isvector will continue to rely on reported dimensions.

isvector Function GPU Execution Behaviour

isvector never launches GPU kernels. For gpuArray inputs the builtin first inspects the shape metadata on the GpuTensorHandle. If a provider omits that metadata, RunMat downloads the tensor once to obtain it and then computes the result on the host. The builtin always returns a host logical scalar, so fusion planning treats it as a metadata query instead of a device-side kernel.

GPU residency in RunMat (Do I need gpuArray?)

isvector performs its checks on whatever residency the input already uses. It will happily accept a GPU tensor without the caller moving it to the CPU first, because the builtin only needs the tensor's metadata. When a provider fully populates tensor shapes (as the WGPU provider does), the runtime never downloads the data. If metadata is missing, the runtime gathers once to recover the shape and then continues on the host. Users can still call gpuArray for compatibility with MathWorks MATLAB, but it is not required for this builtin.

Examples of using the isvector function in MATLAB / RunMat

Checking if a row vector input is a vector

tf = isvector([1 2 3]);

Expected output:

tf = logical(1)

Detecting that a matrix is not a vector

tf = isvector([1 2 3; 4 5 6]);

Expected output:

tf = logical(0)

Verifying that a scalar counts as a vector

tf = isvector(42);

Expected output:

tf = logical(1)

Handling empty dimensions exactly like MATLAB

tf_zero_col = isvector(zeros(1,0));
tf_zero_row = isvector(zeros(0,1));
tf_zero_by_three = isvector(zeros(0,3));

Expected output:

tf_zero_col = logical(1)
tf_zero_row = logical(1)
tf_zero_by_three = logical(0)

Working with character and string arrays

tf_char = isvector('RunMat');
tf_string_row = isvector(["a","b","c"]);

Expected output:

tf_char = logical(1)
tf_string_row = logical(1)

Confirming GPU tensor metadata without gathering

G = gpuArray((1:5)');
tf_gpu = isvector(G);

Expected output:

tf_gpu = logical(1)

Rejecting higher-dimensional arrays

tf = isvector(ones(1,1,4));

Expected output:

tf = logical(0)

Trailing singleton dimensions are still rejected

tf = isvector(ones(1,1,1));

Expected output:

tf = logical(0)

FAQ

Does isvector treat scalars as vectors?

Yes. Scalars are 1-by-1 arrays, so they are vectors.

How does isvector handle empty dimensions?

It follows MATLAB rules: size 0-by-1 or 1-by-0 is a vector, but other empty shapes such as 0-by-3 return false.

Are higher-dimensional arrays ever considered vectors?

No. Any array with more than two dimensions returns false, even if the trailing dimensions equal one (for example, 1×1×N).

Do character vectors and string scalars count as vectors?

Yes. Character vectors are 1-by-N arrays, and string scalars are 1-by-1 string arrays, so both return true.

What happens with GPU arrays?

RunMat reads the shape metadata from the GpuTensorHandle. If the provider does not populate that metadata, the runtime gathers the tensor once to inspect its dimensions.

Are cell arrays and structs supported?

Yes. isvector uses the MATLAB-visible dimensions, so any 1-by-N or N-by-1 cell/struct array returns true.

Will isvector launch GPU kernels?

No. The builtin is purely a metadata query and never dispatches GPU work.

Can I rely on isvector inside fused expressions?

Yes. The builtin returns a host logical scalar, so fusion planning treats it as a metadata operation.

Does sparse support change the semantics?

Sparse inputs will follow the same dimension check once sparse tensors are introduced; no behavioural change is expected.

How does isvector interact with isscalar and ismatrix?

isscalar(A) implies isvector(A) but not vice versa. Conversely, ismatrix(A) can be true even when isvector(A) is false.

See Also

isscalar, isempty, length, numel, size, gpuArray, gather