Learn R Programming

Matrix (version 1.5-4)

isSymmetric-methods: Methods for Function 'isSymmetric' in Package 'Matrix'

Description

isSymmetric tests whether its argument is a symmetric square matrix, by default tolerating some numerical fuzz and requiring symmetric [dD]imnames in addition to symmetry in the mathematical sense. isSymmetric is a generic function in base, which has a method for traditional matrices of implicit class "matrix". Methods are defined here for various proper and virtual classes in Matrix, so that isSymmetric works for all objects inheriting from virtual class "Matrix".

Usage

# S4 method for symmetricMatrix
isSymmetric(object, ...)
# S4 method for triangularMatrix
isSymmetric(object, checkDN = TRUE, ...)
# S4 method for diagonalMatrix
isSymmetric(object, checkDN = TRUE, ...)
# S4 method for indMatrix
isSymmetric(object, checkDN = TRUE, ...)
# S4 method for dgeMatrix
isSymmetric(object, tol = 100 * .Machine$double.eps, tol1 = 8 * tol, checkDN = TRUE, ...)
# S4 method for lgeMatrix
isSymmetric(object, checkDN = TRUE, ...)
# S4 method for ngeMatrix
isSymmetric(object, checkDN = TRUE, ...)
# S4 method for dgCMatrix
isSymmetric(object, tol = 100 * .Machine$double.eps, checkDN = TRUE, ...)
# S4 method for lgCMatrix
isSymmetric(object, checkDN = TRUE, ...)
# S4 method for ngCMatrix
isSymmetric(object, checkDN = TRUE, ...)

Value

A logical, either TRUE or FALSE

(never NA).

Arguments

object

a "Matrix".

tol, tol1

numerical tolerances allowing approximate symmetry of numeric (rather than logical) matrices. See also isSymmetric.matrix.

checkDN

a logical indicating whether symmetry of the Dimnames slot of object should be checked.

...

further arguments passed to methods (typically methods for all.equal).

Details

The Dimnames slot of object, say dn, is considered to be symmetric if and only if

  • dn[[1]] and dn[[2]] are identical or one is NULL; and

  • ndn <- names(dn) is NULL or ndn[1] and ndn[2] are identical or one is the empty string "".

Hence list(a=nms, a=nms) is considered to be symmetric, and so too are list(a=nms, NULL) and list(NULL, a=nms).

Note that this definition is looser than that employed by isSymmetric.matrix, which requires dn[1] and dn[2] to be identical, where dn is the dimnames attribute of a traditional matrix.

See Also

forceSymmetric; symmpart and skewpart; virtual class "symmetricMatrix" and its subclasses.

Examples

Run this code
isSymmetric(Diagonal(4)) # TRUE of course
M <- Matrix(c(1,2,2,1), 2,2)
isSymmetric(M) # TRUE (*and* of formal class "dsyMatrix")
isSymmetric(as(M, "generalMatrix")) # still symmetric, even if not "formally"
isSymmetric(triu(M)) # FALSE

## Look at implementations:
showMethods("isSymmetric", includeDefs = TRUE) # includes S3 generic from base

Run the code above in your browser using DataLab