What does the issymmetric function do in MATLAB / RunMat?
issymmetric(A) returns logical true when a numeric or logical matrix A is symmetric
about its main diagonal (A == A.') and false otherwise.
How does the issymmetric function behave in MATLAB / RunMat?
- Works with scalars, vectors (treated as matrices), and higher-rank arrays whose trailing dimensions are singleton (MATLAB-compatible matrix semantics). An error is raised when the input has more than two non-singleton dimensions.
- Non-square matrices immediately return
false. - Logical inputs are promoted to double precision (
true → 1.0,false → 0.0) before testing. - Complex inputs are compared without conjugation; use
ishermitianfor conjugate symmetry. - Floating-point tolerance can be supplied to account for numerical noise.
- Pass
'skew'to test skew-symmetry (A == -A.'). Diagonal entries must be zero (within the tolerance) whenskewmode is active.
issymmetric Function GPU Execution Behaviour
RunMat keeps GPU tensors resident whenever feasible. When the active acceleration provider
exposes a symmetry predicate hook (issymmetric), the test runs entirely on the device and
returns a host logical scalar. Providers without that hook gracefully fall back to downloading
the matrix, so results remain correct even without GPU specialisation.
Examples of using the issymmetric function in MATLAB / RunMat
Checking whether a matrix is symmetric
A = [2 1 1; 1 3 4; 1 4 5];
tf = issymmetric(A);
Expected output:
tf = logical
1
Allowing numerical noise with a tolerance
A = [1 1+1e-12; 1-1e-12 1];
tf = issymmetric(A, 1e-9);
Expected output:
tf = logical
1
Detecting a skew-symmetric matrix
B = [0 -2 4; 2 0 -3; -4 3 0];
tf = issymmetric(B, 'skew');
Expected output:
tf = logical
1
Handling non-square matrices
C = [1 2 3; 4 5 6];
tf = issymmetric(C);
Expected output:
tf = logical
0
Working with complex-valued matrices
Z = [1+2i 3-4i; 3-4i 5+6i];
tf = issymmetric(Z);
Expected output:
tf = logical
1
Inspecting a GPU-resident matrix
G = gpuArray([0 5; 5 9]);
tf = issymmetric(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 symmetry hook,
RunMat executes the predicate in-place on the GPU and only transfers the scalar result.
Otherwise the runtime gathers the tensor transparently and reuses the CPU path, preserving
correctness with a minor residency cost.
FAQ
Does issymmetric accept tolerance arguments?
Yes. Pass a non-negative scalar tolerance as the second or third argument. The comparison uses an absolute tolerance on the element-wise difference (or sum for skew tests).
What strings are accepted for the skew flag?
Use 'skew' to test skew-symmetry and 'nonskew' (or omit the flag) for the default
symmetry test.
How are diagonal elements handled in skew mode?
Diagonal elements must be zero (within the tolerance) because a skew-symmetric matrix
satisfies A(i,i) = -A(i,i).
Are NaN values considered symmetric?
No. Any NaN encountered off or on the diagonal causes the test to return false, matching
MATLAB behaviour.
Do logical matrices work?
Yes. Logical inputs are promoted to double precision and checked using the same rules as numeric matrices.
Does issymmetric conjugate complex inputs?
No. The builtin compares complex entries without conjugation. Use ishermitian if you
need conjugate symmetry.
What happens with higher-dimensional arrays?
issymmetric raises an error when the input has more than two non-singleton dimensions.
Reshape the data to a 2-D matrix before calling it.
Can I combine the skew flag and tolerance?
Yes. You can call issymmetric(A, 'skew', tol) or issymmetric(A, tol, 'skew'). The order
of the optional arguments does not matter.
Is an empty matrix symmetric?
Yes. Empty square matrices (0x0) return logical true, while non-square empty matrices
return false.
Does the result depend on GPU availability?
No. You receive the same logical answer regardless of whether a GPU provider is registered. Only the execution strategy changes (device-side predicate vs. host fallback).
See Also
bandwidth, chol, eig, gpuArray, gather
Source & Feedback
- View the source:
crates/runmat-runtime/src/builtins/math/linalg/structure/issymmetric.rs - Found a bug or behavioural difference? Open an issue with details and a minimal repro.