isvector — Return true when an array is 1-by-N or N-by-1 (including scalars).
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 isvector works in RunMat
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.
How isvector runs 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)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 functions to explore
These functions work well alongside isvector. Each page has runnable examples you can try in the browser.
isscalar, isempty, length, numel, size, gpuArray, gather, ismatrix, ndims
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isvector works, line by line, in Rust.
- View isvector.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.