ishermitian — Test Hermitian structure of matrices in MATLAB and RunMat.
ishermitian(A) returns true when A equals its conjugate transpose. Optional skew-Hermitian mode and tolerance behavior follow MATLAB semantics.
Syntax
tf = ishermitian(A)
tf = ishermitian(A, option)
tf = ishermitian(A, flag, tol)
tf = ishermitian(A, tol, flag)Inputs
A- Type
Any- Required
- Yes
- Description
- Input matrix.
option- Type
Any- Required
- No
- Description
- Hermitian mode flag or tolerance scalar.
flag- Type
Any- Required
- No
- Description
- Mode flag (for example "hermitian" or "skew").
tol- Type
NumericScalar- Required
- No
- Description
- Tolerance for Hermitian comparison checks.
Returns
tf- Type
LogicalArray- Description
- True when the matrix satisfies the selected Hermitian predicate.
Errors
RunMat:ishermitian:InvalidArgument- When
- Flag/tolerance arguments are malformed, duplicated, or unsupported.
- Message
ishermitian: invalid argument
RunMat:ishermitian:InvalidInput- When
- Input shape/type cannot be interpreted as a numeric or logical 2-D matrix.
- Message
ishermitian: invalid input
RunMat:ishermitian:Internal- When
- Runtime fails while creating internal tensors or coercing values.
- Message
ishermitian: internal runtime failure
Behavior and supported arrays
ishermitian(A) returns true when A equals its conjugate transpose. Optional skew-Hermitian mode and tolerance behavior follow MATLAB semantics.
ishermitian(A) tests for Hermitian structure (A == conj(A').).
Pass 'skew' (or 'skewhermitian') to test for skew-Hermitian structure (A == -conj(A')).
Non-square matrices immediately return false.
Diagonal entries must be real for Hermitian matrices and purely imaginary (within tolerance) for skew-Hermitian matrices.
Logical inputs are promoted to double precision before testing.
NaN values anywhere in the matrix cause the predicate to return false.
Additional singleton trailing dimensions are allowed; higher-dimensional inputs with more than two non-singleton axes raise an error.
GPU residency and provider behavior
Manual gpuArray / gather calls are optional. When a provider implements the Hermitian predicate the computation runs entirely on the GPU and only the boolean result is read back. Otherwise the runtime gathers the tensor automatically and evaluates the predicate on the host.
RunMat keeps GPU tensors resident whenever possible. When the active acceleration provider exposes an ishermitian predicate hook the comparison runs entirely on the device and only a logical scalar is transferred back. Providers without a dedicated hook fall back to gathering the matrix and running the CPU implementation transparently, so correctness is preserved even without GPU specialisation.
Falls back to gathering GPU operands when providers lack a device-side Hermitian predicate.
Examples
How to check if a complex matrix is Hermitian
A = [2 1-3i; 1+3i 5];
tf = ishermitian(A)Expected output:
tf = logical
1How to determine that a real matrix is Hermitian
B = [4 2 2; 2 7 3; 2 3 9];
tf = ishermitian(B)Expected output:
tf = logical
1How to spot a matrix that is not Hermitian
C = [1 2+i; 2-i 1+0.02i];
tf = ishermitian(C)Expected output:
tf = logical
0How to allow numerical noise with a tolerance
D = [1 1+1e-12; 1-1e-12 1];
tf = ishermitian(D, 1e-9)Expected output:
tf = logical
1How to test for skew-Hermitian structure
S = [0 2+3i; -2+3i 0];
tf = ishermitian(S, 'skew')Expected output:
tf = logical
1How to inspect a GPU-resident matrix
G = gpuArray([3 4-2i; 4+2i 6]);
tf = ishermitian(G)Expected output:
tf = logical
1Using ishermitian with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ishermitian changes the result.
Run a small ishermitian example, explain the result, then change one input and compare the output.
FAQ
Does ishermitian work with complex matrices?⌄
Yes. Off-diagonal elements are compared against the conjugate transpose, and diagonal elements must be real (for Hermitian) or purely imaginary (for skew-Hermitian) within the supplied tolerance.
What tolerance values are supported?⌄
Pass a finite, non-negative scalar tolerance. The comparison uses the tolerance on the magnitude of the element-wise difference between the matrix and its (signed) conjugate transpose.
Can I test for skew-Hermitian matrices?⌄
Yes. Provide 'skew' or 'skewhermitian' (optionally along with a tolerance) to require A == -conj(A').
How are diagonal elements handled?⌄
For Hermitian matrices the diagonal entries must be real. For skew-Hermitian matrices the diagonal entries must have zero real part. Imaginary parts are unconstrained in skew mode.
How does the builtin treat NaN values?⌄
If any element of the matrix is NaN the predicate returns false, matching MATLAB behaviour.
Do I need to reshape vectors before calling ishermitian?⌄
Vectors are treated as matrices; column vectors are n×1 matrices and row vectors are 1×n matrices. Non-square shapes always return false.
What happens with empty matrices?⌄
Empty square matrices (0×0) return true, whereas empty rectangular matrices return false.
Do I need to call gpuArray to use ishermitian on the GPU?⌄
No. RunMat automatically keeps tensors resident on the GPU when it is profitable. Explicit gpuArray calls remain available for MATLAB compatibility.
Related Linalg functions
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Source you can read
Every RunMat function's source is public. Read exactly how ishermitian is executed, line by line, in Rust.
- View the source for ishermitian in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.