SCM

SCM Repository

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

Diff of /pkg/R/sparseMatrix.R

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

revision 2004, Tue Jul 17 22:12:30 2007 UTC revision 2005, Wed Jul 18 14:46:20 2007 UTC
# Line 451  Line 451 
451            })            })
452    
453    
454    setMethod("norm", signature(x = "sparseMatrix", type = "character"),
455              function(x, type, ...) {
456    ## as(*, "dsparseMatrix") fails e.g. for "lgT*", but why use it anyway?
457    ##            if(!is(x, "dsparseMatrix"))
458    ##                x <- as(x, "dsparseMatrix")
459                  type <- toupper(substr(type[1], 1, 1))
460                  switch(type,  ##  max(<empty>, 0)  |-->  0
461                         "O" = ,
462                         "1" = max(colSums(abs(x)), 0), ## One-norm (L_1)
463                         "I" = max(rowSums(abs(x)), 0), ## L_Infinity
464                         "F" = sqrt(sum(x^2)), ## Frobenius
465                         "M" = max(abs(x), 0), ## Maximum modulus of all
466                         ## otherwise:
467                         stop("invalid 'type'"))
468              })
469    
470    
471  lm.fit.sparse <-  lm.fit.sparse <-
472  function(x, y, offset = NULL, method = c("qr", "cholesky"),  function(x, y, offset = NULL, method = c("qr", "cholesky"),
473           tol = 1e-7, singular.ok = TRUE, transpose = FALSE, ...)           tol = 1e-7, singular.ok = TRUE, transpose = FALSE, ...)
474  ### Fit a linear model using a sparse QR or a sparse Cholesky factorization  ### Fit a linear model using a sparse QR or a sparse Cholesky factorization
475  {  {
476      stopifnot(is(x, "dsparseMatrix"))      stopifnot(is(x, "dsparseMatrix"))
477    ##     if(!is(x, "dsparseMatrix"))
478    ##         x <- as(x, "dsparseMatrix")
479      yy <- as.numeric(y)      yy <- as.numeric(y)
480      if (!is.null(offset)) {      if (!is.null(offset)) {
481          stopifnot(length(offset) == length(y))          stopifnot(length(offset) == length(y))
482          yy <- yy - as.numeric(offset)          yy <- yy - as.numeric(offset)
483      }      }
484      ans <- switch(as.character(method)[1],      ans <- switch(as.character(method)[1],
485                    cholesky = .Call(dgCMatrix_cholsol,                    cholesky =
486                      .Call(dgCMatrix_cholsol,
487                    as(if (transpose) x else t(x), "dgCMatrix"), yy),                    as(if (transpose) x else t(x), "dgCMatrix"), yy),
488                    qr = .Call(dgCMatrix_qrsol,                    qr =
489                      .Call(dgCMatrix_qrsol,
490                    as(if (transpose) t(x) else x, "dgCMatrix"), yy),                    as(if (transpose) t(x) else x, "dgCMatrix"), yy),
491                    stop(paste("unknown method", dQuote(method)))                    ## otherwise:
492                      stop("unknown method ", dQuote(method))
493                    )                    )
494      ans      ans
495  }  }

Legend:
Removed from v.2004  
changed lines
  Added in v.2005

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