What does the ishermitian function do in MATLAB / RunMat?
ishermitian(A) returns logical true when A equals its conjugate transpose (A == A').
The builtin works with real and complex matrices, logical arrays, and scalars.
How does the ishermitian function behave in MATLAB / RunMat?
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.
ishermitian Function GPU Execution Behaviour
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.
Examples of using the ishermitian function in MATLAB / RunMat
How to check if a complex matrix is Hermitian
A = [2 1-3i; 1+3i 5];
tf = ishermitian(A);
Expected output:
tf = logical
1
How 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
1
How to spot a matrix that is not Hermitian
C = [1 2+i; 2-i 1+0.02i];
tf = ishermitian(C);
Expected output:
tf = logical
0
How 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
1
How to test for skew-Hermitian structure
S = [0 2+3i; -2+3i 0];
tf = ishermitian(S, 'skew');
Expected output:
tf = logical
1
How to inspect a GPU-resident matrix
G = gpuArray([3 4-2i; 4+2i 6]);
tf = ishermitian(G);
Expected output:
tf = logical
1
GPU residency in RunMat (Do I need gpuArray?)
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.
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.
See Also
issymmetric, eig, chol, gpuArray, gather
Source & Feedback
- View the source:
crates/runmat-runtime/src/builtins/math/linalg/structure/ishermitian.rs - Found a bug or behavioural difference? Open an issue with details and a minimal repro.