# SCM Repository

[matrix] Diff of /pkg/R/dtpMatrix.R
 [matrix] / pkg / R / dtpMatrix.R

# Diff of /pkg/R/dtpMatrix.R

revision 1174, Mon Jan 16 20:03:48 2006 UTC revision 1447, Fri Aug 25 20:38:36 2006 UTC
# Line 1  Line 1
1  #### Triangular Packed Matrices -- Coercion and Methods  #### Triangular Packed Matrices -- Coercion and Methods
2
3  setAs("dtpMatrix", "dtrMatrix",  setAs("dtpMatrix", "dtrMatrix",
4        function(from) .Call("dtpMatrix_as_dtrMatrix", from, PACKAGE = "Matrix"))        function(from) .Call(dtpMatrix_as_dtrMatrix, from))
5
6    if(FALSE) # now have faster  "ddense" -> "dge"
7  setAs("dtpMatrix", "dgeMatrix",  setAs("dtpMatrix", "dgeMatrix",
8        function(from) as(as(from, "dtrMatrix"), "dgeMatrix"))        function(from) as(as(from, "dtrMatrix"), "dgeMatrix"))
9
# Line 16  Line 17
17                gt2tT(as(x, "dgTMatrix"), uplo = from@uplo, diag = from@diag)                gt2tT(as(x, "dgTMatrix"), uplo = from@uplo, diag = from@diag)
18        })        })
19
gt2tT <- function(x, uplo, diag) {
## coerce *gtMatrix to *tTMatrix {general -> triangular}
i <- x@i
j <- x@j
sel <-
if(uplo == "U") {
if(diag == "U") i < j else i <= j
} else {
if(diag == "U") i > j else i >= j
}
i <- i[sel]
j <- j[sel]
if(is(x, "lMatrix"))
new("ltTMatrix", i = i, j = j, uplo = uplo, diag = diag,
Dim = x@Dim, Dimnames = x@Dimnames) # no 'x' slot
else
new(paste(substr(class(x), 1,1), # "d", "l", "i" or "z"
"tTMatrix", sep=''),
i = i, j = j, uplo = uplo, diag = diag,
x = x@x[sel], Dim = x@Dim, Dimnames = x@Dimnames)
}

20  setAs("dtpMatrix", "matrix",  setAs("dtpMatrix", "matrix",
21        function(from) as(as(from, "dtrMatrix"), "matrix"))        function(from) as(as(from, "dtrMatrix"), "matrix"))
22  setAs("matrix", "dtpMatrix",  setAs("matrix", "dtpMatrix",
# Line 45  Line 24
24
25
26  setMethod("%*%", signature(x = "dtpMatrix", y = "dgeMatrix"),  setMethod("%*%", signature(x = "dtpMatrix", y = "dgeMatrix"),
27            function(x, y) .Call("dtpMatrix_dgeMatrix_mm", x, y, PACKAGE = "Matrix"))            function(x, y) .Call(dtpMatrix_dgeMatrix_mm, x, y))
28  setMethod("%*%", signature(x = "dgeMatrix", y = "dtpMatrix"),  setMethod("%*%", signature(x = "dgeMatrix", y = "dtpMatrix"),
29            function(x, y) .Call("dgeMatrix_dtpMatrix_mm", x, y, PACKAGE = "Matrix"))            function(x, y) .Call(dgeMatrix_dtpMatrix_mm, x, y))
30  ## %*% should always work for  <fooMatrix> %*% <fooMatrix>  ## %*% should always work for  <fooMatrix> %*% <fooMatrix>
31  setMethod("%*%", signature(x = "dtpMatrix", y = "dtpMatrix"),  setMethod("%*%", signature(x = "dtpMatrix", y = "dtpMatrix"),
32            function(x, y)            function(x, y)
# Line 88  Line 67
67            })            })
68
69  setMethod("diag", signature(x = "dtpMatrix"),  setMethod("diag", signature(x = "dtpMatrix"),
70            function(x = 1, nrow, ncol = n) .Call("dtpMatrix_getDiag", x, PACKAGE = "Matrix"),            function(x = 1, nrow, ncol = n) .Call(dtpMatrix_getDiag, x),
71            valueClass = "numeric")            valueClass = "numeric")
72
73  setMethod("norm", signature(x = "dtpMatrix", type = "character"),  setMethod("norm", signature(x = "dtpMatrix", type = "character"),
74            function(x, type, ...)            function(x, type, ...)
75            .Call("dtpMatrix_norm", x, type, PACKAGE = "Matrix"),            .Call(dtpMatrix_norm, x, type),
76            valueClass = "numeric")            valueClass = "numeric")
77
78  setMethod("norm", signature(x = "dtpMatrix", type = "missing"),  setMethod("norm", signature(x = "dtpMatrix", type = "missing"),
79            function(x, type, ...)            function(x, type, ...)
80            .Call("dtpMatrix_norm", x, "O", PACKAGE = "Matrix"),            .Call(dtpMatrix_norm, x, "O"),
81            valueClass = "numeric")            valueClass = "numeric")
82
83  setMethod("rcond", signature(x = "dtpMatrix", type = "character"),  setMethod("rcond", signature(x = "dtpMatrix", type = "character"),
84            function(x, type, ...)            function(x, type, ...)
85            .Call("dtpMatrix_rcond", x, type, PACKAGE = "Matrix"),            .Call(dtpMatrix_rcond, x, type),
86            valueClass = "numeric")            valueClass = "numeric")
87
88  setMethod("rcond", signature(x = "dtpMatrix", type = "missing"),  setMethod("rcond", signature(x = "dtpMatrix", type = "missing"),
89            function(x, type, ...)            function(x, type, ...)
90            .Call("dtpMatrix_rcond", x, "O", PACKAGE = "Matrix"),            .Call(dtpMatrix_rcond, x, "O"),
91            valueClass = "numeric")            valueClass = "numeric")
92
93  setMethod("solve", signature(a = "dtpMatrix", b="missing"),  setMethod("solve", signature(a = "dtpMatrix", b="missing"),
94            function(a, b, ...)            function(a, b, ...)
95            .Call("dtpMatrix_solve", a, PACKAGE = "Matrix"),            .Call(dtpMatrix_solve, a),
96            valueClass = "dtpMatrix")            valueClass = "dtpMatrix")
97
98  setMethod("solve", signature(a = "dtpMatrix", b="matrix"),  setMethod("solve", signature(a = "dtpMatrix", b="matrix"),
99            function(a, b, ...)            function(a, b, ...)
100            .Call("dtpMatrix_matrix_solve", a, b, PACKAGE = "Matrix"),            .Call(dtpMatrix_matrix_solve, a, b),
101            valueClass = "matrix")            valueClass = "matrix")
102
103  setMethod("t", signature(x = "dtpMatrix"),  setMethod("t", signature(x = "dtpMatrix"),

Legend:
 Removed from v.1174 changed lines Added in v.1447

 root@r-forge.r-project.org ViewVC Help Powered by ViewVC 1.0.0
Thanks to: