issymmetric — Test matrix symmetry in MATLAB and RunMat.
issymmetric(A) returns true when matrix A is symmetric about its main diagonal. Optional skew-symmetric mode and tolerance behavior follow MATLAB semantics.
Syntax
tf = issymmetric(A)
tf = issymmetric(A, option)
tf = issymmetric(A, flag, tol)
tf = issymmetric(A, tol, flag)Inputs
A- Type
Any- Required
- Yes
- Description
- Input matrix.
option- Type
Any- Required
- No
- Description
- Symmetry flag or tolerance scalar.
flag- Type
Any- Required
- No
- Description
- Symmetry flag (for example "skew" or "symmetric").
tol- Type
NumericScalar- Required
- No
- Description
- Tolerance for element-wise symmetry checks.
Returns
tf- Type
LogicalArray- Description
- True when the matrix satisfies the selected symmetry predicate.
Errors
RunMat:issymmetric:InvalidArgument- When
- Flag/tolerance arguments are malformed, duplicated, or unsupported.
- Message
issymmetric: invalid argument
RunMat:issymmetric:InvalidInput- When
- Input shape/type cannot be interpreted as a numeric or logical 2-D matrix.
- Message
issymmetric: invalid input
RunMat:issymmetric:Internal- When
- Runtime fails while creating internal tensors or coercing values.
- Message
issymmetric: internal runtime failure
Behavior and supported arrays
issymmetric(A) returns true when matrix A is symmetric about its main diagonal. Optional skew-symmetric mode and tolerance behavior follow MATLAB semantics.
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 ishermitian for 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) when skew mode is active.
GPU residency and provider behavior
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.
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.
Falls back to gathering GPU operands when providers lack a device-side symmetry predicate.
Examples
Checking whether a matrix is symmetric
A = [2 1 1; 1 3 4; 1 4 5];
tf = issymmetric(A)Expected output:
tf = logical
1Allowing numerical noise with a tolerance
A = [1 1+1e-12; 1-1e-12 1];
tf = issymmetric(A, 1e-9)Expected output:
tf = logical
1Detecting a skew-symmetric matrix
B = [0 -2 4; 2 0 -3; -4 3 0];
tf = issymmetric(B, 'skew')Expected output:
tf = logical
1Handling non-square matrices
C = [1 2 3; 4 5 6];
tf = issymmetric(C)Expected output:
tf = logical
0Working with complex-valued matrices
Z = [1+2i 3-4i; 3-4i 5+6i];
tf = issymmetric(Z)Expected output:
tf = logical
1Inspecting a GPU-resident matrix
G = gpuArray([0 5; 5 9]);
tf = issymmetric(G)Expected output:
tf = logical
1Using issymmetric with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how issymmetric changes the result.
Run a small issymmetric example, explain the result, then change one input and compare the output.
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).
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 issymmetric is executed, line by line, in Rust.
- View the source for issymmetric 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.