isvector — Test whether values are vectors in MATLAB and RunMat.
isvector(A) returns true when A is 1-by-N or N-by-1 (including scalars). Dimensionality rules across value types follow MATLAB semantics.
Syntax
tf = isvector(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input value to inspect. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when input is vector-shaped (1-by-N or N-by-1, including scalars). |
How isvector works
isvectoristruefor 1-by-NandN-by-1 arrays (withN ≥ 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×1or1×0is a vector, but size0×3is 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,
isvectorwill continue to rely on reported dimensions.
Does RunMat run isvector on the GPU?
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 memory and residency
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
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)Using isvector with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isvector changes the result.
Run a small isvector example, explain the result, then change one input and compare the output.
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.
Related Array functions
Shape
cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · squeeze · tril · triu · vertcat
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isvector is executed, line by line, in Rust.
- View the source for isvector 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.