The class "ddiMatrix" of numerical diagonal matrices. Note that diagonal matrices now extend sparseMatrix, whereas they did extend dense matrices earlier.

Objects from the Class

Objects can be created by calls of the form new("ddiMatrix", ...) but typically rather via Diagonal.

Slots

x:

numeric vector. For an \(n \times n\) matrix, the x slot is of length \(n\) or 0, depending on the diag slot:

diag:

"character" string, either "U" or "N" where "U" denotes unit-diagonal, i.e., identity matrices.

Dim,Dimnames:

matrix dimension and dimnames, see the Matrix class description.

Extends

Class "diagonalMatrix", directly. Class "dMatrix", directly. Class "sparseMatrix", indirectly, see showClass("ddiMatrix").

Methods

%*%

signature(x = "ddiMatrix", y = "ddiMatrix"): ...

See also

Class diagonalMatrix and function Diagonal.

Examples

(d2 <- Diagonal(x = c(10,1)))
#> 2 x 2 diagonal matrix of class "ddiMatrix"
#>      [,1] [,2]
#> [1,]   10    .
#> [2,]    .    1
str(d2)
#> Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
#>   ..@ diag    : chr "N"
#>   ..@ Dim     : int [1:2] 2 2
#>   ..@ Dimnames:List of 2
#>   .. ..$ : NULL
#>   .. ..$ : NULL
#>   ..@ x       : num [1:2] 10 1
## slightly larger in internal size:
str(as(d2, "sparseMatrix"))
#> Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
#>   ..@ diag    : chr "N"
#>   ..@ Dim     : int [1:2] 2 2
#>   ..@ Dimnames:List of 2
#>   .. ..$ : NULL
#>   .. ..$ : NULL
#>   ..@ x       : num [1:2] 10 1

M <- Matrix(cbind(1,2:4))
M %*% d2 #> `fast' multiplication
#> 3 x 2 Matrix of class "dgeMatrix"
#>      [,1] [,2]
#> [1,]   10    2
#> [2,]   10    3
#> [3,]   10    4

chol(d2) # trivial
#> 2 x 2 diagonal matrix of class "ddiMatrix"
#>      [,1]     [,2]
#> [1,] 3.162278    .
#> [2,]        .    1
stopifnot(is(cd2 <- chol(d2), "ddiMatrix"),
          all.equal(cd2@x, c(sqrt(10),1)))