SCM

SCM Repository

[matrix] Diff of /pkg/R/dtCMatrix.R
ViewVC logotype

Diff of /pkg/R/dtCMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1252, Sat Apr 15 13:47:09 2006 UTC revision 1253, Wed Apr 19 09:17:14 2006 UTC
# Line 42  Line 42 
42  setAs("dtCMatrix", "dtTMatrix",  setAs("dtCMatrix", "dtTMatrix",
43        function(from) {# and this is not elegant:        function(from) {# and this is not elegant:
44            x <- as(from, "dgTMatrix")            x <- as(from, "dgTMatrix")
45            ## FIXME: if(from@diag == "U") should drop diagonal entries:            if (from@diag == "U") { ## drop diagonal entries '1':
46            new("dtTMatrix", x = x@x, i = x@i, j = x@j,                i <- x@i; j <- x@j
47                Dim = x@Dim, Dimnames = x@Dimnames,                nonD <- i != j
48                uplo = from@uplo, diag = "N")                xx <- x@x[nonD] ; i <- i[nonD] ; j <- j[nonD]
49              } else {
50                  xx <- x@x; i <- x@i; j <- x@j
51              }
52              new("dtTMatrix", x = xx, i = i, j = j, Dim = x@Dim,
53                  Dimnames = x@Dimnames, uplo = from@uplo, diag = from@diag)
54        })        })
55    
56  setAs("dtCMatrix", "TsparseMatrix", function(from) as(from, "dtTMatrix"))  setAs("dtCMatrix", "TsparseMatrix", function(from) as(from, "dtTMatrix"))
# Line 53  Line 58 
58  setAs("dtCMatrix", "dtrMatrix",  setAs("dtCMatrix", "dtrMatrix",
59        function(from) as(as(from, "dtTMatrix"), "dtrMatrix"))        function(from) as(as(from, "dtTMatrix"), "dtrMatrix"))
60    
61    ## using  diagU2N() from ./Auxiliaries.R :
62  setMethod("solve", signature(a = "dtCMatrix", b = "missing"),  setMethod("solve", signature(a = "dtCMatrix", b = "missing"),
63            function(a, b, ...) {            function(a, b, ...) {
64                if (a@diag == "U") a <- as(as(a, "dtTMatrix"), "dtCMatrix")                if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
65                .Call("dtCMatrix_solve", a, PACKAGE = "Matrix")                .Call("dtCMatrix_solve", a, PACKAGE = "Matrix")
66            }, valueClass = "dtCMatrix")            }, valueClass = "dtCMatrix")
67    
68  setMethod("solve", signature(a = "dtCMatrix", b = "dgeMatrix"),  setMethod("solve", signature(a = "dtCMatrix", b = "dgeMatrix"),
69            function(a, b, ...) {            function(a, b, ...) {
70                if (a@diag == "U") a <- as(as(a, "dtTMatrix"), "dtCMatrix")                if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
71                .Call("dtCMatrix_matrix_solve", a, b, TRUE, PACKAGE = "Matrix")                .Call("dtCMatrix_matrix_solve", a, b, TRUE, PACKAGE = "Matrix")
72            }, valueClass = "dgeMatrix")            }, valueClass = "dgeMatrix")
73    
74  setMethod("solve", signature(a = "dtCMatrix", b = "matrix"),  setMethod("solve", signature(a = "dtCMatrix", b = "matrix"),
75            function(a, b, ...) {            function(a, b, ...) {
76                if (a@diag == "U") a <- as(as(a, "dtTMatrix"), "dtCMatrix")                if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
77                storage.mode(b) <- "double"                storage.mode(b) <- "double"
78                .Call("dtCMatrix_matrix_solve", a, b, FALSE, PACKAGE = "Matrix")                .Call("dtCMatrix_matrix_solve", a, b, FALSE, PACKAGE = "Matrix")
79            }, valueClass = "dgeMatrix")            }, valueClass = "dgeMatrix")
80    
81  setMethod("solve", signature(a = "dtCMatrix", b = "numeric"),  setMethod("solve", signature(a = "dtCMatrix", b = "numeric"),
82            function(a, b, ...) {            function(a, b, ...) {
83                if (a@diag == "U") a <- as(as(a, "dtTMatrix"), "dtCMatrix")                if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
84                .Call("dtCMatrix_matrix_solve", a, as.matrix(as.double(b)),                .Call("dtCMatrix_matrix_solve", a, as.matrix(as.double(b)),
85                      FALSE, PACKAGE = "Matrix")                      FALSE, PACKAGE = "Matrix")
86            }, valueClass = "dgeMatrix")            }, valueClass = "dgeMatrix")

Legend:
Removed from v.1252  
changed lines
  Added in v.1253

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