Triangular, dense, numeric matrices
dtrMatrix-class-dense.RdThe "dtrMatrix" class is the class of triangular, dense,
numeric matrices in nonpacked storage. The "dtpMatrix" class
is the same except in packed storage, see pack().
Slots
uplo:Object of class
"character". Must be either "U", for upper triangular, and "L", for lower triangular.diag:Object of class
"character". Must be either"U", for unit triangular (diagonal is all ones), or"N"; seetriangularMatrix.x:Object of class
"numeric". The numeric values that constitute the matrix, stored in column-major order.Dim:Object of class
"integer". The dimensions of the matrix which must be a two-element vector of non-negative integers.
Extends
Class "ddenseMatrix", directly.
Class "triangularMatrix", directly.
Class "Matrix" and others, by class "ddenseMatrix".
Methods
Among others (such as matrix products, e.g. ?crossprod-methods),
- norm
signature(x = "dtrMatrix", type = "character"): ..- rcond
signature(x = "dtrMatrix", norm = "character"): ..- solve
signature(a = "dtrMatrix", b = "...."): efficiently use a “forwardsolve” orbacksolvefor a lower or upper triangular matrix, respectively, see alsosolve-methods.- +, -, *, ..., ==, >=, ...
all the
Opsgroup methods are available. When applied to two triangular matrices, these return a triangular matrix when easily possible.
See also
Classes ddenseMatrix, dtpMatrix,
triangularMatrix
Examples
(m <- rbind(2:3, 0:-1))
#> [,1] [,2]
#> [1,] 2 3
#> [2,] 0 -1
(M <- as(m, "generalMatrix"))
#> 2 x 2 Matrix of class "dgeMatrix"
#> [,1] [,2]
#> [1,] 2 3
#> [2,] 0 -1
(T <- as(M, "triangularMatrix")) # formally upper triangular
#> 2 x 2 Matrix of class "dtrMatrix"
#> [,1] [,2]
#> [1,] 2 3
#> [2,] . -1
(T2 <- as(t(M), "triangularMatrix"))
#> 2 x 2 Matrix of class "dtrMatrix"
#> [,1] [,2]
#> [1,] 2 .
#> [2,] 3 -1
stopifnot(T@uplo == "U", T2@uplo == "L", identical(T2, t(T)))
m <- matrix(0,4,4); m[upper.tri(m)] <- 1:6
(t1 <- Matrix(m+diag(,4)))
#> 4 x 4 Matrix of class "dtrMatrix"
#> [,1] [,2] [,3] [,4]
#> [1,] 1 1 2 4
#> [2,] . 1 3 5
#> [3,] . . 1 6
#> [4,] . . . 1
str(t1p <- pack(t1))
#> Formal class 'dtpMatrix' [package "Matrix"] with 5 slots
#> ..@ uplo : chr "U"
#> ..@ Dim : int [1:2] 4 4
#> ..@ Dimnames:List of 2
#> .. ..$ : NULL
#> .. ..$ : NULL
#> ..@ x : num [1:10] 1 1 1 2 3 1 4 5 6 1
#> ..@ diag : chr "N"
(t1pu <- diagN2U(t1p))
#> 4 x 4 sparse Matrix of class "dtCMatrix" (unitriangular)
#>
#> [1,] I 1 2 4
#> [2,] . I 3 5
#> [3,] . . I 6
#> [4,] . . . I
stopifnot(exprs = {
inherits(t1 , "dtrMatrix"); validObject(t1)
inherits(t1p, "dtpMatrix"); validObject(t1p)
inherits(t1pu,"dtCMatrix"); validObject(t1pu)
t1pu@x == 1:6
all(t1pu == t1p)
identical((t1pu - t1)@x, numeric())# sparse all-0
})