Skip to content

Commit

Permalink
version 1.2-0
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Maechler authored and gaborcsardi committed Apr 3, 2015
1 parent 51f06c8 commit 2fe60ba
Show file tree
Hide file tree
Showing 133 changed files with 7,549 additions and 3,251 deletions.
15 changes: 12 additions & 3 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
2015-04-01 Martin Maechler <maechler@stat.math.ethz.ch>

* inst/NEWS.Rd: Moving ChangeLog to new (markup) NEWS file

2015-03-16 Martin Maechler <maechler@stat.math.ethz.ch>

* R/Auxiliaries.R (anyDuplicatedT): renamed from is_duplicatedT(),
and exported. uniqTsparse(): exported too.

2014-06-15 Martin Maechler <maechler@stat.math.ethz.ch>

* DESCRIPTION (Version): 1.1-4, released to CRAN
* DESCRIPTION (Version): 1.1-4, released to CRAN on 2014-06-14
* src/dsyMatrix.c (dsyMatrix_matrix_mm): fix crossprod(<vec>, <dsyMatrix>) bug

2014-04-26 Martin Maechler <maechler@stat.math.ethz.ch>
Expand All @@ -9,7 +18,7 @@

2014-03-30 Martin Maechler <maechler@stat.math.ethz.ch>

* DESCRIPTION (Version): 1.1-3, released to CRAN
* DESCRIPTION (Version): 1.1-3, released to CRAN on 2014-03-30

2014-03-12 Martin Maechler <maechler@stat.math.ethz.ch>

Expand All @@ -24,7 +33,7 @@

2014-01-20 Martin Maechler <maechler@stat.math.ethz.ch>

* DESCRIPTION (Version): 1.1-2
* DESCRIPTION (Version): 1.1-2, released to CRAN on 2014-01-28

* NAMESPACE: export fast power-user coercion utilities
.dsy2mat(), .dxC2mat(), .T2Cmat(), ..2dge().
Expand Down
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: Matrix
Version: 1.1-5-1
Date: 2015-03-23
Version: 1.2-0
Date: 2015-04-03
Priority: recommended
Title: Sparse and Dense Matrix Classes and Methods
Author: Douglas Bates <bates@stat.wisc.edu> and Martin Maechler
Maintainer: Martin Maechler <mmaechler+Matrix@gmail.com>
Contact: Doug and Martin <Matrix-authors@R-project.org>
Description: Classes and methods for dense and sparse matrices and
operations on them using LAPACK and SuiteSparse.
operations on them using 'LAPACK' and 'SuiteSparse'.
Depends: R (>= 2.15.2), methods
Imports: graphics, grid, stats, utils, lattice
Suggests: expm, MASS
Expand All @@ -24,6 +24,6 @@ LicenseNote: The Matrix package includes libraries AMD, CHOLMOD,
LGPL licenses. See the directory doc/UFsparse for details.
URL: http://Matrix.R-forge.R-project.org/
NeedsCompilation: yes
Packaged: 2015-03-23 15:44:22 UTC; maechler
Packaged: 2015-04-03 21:19:32 UTC; maechler
Repository: CRAN
Date/Publication: 2015-03-23 22:33:36
Date/Publication: 2015-04-04 16:16:00
259 changes: 132 additions & 127 deletions MD5

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ importFrom("methods",


## Generics and functions defined in this package
export("Cholesky", ".SuiteSparse_version",
export("%&%",
"Cholesky", ".SuiteSparse_version",
"Diagonal", ".symDiagonal", ".sparseDiagonal",
"Hilbert", "KhatriRao",
"Matrix",
Expand All @@ -46,6 +47,7 @@ export("Cholesky", ".SuiteSparse_version",
## "mkDet", # <- useful in other packages (Rmpfr, gmp) .. hmm --> 'stats' ?
## FIXME: why exactly these and not e.g. dsp2dsy and many more?
".dsy2mat", ".dsy2dsp", ".dxC2mat", ".T2Cmat", "..2dge", ".dense2sy",
".C2nC", ".nC2d", ".nC2l",
".diag.dsC",# -> R/dsCMatrix.R --has FIXME
".solve.dgC.chol", ".solve.dgC.qr",
"diagN2U", "diagU2N", ".diagU2N", ".diag2tT", ".diag2sT", ".diag2mat",
Expand All @@ -54,8 +56,8 @@ export("Cholesky", ".SuiteSparse_version",
"expm",
"facmul", "fac2sparse", "fac2Sparse",
"forceSymmetric",
## 'graph' package (and class) related:
"T2graph", "graph2T",
"T2graph", "graph2T", ## <- 'graph' package (and class) related
"anyDuplicatedT", "uniqTsparse",
"isTriangular",
"isDiagonal",
"isLDL",
Expand Down Expand Up @@ -87,6 +89,7 @@ if(getRversion() < "2.15.0")
export(".M.classEnv")

## substitute for using cbind() / rbind()
## .Deprecated() for R version >= 3.2.0 [2015-04]:
export("cBind",
"rBind")

Expand Down
33 changes: 26 additions & 7 deletions R/AllClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,32 @@ setClass("lsparseMatrix", representation("VIRTUAL"),

if(FALSE) { ##--not yet--
setClass("isparseMatrix", representation("VIRTUAL"),
contains = c("lMatrix", "sparseMatrix"))
contains = c("iMatrix", "sparseMatrix"))
}

## these are the "pattern" matrices for "symbolic analysis" of sparse OPs:
setClass("nsparseMatrix", representation("VIRTUAL"),
contains = c("nMatrix", "sparseMatrix"))

if(FALSE) { ##-- a nice idea --- but needs more careful method re-definitions
##-- such that the *correct* methods are dispatched:
## Trying to use more economical method defs:
## More Class Intersections {for method dispatch}:
if(FALSE) { ## this is "natural" but gives WARNINGs when other packages use "it"
setClass("dCsparseMatrix", representation("VIRTUAL"),
contains = c("CsparseMatrix", "dsparseMatrix"))
setClass("lCsparseMatrix", representation("VIRTUAL"),
contains = c("CsparseMatrix", "lsparseMatrix"))
setClass("nCsparseMatrix", representation("VIRTUAL"),
contains = c("CsparseMatrix", "nsparseMatrix"))

## dense general
setClass("geMatrix", representation("VIRTUAL"),
contains = c("denseMatrix", "generalMatrix"))

} else { ## ----------- a version that maybe works better for other pkgs ---------

##--> setClassUnion() ... below
}


## ------------------ Proper (non-virtual) Classes ----------------------------

##---------------------- DENSE -----------------------------------------
Expand Down Expand Up @@ -540,12 +548,12 @@ setClass("isRMatrix",
setClass("indMatrix", representation(perm = "integer"),
contains = c("sparseMatrix", "generalMatrix"),
validity = function(object) {
n <- object@Dim[1]
d <- object@Dim[2]
n <- object@Dim[1]
d <- object@Dim[2]
perm <- object@perm
if (length(perm) != n)
return(paste("length of 'perm' slot must be", n))
if(n > 0 && (any(perm > d) | any(perm < 1)))
if(n > 0 && (any(perm > d) || any(perm < 1)))
return("'perm' slot is not a valid index")
TRUE
})
Expand Down Expand Up @@ -695,6 +703,17 @@ setClassUnion("xMatrix", ## those Matrix classes with an 'x' slot
"ndenseMatrix",
"zMatrix"))

if(TRUE) { ##--- variant of setClass("dCsparse..." ..) etc working better for other pkgs -----

setClassUnion("dCsparseMatrix", members = c("dgCMatrix", "dtCMatrix", "dsCMatrix"))
setClassUnion("lCsparseMatrix", members = c("lgCMatrix", "ltCMatrix", "lsCMatrix"))
setClassUnion("nCsparseMatrix", members = c("ngCMatrix", "ntCMatrix", "nsCMatrix"))

## dense general
setClassUnion("geMatrix", members = c("dgeMatrix", "lgeMatrix", "ngeMatrix"))
}



## Definition Packed := dense with length( . @x) < prod( . @Dim)
## ~~~~~~
Expand Down
13 changes: 12 additions & 1 deletion R/AllGeneric.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ setGeneric("isDiagonal", function(object) standardGeneric("isDiagonal"))
setGeneric("isTriangular", function(object, upper = NA, ...)
standardGeneric("isTriangular"))

## Boolean Arithmetic Matrix multiplication
setGeneric("%&%", function (x, y) standardGeneric("%&%"))


## isSymmetric is "S3 generic" in R's base/R/eigen.R

setGeneric("facmul",
Expand All @@ -26,12 +30,19 @@ setGeneric("lu", function(x, ...) standardGeneric("lu"))
##NB setGeneric("qr", def = function(x, tol=1e-7,...) standardGeneric("qr"),
##NB useAsDefault= function(x, tol=1e-7,...) base::qr(x, tol, ...))

if(is.na(match("...", names(formals(implicitGeneric("crossprod")))))) {
## base:crossprod() has no '...', but since 2015-03, there's an implicit generic
setGeneric("crossprod", function(x, y=NULL, ...) standardGeneric("crossprod"),
useAsDefault= function(x, y=NULL, ...) base::crossprod(x, y))
setGeneric("tcrossprod", function(x, y=NULL, ...) standardGeneric("tcrossprod"),
useAsDefault= function(x, y=NULL, ...) base::tcrossprod(x, y))
}

setGeneric("Schur", function(x, vectors, ...) standardGeneric("Schur"))

setGeneric("unpack", function(x, ...) standardGeneric("unpack"))
setGeneric("pack", function(x, ...) standardGeneric("pack"))

##- setGeneric("%p%", function(a, b) standardGeneric("%p%"))

setGeneric("expm", function(x) standardGeneric("expm"))

Expand Down
67 changes: 28 additions & 39 deletions R/Auxiliaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ any0 <- function(x) .Call(R_any0, x)
## These work "identically" for 1 ('==' TRUE) and 0 ('==' FALSE)
## (but give a warning for "double" 1 or 0)
## TODO: C versions of these would be faster
allTrue <- function(x) all(x) && !any(is.na(x))
allTrue <- function(x) all(x) && !anyNA(x)


## Note that mode(<integer>) = "numeric" -- as0(), as1() return "double"
Expand Down Expand Up @@ -233,7 +233,7 @@ detSparseLU <- function(x, logarithm = TRUE, ...) {
ll <- lu(x, errSing = FALSE)
## ^^^^^^^^^^^^^^^ no error in case of singularity
if(identical(NA, ll)) { ## LU-decomposition failed with singularity
return(mkDet(ldet=if(any(is.na(x))) NaN else -Inf,
return(mkDet(ldet = if(anyNA(x)) NaN else -Inf,
logarithm=logarithm, sig = 1L))
}
## else
Expand Down Expand Up @@ -730,38 +730,27 @@ uniqTsparse <- function(x, class.x = c(class(x))) {
## and as() are based on C code (all of them?)
##
## FIXME: Do it fast for the case where 'x' is already 'uniq'

switch(class.x,
"dgTMatrix" = as(as(x, "dgCMatrix"), "dgTMatrix"),
"dsTMatrix" = as(as(x, "dsCMatrix"), "dsTMatrix"),
"dtTMatrix" = as(as(x, "dtCMatrix"), "dtTMatrix"),
## do we need this for "logical" ones, there's no sum() there!
"lgTMatrix" = as(as(x, "lgCMatrix"), "lgTMatrix"),
"lsTMatrix" = as(as(x, "lsCMatrix"), "lsTMatrix"),
"ltTMatrix" = as(as(x, "ltCMatrix"), "ltTMatrix"),
## do we need this for "logical" ones, there's no sum() there!
"ngTMatrix" = as(as(x, "ngCMatrix"), "ngTMatrix"),
"nsTMatrix" = as(as(x, "nsCMatrix"), "nsTMatrix"),
"ntTMatrix" = as(as(x, "ntCMatrix"), "ntTMatrix"),
## otherwise:
stop(gettextf("not yet implemented for class %s", dQuote(class.x)),
domain = NA))
if(extends(class.x, "TsparseMatrix")) {
tri <- extends(class.x, "triangularMatrix")
.Call(Csparse_to_Tsparse, .Call(Tsparse_to_Csparse, x, tri), tri)
} else
stop(gettextf("not yet implemented for class %s", dQuote(class.x)),
domain = NA)
}

## Note: maybe, using
## ---- xj <- .Call(Matrix_expand_pointers, x@p)
## would be slightly more efficient than as( <dgC> , "dgTMatrix")
## but really efficient would be to use only one .Call(.) for uniq(.) !

## Earlier was:
## drop0 <- function(x, clx = c(class(x)), tol = 0) {
drop0 <- function(x, tol = 0, is.Csparse = NA) {
.Call(Csparse_drop,
if(isTRUE(is.Csparse) || is.na(is.Csparse) && is(x, "CsparseMatrix")) x else
as(x, "CsparseMatrix"),
if(isTRUE(is.Csparse) || is.na(is.Csparse) && is(x, "CsparseMatrix"))
x else as(x, "CsparseMatrix"),
tol)
}


uniq <- function(x) {
if(is(x, "TsparseMatrix")) uniqTsparse(x) else
if(is(x, "sparseMatrix")) drop0(x) else x
Expand All @@ -773,10 +762,11 @@ asTuniq <- function(x) {

## is 'x' a uniq Tsparse Matrix ?
is_not_uniqT <- function(x, di = dim(x))
is.unsorted(x@j) || anyDuplicated(.Call(m_encodeInd2, x@i, x@j, di, FALSE, FALSE))
is.unsorted(x@j) || anyDuplicatedT(x, di)

## is 'x' a TsparseMatrix with duplicated entries (to be *added* for uniq):
is_duplicatedT <- function(x, di = dim(x))
is_duplicatedT <- # <- keep old name for a while, as ../inst/test-tools-Matrix.R has used it
anyDuplicatedT <- function(x, di = dim(x))
anyDuplicated(.Call(m_encodeInd2, x@i, x@j, di, FALSE, FALSE))


Expand Down Expand Up @@ -808,6 +798,10 @@ fixupDense <- function(m, from, cldm = getClassDef(class(m))) {
m
}

##' @title Transform {vectors, matrix, Matrix, ...} to dgeMatrix
##' @export
..2dge <- function(from) .Call(dup_mMatrix_as_dgeMatrix, from)

## -> ./ldenseMatrix.R :
l2d_Matrix <- function(from, cl = MatrixClass(class(from)), cld = getClassDef(cl)) {
## stopifnot(is(from, "lMatrix"))
Expand Down Expand Up @@ -968,10 +962,9 @@ l2d_meth <- function(x) {
else .M.kindC(clx)
}

.M.kindC <- function(clx) { ## 'clx': class() *or* classdefinition
.M.kindC <- function(clx, ex = extends(clx)) { ## 'clx': class() *or* classdefinition
if(is.character(clx)) # < speedup: get it once
clx <- getClassDef(clx)
ex <- extends(clx)
clx <- getClassDef(clx)
if(any(ex == "sparseVector")) {
## must work for class *extending* "dsparseVector" ==> cannot use (clx@className) !
if (any(ex == "dsparseVector")) "d"
Expand Down Expand Up @@ -1116,8 +1109,6 @@ as_Csp2 <- function(x) {
if(is(x, "triangularMatrix")) .Call(Csparse_diagU2N, x) else x
}

.gC2sym <- function(x, uplo) .Call(Csparse_general_to_symmetric, x, uplo)

## 'cl' : class() *or* class definition of from
as_gCsimpl2 <- function(from, cl = class(from))
as(from, paste0(.M.kind(from, cl), "gCMatrix"))
Expand Down Expand Up @@ -1164,7 +1155,7 @@ as_CspClass <- function(x, cl) {
##(extends(cld, "diagonalMatrix") && isDiagonal(x)) ||
if (extends(cld, "symmetricMatrix") && isSymmetric(x))
forceSymmetric(as(x,"CsparseMatrix"))
else if (extends(cld, "triangularMatrix") && (iT <- isTriangular(x)))
else if (extends(cld, "triangularMatrix") && isTriangular(x))
as(x, cl)
else if(is(x, "CsparseMatrix")) x
else as(x, paste0(.M.kind(x, cld), "gCMatrix"))
Expand Down Expand Up @@ -1208,7 +1199,7 @@ try_as <- function(x, classes, tryAnyway = FALSE) {


## For *dense* matrices
isTriMat <- function(object, upper = NA) {
isTriMat <- function(object, upper = NA, ...) {
## pretest: is it square?
d <- dim(object)
if(d[1] != d[2]) return(FALSE)
Expand All @@ -1231,7 +1222,7 @@ isTriMat <- function(object, upper = NA) {
}

## For Tsparse matrices:
isTriT <- function(object, upper = NA) {
isTriT <- function(object, upper = NA, ...) {
## pretest: is it square?
d <- dim(object)
if(d[1] != d[2]) return(FALSE)
Expand All @@ -1253,7 +1244,7 @@ isTriT <- function(object, upper = NA) {
}

## For Csparse matrices
isTriC <- function(object, upper = NA) {
isTriC <- function(object, upper = NA, ...) {
## pretest: is it square?
d <- dim(object)
if(d[1] != d[2]) return(FALSE)
Expand Down Expand Up @@ -1312,12 +1303,10 @@ isTriC <- function(object, upper = NA) {
## -> has 'uplo' differentiate between packed and unpacked

### .......... FIXME ...............

packed <- isPacked(object)
if(object@uplo == "U") {
} else { ## uplo == "L"
}

## packed <- isPacked(object)
## if(object@uplo == "U") {
## } else { ## uplo == "L"
## }
### very cheap workaround
all0(as.matrix(object)[rep_len(c(FALSE, rep.int(TRUE,n)), n^2)])
}
Expand Down
Loading

0 comments on commit 2fe60ba

Please sign in to comment.