diagonalMatrix-class {Matrix} | R Documentation |
Class "diagonalMatrix" is the virtual class of all diagonal matrices.
A virtual Class: No objects may be created from it.
diag
:code"character" string, either "U"
or
"N"
, where "U"
means ‘unit-diagonal’.
Dim
:matrix dimension, and
Dimnames
:the dimnames
, a
list
, see the Matrix
class
description. Typically list(NULL,NULL)
for diagonal matrices.
Class "sparseMatrix"
, directly.
These are just a subset of the signature for which defined methods. Currently, there are (too) many explicit methods defined in order to ensure efficient methods for diagonal matrices.
signature(from = "matrix", to = "diagonalMatrix")
: ...
signature(from = "Matrix", to = "diagonalMatrix")
: ...
signature(from = "diagonalMatrix", to = "generalMatrix")
: ...
signature(from = "diagonalMatrix", to = "triangularMatrix")
: ...
signature(from = "diagonalMatrix", to = "nMatrix")
: ...
signature(from = "diagonalMatrix", to = "matrix")
: ...
signature(from = "diagonalMatrix", to = "sparseVector")
: ...
signature(x = "diagonalMatrix")
: ...
signature(x = "dgeMatrix", y = "diagonalMatrix")
: ...
signature(x = "matrix", y = "diagonalMatrix")
: ...
signature(x = "diagonalMatrix", y = "matrix")
: ...
signature(x = "diagonalMatrix", y = "dgeMatrix")
: ...
signature(x = "diagonalMatrix", y = "dgeMatrix")
: ...
and many more methods
signature(a = "diagonalMatrix", b, ...)
: is
trivially implemented, of course.
signature(x = "nMatrix")
, semantically
equivalent to base function which(x, arr.ind)
.
signature(e1 = "ddiMatrix", e2="denseMatrix")
:
arithmetic and other operators from the Ops
group have a few dozen explicit method definitions, in order to
keep the results diagonal in many cases, including the following:
signature(e1 = "ddiMatrix", e2="denseMatrix")
:
the result is from class ddiMatrix
which is
typically very desirable. Note that when e2
contains
off-diagonal zeros or NA
s, we implicitly use 0 / x = 0, hence
differing from traditional R arithmetic (where 0/0 |-> NaN), in order to preserve sparsity.
ddiMatrix
and ldiMatrix
are
“actual” classes extending "diagonalMatrix"
.
I5 <- Diagonal(5) D5 <- Diagonal(x = 10*(1:5)) ## trivial (but explicitly defined) methods: stopifnot(identical(crossprod(I5), I5), identical(tcrossprod(I5), I5), identical(crossprod(I5, D5), D5), identical(tcrossprod(D5, I5), D5), identical(solve(D5), solve(D5, I5)), all.equal(D5, solve(solve(D5)), tol = 1e-12) ) solve(D5)# efficient as is diagonal # an unusual way to construct a band matrix: rbind2(cbind2(I5, D5), cbind2(D5, I5))