R: Virtual Class of Symmetric Matrices in Package Matrix
symmetricMatrix-class
R Documentation
Virtual Class of Symmetric Matrices in Package Matrix
Description
The virtual class of symmetric matrices, "symmetricMatrix",
from the package Matrix contains numeric and logical, dense and
sparse matrices, e.g., see the examples.
The main use is in methods (and C functions) that can deal with
all symmetric matrices.
Slots
uplo:
Object of class "character". Must be
either "U", for upper triangular, and "L", for lower triangular.
Dim, Dimnames:
The dimension (a length-2
"integer") and corresponding names (or NULL),
inherited from the Matrix, see there. See below,
about storing only one of the two Dimnames components.
factors:
a list of matrix factorizations, also from the
Matrix class.
Extends
Class "Matrix", directly.
Methods
coerce
signature(from = "ddiMatrix", to =
"symmetricMatrix"): and many other coercion methods, some of
which are particularly optimized.
dimnames
signature(object = "symmetricMatrix"):
returns symmetricdimnames, even when the
Dimnames slot only has row or column names. This allows to
save storage for large (typically sparse) symmetric matrices.
There's a C function symmetricMatrix_validate()
called by the internal validity checking functions, and also from
getValidity(getClass("symmetricMatrix")).
Validity and dimnames
The validity checks do not require a symmetric Dimnames slot,
so it can be list(NULL, <character>), e.g., for efficiency.
However, dimnames() and other functions and methods
should behave as if the dimnames were symmetric, i.e., with both list
components identical.
See Also
isSymmetric which has efficient methods
(isSymmetric-methods) for the Matrix classes.
Classes triangularMatrix, and, e.g.,
dsyMatrix for numeric dense matrices, or
lsCMatrix for a logical sparse matrix class.
Examples
## An example about the symmetric Dimnames:
sy <- sparseMatrix(i= c(2,4,3:5), j= c(4,7:5,5), x = 1:5, dims = c(7,7),
symmetric=TRUE, dimnames = list(NULL, letters[1:7]))
sy # shows symmetrical dimnames
sy@Dimnames # internally only one part is stored
dimnames(sy) # both parts - as sy *is* symmetrical
showClass("symmetricMatrix")
## The names of direct subclasses:
scl <- getClass("symmetricMatrix")@subclasses
directly <- sapply(lapply(scl, slot, "by"), length) == 0
names(scl)[directly]
## Methods -- applicaple to all subclasses above:
showMethods(classes = "symmetricMatrix")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Matrix)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Matrix/symmetricMatrix-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: symmetricMatrix-class
> ### Title: Virtual Class of Symmetric Matrices in Package Matrix
> ### Aliases: symmetricMatrix-class coerce,matrix,symmetricMatrix-method
> ### coerce,denseMatrix,symmetricMatrix-method
> ### coerce,CsparseMatrix,symmetricMatrix-method
> ### dimnames,symmetricMatrix-method
> ### Keywords: classes
>
> ### ** Examples
>
> ## An example about the symmetric Dimnames:
> sy <- sparseMatrix(i= c(2,4,3:5), j= c(4,7:5,5), x = 1:5, dims = c(7,7),
+ symmetric=TRUE, dimnames = list(NULL, letters[1:7]))
> sy # shows symmetrical dimnames
7 x 7 sparse Matrix of class "dsCMatrix"
a b c d e f g
a . . . . . . .
b . . . 1 . . .
c . . . . . 3 .
d . 1 . . 4 . 2
e . . . 4 5 . .
f . . 3 . . . .
g . . . 2 . . .
> sy@Dimnames # internally only one part is stored
[[1]]
NULL
[[2]]
[1] "a" "b" "c" "d" "e" "f" "g"
> dimnames(sy) # both parts - as sy *is* symmetrical
[[1]]
[1] "a" "b" "c" "d" "e" "f" "g"
[[2]]
[1] "a" "b" "c" "d" "e" "f" "g"
> ## Don't show:
> local({ nm <- letters[1:7]
+ stopifnot(identical(dimnames(sy), list( nm, nm)),
+ identical(sy@Dimnames , list(NULL, nm)))
+ })
> ## End(Don't show)
> showClass("symmetricMatrix")
Virtual Class "symmetricMatrix" [package "Matrix"]
Slots:
Name: uplo factors Dim Dimnames
Class: character list integer list
Extends:
Class "compMatrix", directly
Class "Matrix", by class "compMatrix", distance 2
Class "mMatrix", by class "Matrix", distance 3
Known Subclasses:
Class "dsyMatrix", directly
Class "dspMatrix", directly
Class "lsyMatrix", directly
Class "lspMatrix", directly
Class "nsyMatrix", directly
Class "nspMatrix", directly
Class "dsTMatrix", directly
Class "dsCMatrix", directly
Class "dsRMatrix", directly
Class "lsTMatrix", directly
Class "lsCMatrix", directly
Class "lsRMatrix", directly
Class "nsTMatrix", directly
Class "nsCMatrix", directly
Class "nsRMatrix", directly
Class "dpoMatrix", by class "dsyMatrix", distance 2
Class "dppMatrix", by class "dspMatrix", distance 2
Class "corMatrix", by class "dsyMatrix", distance 3
>
> ## The names of direct subclasses:
> scl <- getClass("symmetricMatrix")@subclasses
> directly <- sapply(lapply(scl, slot, "by"), length) == 0
> names(scl)[directly]
[1] "dsyMatrix" "dspMatrix" "lsyMatrix" "lspMatrix" "nsyMatrix" "nspMatrix"
[7] "dsTMatrix" "dsCMatrix" "dsRMatrix" "lsTMatrix" "lsCMatrix" "lsRMatrix"
[13] "nsTMatrix" "nsCMatrix" "nsRMatrix"
>
> ## Methods -- applicaple to all subclasses above:
> showMethods(classes = "symmetricMatrix")
Function: Schur (package Matrix)
x="symmetricMatrix", vectors="logical"
x="symmetricMatrix", vectors="missing"
Function: coerce (package methods)
from="CsparseMatrix", to="symmetricMatrix"
from="ddiMatrix", to="symmetricMatrix"
from="denseMatrix", to="symmetricMatrix"
from="dgTMatrix", to="symmetricMatrix"
from="dsCMatrix", to="symmetricMatrix"
from="dsTMatrix", to="symmetricMatrix"
from="ldiMatrix", to="symmetricMatrix"
from="lgTMatrix", to="symmetricMatrix"
from="matrix", to="symmetricMatrix"
from="ngTMatrix", to="symmetricMatrix"
from="sparseMatrix", to="symmetricMatrix"
from="triangularMatrix", to="symmetricMatrix"
Function: crossprod (package base)
x="symmetricMatrix", y="ANY"
x="symmetricMatrix", y="Matrix"
x="symmetricMatrix", y="missing"
Function: dimnames (package base)
x="symmetricMatrix"
Function: expm (package Matrix)
x="symmetricMatrix"
Function: isSymmetric (package base)
object="symmetricMatrix"
Function: pack (package Matrix)
x="symmetricMatrix"
Function: skewpart (package Matrix)
x="symmetricMatrix"
Function: symmpart (package Matrix)
x="symmetricMatrix"
Function: tcrossprod (package base)
x="ANY", y="symmetricMatrix"
x="Matrix", y="symmetricMatrix"
Function: unpack (package Matrix)
x="symmetricMatrix"
>
>
>
>
>
> dev.off()
null device
1
>