SCM

SCM Repository

[matrix] View of /pkg/R/lgTMatrix.R
ViewVC logotype

View of /pkg/R/lgTMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1548 - (download) (annotate)
Mon Sep 11 22:13:07 2006 UTC (12 years, 5 months ago) by maechler
File size: 1153 byte(s)
new nMatrix and subclasses; lsparse change to have x slot; many consequences
#### Logical Sparse Matrices in triplet format

### contains = "lsparseMatrix"
###             ============= ---> superclass methods in ./lsparseMatrix.R


setAs("lgTMatrix", "matrix", # go via fast C code:
      function(from) as(as(from, "lgCMatrix"), "matrix"))

setAs("matrix", "lgTMatrix",
      function(from) {
	  stopifnot(is.logical(from))
          TorNA <- is.na(from) | from
	  ij <- which(TorNA, arr.ind = TRUE) - 1:1
	  if(length(ij) == 0) ij <- matrix(ij, 0, 2)
	  new("lgTMatrix",
	      i = ij[,1],
	      j = ij[,2],
	      x = from[TorNA],
	      Dim = as.integer(dim(from)),
	      Dimnames = .M.DN(from))
	  })

setAs("lgTMatrix", "dgTMatrix",
      function(from)
      ## more efficient than
      ## as(as(as(sM, "lgCMatrix"), "dgCMatrix"), "dgTMatrix")
      new("dgTMatrix", i = from@i, j = from@j,
          x = as.double(from@x),
          ## cannot copy factors, but can we use them?
          Dim = from@Dim, Dimnames= from@Dimnames))

setMethod("t", signature(x = "lgTMatrix"),
	  function(x) new("lgTMatrix", i = x@j, j = x@i, x = x@x,
			  Dim = x@Dim[2:1],
			  Dimnames= x@Dimnames[2:1]),
	  valueClass = "lgTMatrix")

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge