# NOT RUN {
<!-- % ../R/sparseMatrix.R -->
# }
# NOT RUN {
if(FALSE) ## The function is defined (don't redefine here!), simply as
mat2triplet <- function(x, uniqT = FALSE) {
T <- as(x, "TsparseMatrix")
if(uniqT && anyDuplicatedT(T)) T <- .uniqTsparse(T)
if(is(T, "nsparseMatrix"))
list(i = T@i + 1L, j = T@j + 1L)
else list(i = T@i + 1L, j = T@j + 1L, x = T@x)
}
i <- c(1,3:8); j <- c(2,9,6:10); x <- 7 * (1:7)
(Ax <- sparseMatrix(i, j, x = x)) ## 8 x 10 "dgCMatrix"
str(trA <- mat2triplet(Ax))
stopifnot(i == sort(trA$i), sort(j) == trA$j, x == sort(trA$x))
D <- Diagonal(x=4:2)
summary(D)
str(mat2triplet(D))
# }
Run the code above in your browser using DataLab