1 |
|
#### Toplevel ``virtual'' class "Matrix" |
2 |
|
|
3 |
|
## probably not needed eventually: |
4 |
|
setAs(from = "Matrix", to = "matrix", |
5 |
|
function(from) { |
6 |
|
if(length(d <- dim(from)) != 2) stop("dim(.) has not length 2") |
7 |
|
array(as.numeric(NA), dim = d, dimnames = dimnames(from)) |
8 |
|
}) |
9 |
|
|
10 |
prMatrix <- |
prMatrix <- |
11 |
## private function to be used as show() method possibly more than once |
## private function to be used as show() method possibly more than once |
12 |
function(object) { |
function(object) { |
27 |
invisible() |
invisible() |
28 |
} |
} |
29 |
|
|
30 |
|
setMethod("show", signature(object = "ddenseMatrix"), prMatrix) |
31 |
|
## this may go away {since sparse matrices need something better!} : |
32 |
setMethod("show", signature(object = "Matrix"), prMatrix) |
setMethod("show", signature(object = "Matrix"), prMatrix) |
33 |
|
|
|
if(FALSE) {## FIXME: we should do this here (for all subclasses), |
|
|
## ----- but it coerces some to "Matrix" {with no @x slot} |
|
34 |
setMethod("dim", signature(x = "Matrix"), |
setMethod("dim", signature(x = "Matrix"), |
35 |
function(x) x@Dim, valueClass = "integer") |
function(x) x@Dim, valueClass = "integer") |
36 |
setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames) |
setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames) |
37 |
}# FIXME |
## not exported but used more than once for "dimnames<-" method : |
38 |
|
## -- or do only once for all "Matrix" classes ?? |
39 |
|
dimnamesGets <- function (x, value) { |
40 |
|
d <- dim(x) |
41 |
|
if (!is.list(value) || length(value) != 2 || |
42 |
|
!(is.null(v1 <- value[[1]]) || length(v1) == d[1]) || |
43 |
|
!(is.null(v2 <- value[[2]]) || length(v2) == d[2])) |
44 |
|
stop(sprintf("invalid dimnames given for '%s' object", class(x))) |
45 |
|
x@Dimnames <- list(if(!is.null(v1)) as.character(v1), |
46 |
|
if(!is.null(v2)) as.character(v2)) |
47 |
|
x |
48 |
|
} |
49 |
|
setMethod("dimnames<-", signature(x = "Matrix", value = "list"), |
50 |
|
dimnamesGets) |
51 |
|
|
52 |
|
|
53 |
Matrix <- |
Matrix <- |
54 |
function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) |
function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) |