SCM

SCM Repository

[matrix] Annotation of /pkg/R/Rsparse.R
ViewVC logotype

Annotation of /pkg/R/Rsparse.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1349 - (view) (download)
Original Path: pkg/R/dgRMatrix.R

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

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge