Methods for function all.equal() (from R package base) are defined for all Matrix classes.

Methods

target = "Matrix", current = "Matrix"

\

target = "ANY", current = "Matrix"

\

target = "Matrix", current = "ANY"

these three methods are simply using all.equal.numeric directly and work via as.vector().

There are more methods, notably also for "sparseVector"'s, see showMethods("all.equal").

Examples

showMethods("all.equal")
#> Function: all.equal (package base)
#> target="ANY", current="ANY"
#> target="Matrix", current="Matrix"
#> target="Matrix", current="sparseVector"
#> target="Matrix", current="vector"
#> target="abIndex", current="abIndex"
#> target="abIndex", current="numLike"
#> target="complex", current="complex"
#>     (inherited from: target="ANY", current="ANY")
#> target="dCHMsimpl", current="dCHMsimpl"
#>     (inherited from: target="ANY", current="ANY")
#> target="dgeMatrix", current="dgeMatrix"
#>     (inherited from: target="Matrix", current="Matrix")
#> target="dgeMatrix", current="numeric"
#>     (inherited from: target="Matrix", current="vector")
#> target="dsCMatrix", current="dsCMatrix"
#>     (inherited from: target="Matrix", current="Matrix")
#> target="dsparseVector", current="dsparseVector"
#>     (inherited from: target="sparseVector", current="sparseVector")
#> target="dtCMatrix", current="dtCMatrix"
#>     (inherited from: target="Matrix", current="Matrix")
#> target="dtrMatrix", current="dtrMatrix"
#>     (inherited from: target="Matrix", current="Matrix")
#> target="matrix", current="matrix"
#>     (inherited from: target="ANY", current="ANY")
#> target="numLike", current="abIndex"
#> target="numeric", current="numeric"
#>     (inherited from: target="ANY", current="ANY")
#> target="sparseVector", current="Matrix"
#> target="sparseVector", current="sparseVector"
#> target="sparseVector", current="vector"
#> target="vector", current="Matrix"
#> target="vector", current="sparseVector"
#> 

(A <- spMatrix(3,3, i= c(1:3,2:1), j=c(3:1,1:2), x = 1:5))
#> 3 x 3 sparse Matrix of class "dgTMatrix"
#>           
#> [1,] . 5 1
#> [2,] 4 2 .
#> [3,] 3 . .
ex <- expand(lu. <- lu(A))
stopifnot( all.equal(as(A[lu.@p + 1L, lu.@q + 1L], "CsparseMatrix"),
                     lu.@L %*% lu.@U),
           with(ex, all.equal(as(P %*% A %*% t(Q), "CsparseMatrix"),
                              L %*% U)),
           with(ex, all.equal(as(A, "CsparseMatrix"),
                              t(P) %*% L %*% U %*% Q)))