The virtual class of triangular matrices,"triangularMatrix", the package Matrix contains square (nrow == ncol) numeric and logical, dense and sparse matrices, e.g., see the examples. A main use of the virtual class is in methods (and C functions) that can deal with all triangular matrices.

Slots

uplo:

String (of class "character"). Must be either "U", for upper triangular, and "L", for lower triangular.

diag:

String (of class "character"). Must be either "U", for unit triangular (diagonal is all ones), or "N" for non-unit. The diagonal elements are not accessed internally when diag is "U". For denseMatrix classes, they need to be allocated though, such that the length of the x slot does not depend on diag.

Dim, Dimnames:

The dimension (a length-2 "integer") and corresponding names (or NULL), inherited from the Matrix, see there.

Extends

Class "Matrix", directly.

Methods

There's a C function triangularMatrix_validity() called by the internal validity checking functions.

Currently, Schur, isSymmetric and as() (i.e. coerce) have methods with triangularMatrix in their signature.

See also

isTriangular() for testing any matrix for triangularity; classes symmetricMatrix, and, e.g., dtrMatrix for numeric dense matrices, or ltCMatrix for a logical sparse matrix subclass of "triangularMatrix".

Examples

showClass("triangularMatrix")
#> Virtual Class "triangularMatrix" [package "Matrix"]
#> 
#> Slots:
#>                                               
#> Name:       uplo      diag       Dim  Dimnames
#> Class: character character   integer      list
#> 
#> Extends: 
#> Class "Matrix", directly
#> Class "replValueSp", by class "Matrix", distance 2
#> 
#> Known Subclasses: "ntrMatrix", "ntpMatrix", "ltrMatrix", "ltpMatrix", "dtrMatrix", "dtpMatrix", 
#> "ntCMatrix", "ntRMatrix", "ntTMatrix", "ltCMatrix", "ltRMatrix", "ltTMatrix", 
#> "dtCMatrix", "dtRMatrix", "dtTMatrix"

## The names of direct subclasses:
scl <- getClass("triangularMatrix")@subclasses
directly <- sapply(lapply(scl, slot, "by"), length) == 0
names(scl)[directly]
#>  [1] "ntrMatrix" "ntpMatrix" "ltrMatrix" "ltpMatrix" "dtrMatrix" "dtpMatrix"
#>  [7] "ntCMatrix" "ntRMatrix" "ntTMatrix" "ltCMatrix" "ltRMatrix" "ltTMatrix"
#> [13] "dtCMatrix" "dtRMatrix" "dtTMatrix"

(m <- matrix(c(5,1,0,3), 2))
#>      [,1] [,2]
#> [1,]    5    0
#> [2,]    1    3
as(m, "triangularMatrix")
#> 2 x 2 Matrix of class "dtrMatrix"
#>      [,1] [,2]
#> [1,]    5    .
#> [2,]    1    3