# SCM Repository

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

# Diff of /pkg/R/dtrMatrix.R

revision 1108, Mon Jan 2 23:02:07 2006 UTC revision 1109, Tue Jan 3 16:42:31 2006 UTC
# Line 101  Line 101
101            valueClass = "dgeMatrix")            valueClass = "dgeMatrix")
102
103  setMethod("t", signature(x = "dtrMatrix"), t_trMatrix)  setMethod("t", signature(x = "dtrMatrix"), t_trMatrix)

###

## Basing 'Diagonal' on  dtpMatrix:   This is cheap but inefficient:
## TODO:  ddiagonalMatrix : contains = c("diagonalMatrix", "dMatrix")
##        diagonalMatrix :  diag = [U/N], contains = "Matrix"
Diagonal <- function(n, x = NULL)
{
## Purpose: Constructor of diagonal matrices -- ~= diag() ,
##          but *not* diag() extractor!

## Allow  Diagonal(4)  and  Diagonal(x=1:5)
if(missing(n))
n <- length(x)
else {
stopifnot(length(n) == 1, n == as.integer(n), n >= 0)
n <- as.integer(n)
}
r <-
if(missing(x)) # unit diagonal matrix
new("dtrMatrix", Dim = c(n,n), diag = "U", x = rep.int(0, n*n))
else {
x <- as.numeric(x)
stopifnot(length(x) == n)
new("dtrMatrix", Dim = c(n,n), diag = "N",
x = rbind(x, matrix(0, n,n))[1:(n*n)])
}
as(r, "dtpMatrix")# at least 'packed'
}

Legend:
 Removed from v.1108 changed lines Added in v.1109

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