kronecker-methods.Rd
Computes Kronecker products for objects inheriting from
"Matrix"
.
In order to preserver sparseness, we treat 0 * NA
as 0
,
not as NA
as usually in R (and as used for the
base function kronecker
).
signature(X = "Matrix", Y = "ANY")
.......
signature(X = "ANY", Y = "Matrix")
.......
signature(X = "diagonalMatrix", Y = "ANY")
.......
signature(X = "sparseMatrix", Y = "ANY")
.......
signature(X = "TsparseMatrix", Y = "TsparseMatrix")
.......
signature(X = "dgTMatrix", Y = "dgTMatrix")
.......
signature(X = "dtTMatrix", Y = "dtTMatrix")
.......
signature(X = "indMatrix", Y = "indMatrix")
.......
(t1 <- spMatrix(5,4, x= c(3,2,-7,11), i= 1:4, j=4:1)) # 5 x 4
#> 5 x 4 sparse Matrix of class "dgTMatrix"
#>
#> [1,] . . . 3
#> [2,] . . 2 .
#> [3,] . -7 . .
#> [4,] 11 . . .
#> [5,] . . . .
(t2 <- kronecker(Diagonal(3, 2:4), t1)) # 15 x 12
#> 15 x 12 sparse Matrix of class "dgTMatrix"
#>
#> [1,] . . . 6 . . . . . . . .
#> [2,] . . 4 . . . . . . . . .
#> [3,] . -14 . . . . . . . . . .
#> [4,] 22 . . . . . . . . . . .
#> [5,] . . . . . . . . . . . .
#> [6,] . . . . . . . 9 . . . .
#> [7,] . . . . . . 6 . . . . .
#> [8,] . . . . . -21 . . . . . .
#> [9,] . . . . 33 . . . . . . .
#> [10,] . . . . . . . . . . . .
#> [11,] . . . . . . . . . . . 12
#> [12,] . . . . . . . . . . 8 .
#> [13,] . . . . . . . . . -28 . .
#> [14,] . . . . . . . . 44 . . .
#> [15,] . . . . . . . . . . . .
## should also work with special-cased logical matrices
l3 <- upper.tri(matrix(,3,3))
M <- Matrix(l3)
(N <- as(M, "nsparseMatrix")) # "ntCMatrix" (upper triangular)
#> 3 x 3 sparse Matrix of class "ntCMatrix"
#>
#> [1,] . | |
#> [2,] . . |
#> [3,] . . .
N2 <- as(N, "generalMatrix") # (lost "t"riangularity)
MM <- kronecker(M,M)
NN <- kronecker(N,N) # "dtTMatrix" i.e. did keep
NN2 <- kronecker(N2,N2)
stopifnot(identical(NN,MM),
is(NN2, "sparseMatrix"), all(NN2 == NN),
is(NN, "triangularMatrix"))