1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#### Sparse Matrices in Compressed row-oriented format
#### --- "R"
### contains = "dMatrix"
setAs("dgRMatrix", "dgTMatrix",
function(from) .Call(compressed_to_dgTMatrix, from, FALSE))
### FIXME: Activate the following with "little" change in ../src/dgCMatrix.c
### ----- similar to compressed_to_dgTMatrix above ~~~~~~~~~~~~~~~~~~
##setAs("dgRMatrix", "matrix",
## function(from) .Call(csc_to_matrix, from))
## easy "cheap" alternative:
setAs("dgRMatrix", "matrix",
function(from) as(as(from, "dgTMatrix"), "matrix"))
##setAs("dgRMatrix", "dgeMatrix",
## function(from) .Call(csc_to_dgeMatrix, from))
##setAs("matrix", "dgRMatrix",
## function(from) {
## storage.mode(from) <- "double"
## .Call(matrix_to_csc, from)
## })
##setMethod("diag", signature(x = "dgRMatrix"),
## function(x = 1, nrow, ncol = n) .Call(csc_getDiag, x))
setAs("dgRMatrix", "dgCMatrix",
function(from) as(as(from, "dgTMatrix"), "dgCMatrix"))
setAs("dgRMatrix", "CsparseMatrix", function(from) as(from, "dgCMatrix"))
## **VERY** cheap substitutes: work via dgC and t(.)
.to.dgR <- function(from) {
m <- as(t(from), "dgCMatrix")
new("dgRMatrix", Dim = dim(from), Dimnames = .M.DN(from),
p = m@p, j = m@i, x = m@x)
}
setAs("matrix", "dgRMatrix", .to.dgR)
setAs("dgeMatrix", "dgRMatrix", .to.dgR)
setAs("dgCMatrix", "dgRMatrix", .to.dgR)
setAs("dgTMatrix", "dgRMatrix", .to.dgR)
##setAs("dgRMatrix", "dgeMatrix",
## function(from) .Call(csc_to_dgeMatrix, from))
##setAs("matrix", "dgRMatrix",
## function(from) {
## storage.mode(from) <- "double"
## .Call(matrix_to_csc, from)
## })
## try to define for "Matrix" -- once and for all -- but that fails -- why? __ FIXME __
## setMethod("dim", signature(x = "dgRMatrix"),
## function(x) x@Dim, valueClass = "integer")
##setMethod("t", signature(x = "dgRMatrix"),
## function(x) .Call(csc_transpose, x),
## valueClass = "dgRMatrix")
setMethod("image", "dgRMatrix",
function(x, ...) {
x <- as(x, "dgTMatrix")
callGeneric()
})
setMethod("t", "RsparseMatrix",
function(x) as_Rsparse(t(as_Tsparse(x))))
## Want tril(), triu(), band() --- just as "indexing" ---
## return a "close" class:
setMethod("tril", "RsparseMatrix",
function(x, k = 0, ...) as_Rsparse(tril(as_Csparse(x), k = k, ...)))
setMethod("triu", "RsparseMatrix",
function(x, k = 0, ...) as_Rsparse(triu(as_Csparse(x), k = k, ...)))
setMethod("band", "RsparseMatrix",
function(x, k1, k2, ...)
as_Rsparse(band(as_Csparse(x), k1 = k1, k2 = k2, ...)))
|