istriu — Determine whether a matrix is upper triangular in MATLAB and RunMat.
istriu(A) returns true when every element below the main diagonal of matrix A is zero.
Syntax
tf = istriu(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input numeric, logical, complex, sparse, or gpuArray matrix. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when the input matrix satisfies the requested structure predicate. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:istriu:InvalidInput | Input cannot be interpreted as a supported numeric, logical, sparse, complex, or gpuArray matrix. | istriu: invalid input |
RunMat:istriu:Internal | Runtime fails while gathering GPU input or constructing an internal matrix view. | istriu: internal runtime failure |
How istriu works
- Scalars are upper triangular.
- Diagonal and all-zero matrices are upper triangular.
- Rectangular matrices are supported.
- Dense real, logical, complex, sparse, and gpuArray inputs are supported.
- Complex entries count as nonzero when either real or imaginary part is nonzero.
- NaN values count as nonzero when testing matrix structure.
- Arrays with a non-singleton dimension beyond the second return
false, matching MATLAB matrix-predicate behavior.
Does RunMat run istriu on the GPU?
istriu is registered as a structure-analysis fusion sink. GPU-resident real/logical inputs use provider bandwidth (lower == 0) instead of gathering the full matrix when the active provider supports it.
GPU memory and residency
The result is always a host logical scalar. For real/logical gpuArray inputs, RunMat keeps the matrix on the provider and uses the bandwidth hook to read back only lower/upper bandwidth metadata. Complex-interleaved GPU inputs and providers without bandwidth support fall back to the host path.
Examples
Checking an upper-triangular matrix
A = [1 2 3; 0 4 5; 0 0 6];
tf = istriu(A)Expected output:
tf = logical
1Detecting a value below the main diagonal
B = [1 0; 7 2];
tf = istriu(B)Expected output:
tf = logical
0Checking a rectangular matrix
C = [1 2 3; 0 4 5];
tf = istriu(C)Expected output:
tf = logical
1Inspecting a GPU-resident matrix
G = gpuArray(triu(ones(3)));
tf = istriu(G)Expected output:
tf = logical
1Using istriu with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how istriu changes the result.
Run a small istriu example, explain the result, then change one input and compare the output.
FAQ
What entries does istriu inspect?⌄
Only entries below the main diagonal can make the predicate false.
Are diagonal matrices upper triangular?⌄
Yes. Diagonal matrices have zeros below the main diagonal, so istriu returns true.
How are sparse matrices handled?⌄
RunMat scans stored sparse entries without densifying and returns false only when a stored nonzero appears below the main diagonal.
Related Linalg functions
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · symrcm
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how istriu is executed, line by line, in Rust.
- View the source for istriu 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.