NEWS | R Documentation |
ASAN-detected bugs fixed in C-level
Tsparse_as_CRsparse()
(triggered by .T2C(<0-by-0>)
)
and pMatrix_validate()
.
With a few exceptions, direct coercions to non-virtual subclasses
of Matrix
(e.g., dsCMatrix
) have been formally deprecated.
For now, these will continue to work as before, but with a warning
indicating how to accomplish the desired coercion via virtual classes
(e.g., symmetricMatrix
) alone. How such warnings are signaled
is controlled by the global option Matrix.warnDeprecatedCoerce
.
0
or lessis to be silent.
1
is to signal a warning with each deprecated coercion.
2
or greateris to signal an error with each deprecated coercion.
NA
is to signal a message or warning (see below) with the next deprecated coercion and be silent after that.
If unset or invalid, then the value of the environment variable
R_MATRIX_WARN_DEPRECATED_COERCE (NA
if unset) is
used. This is cached when the Matrix namespace is loaded.
Option values are coerced to integer before use.
To reduce disruption to existing code, the NA
case signals
messages rather than warnings with coercions to the most-used
non-virtual subclasses of Matrix
, namely dg.Matrix
and d.CMatrix
. This may change in the future.
Symmetrization of <Matrix>@Dimnames
and
dimnames(<matrix>)
now goes through C utility symmDN()
in most places, resolving some earlier inconsistencies.
Many more validity methods now correctly operate under the assumption that methods for superclasses have already been called, eliminating many redundant checks.
Validation of <Matrix>@Dim
now looks at type
before length, avoiding a misleading error message.
Validation of <Matrix>@Dimnames
now avoids
isNewList
, which had allowed an error message suggesting
that NULL
is a list.
Setting a factor on a compMatrix
is now to install
the factor itself, not a copy, for efficiency and consistency
with the semantics of <compMatrix>@factors[[name]] <- value
.
Long vector support in methods for packing and unpacking
denseMatrix
, and others.
diag<-
incorrectly preserved the class of dense matrices,
so that, e.g., `diag<-`(x=<dpoMatrix>, value=-1)
was still a
dpoMatrix
. Now the result is always one of the more general
.(ge|tr|sy|tp|sp)Matrix
.
t(<corMatrix>)
no longer clears the sd
slot.
t(<p?BunchKaufman>)
now returns one of the more general
dt[rp]Matrix
, rather than preserving class and clearing
the perm
slot.
t(<symmetricMatrix>)
no longer reverses the
Dimnames
slot. Symmetrization of dn <- x@Dimnames
and t(x)@Dimnames
had given different results when
dn[[1]]
and dn[[2]]
were non-NULL
and
asymmetric.
isTriangular(x, upper)
had incorrectly returned
FALSE
for x
of class triangularMatrix
when upper = TRUE
and x@uplo = "L"
or when
upper = FALSE
and x@uplo = "U"
.
isTriangular
is now equivalent to isDiagonal
in those cases.
isSymmetric()
was equivalent to isDiagonal()
for triangular matrices, not allowing numerical fuzz via an
argument tol
. A tol
argument is now implemented
for all subclasses of dMatrix
except for those inheriting
from symmetricMatrix
or diagonalMatrix
.
Methods for isSymmetric
now also look at
Dimnames
and names(Dimnames)
, following
isSymmetric.matrix
from base. See also
New Features.
band(x, -k, k)
for sparse x
used
isSymmetric(x)
(which tolerates numerical fuzz) to test
for symmetry, resulting in loss of information in some cases.
Now it tests that x
inherits from symmetricMatrix
,
and so returns symmetricMatrix
in fewer cases.
triu(x, k)
and tril(x, k)
incorrectly
required k <= m
(instead of k <= n
),
for m
-by-n
sparse x
. They now accept
all k
from -m
to n
, with fewer errors
in the m < n
case.
crossprod(<Rsparse>, <Tsparse>)
and similar now work
again (optional boolArith
was not passed on), fixing Matrix
bug #6766 by David Cortes.
Ditto for tcrossprod()
, where the old result was even wrong
when it had “worked”, before Matrix 1.2-0.
as(<matrix>, "nMatrix")
can now be sparse or
dense, going via Matrix()
, for greater consistency with
coercions to dMatrix
and lMatrix
.
(Previously, the result was always an ngTMatrix
.)
forceSymmetric(<[RT]sparseMatrix>)
are now more
efficient, returning symmetric [RT]sparseMatrix
without
intermediate coercions to CsparseMatrix
.
tcrossprod(a, b)
for unit triangular sparse matrices
now works correctly.
!<ltrMatrix>
is no longer an error in the 0-by-0
unit diagonal case.
Coercions among [CRT]sparseMatrix
preserve the
factors
slot in more cases.
Coercions of overallocated l.TMatrix
to
denseMatrix
or CsparseMatrix
now give TRUE
instead of NA
in the NA || TRUE
case, following
conventional logic.
Methods for unpacking and indexing packedMatrix
and
for coercing from [CRT]sparseMatrix
to denseMatrix
now check more consistently for overflow of R_XLEN_T_MAX
.
solve(<ddenseMatrix>, <ANY>)
is removed from
the method list. It had allowed infinite recursion, e.g.,
with solve(new("dgeMatrix"), NULL)
.
is.na(<ndenseMatrix>)
gave TRUE
where
the x
slot had NA
. Now the result is always
a zero matrix.
is.na(<.t[rp]Matrix>)
and
is.infinite(<.t[rp]Matrix>)
ignored the diag
slot,
behaving always as though diag == "N"
. They now give
FALSE
on the diagonal in the diag != "N"
case.
Now only “nontrivial” matrix elements determine
whether is.na(<denseMatrix>)
is an ndenseMatrix
or an nsparseMatrix
.
is.na(<ddenseMatrix>)
coerced to lMatrix
.
This unnecessary step is avoided now, saving a potentially
nontrivial allocation.
solve(<ddenseMatrix>, b)
coerced the first argument
to dgeMatrix
when b
was not a ddenseMatrix
or traditional matrix
. This unnecessary step is avoided now,
so that specialized methods for d(tr|sy|po|tp|sp|pp)Matrix
are used where possible (including for b
inheriting from
[ln]denseMatrix
, sparseMatrix
, or numLike
).
`dim<-`(x, -x@Dim)
is now an error, no longer
yielding an invalid Matrix
object.
`dim<-`(x, x@Dim)
is now faster, returning x
without allocation in all cases.
`dim<-`(x, value)
gives a better error when
value
contains NA
or elements exceeding
INT_MAX
.
`dim<-`(<RsparseMatrix>, value)
is now an
RsparseMatrix
, rather than a TsparseMatrix
.
For consistency with other methods,
symmpart(<diagonalMatrix>)
now always inherits from
both dMatrix
and symmetricMatrix
, and
skewpart(<diagonalMatrix>)
now always has symmetric
Dimnames
.
Zeros on the diagonal of skewpart(<[CRT]sparseMatrix>)
are now structural.
as(<ndenseMatrix>, "(vector|matrix|[dl]Matrix)")
and nnzero(<ndenseMatrix>)
now correctly treat NA
in the x
slot as TRUE
.
as(<[nl].TMatrix>, "dMatrix")
now correctly handles
the overallocated case: data for each unique [i,j]
pair are aggregated logically (x1 || ... || xn
) rather than
arithmetically (x1 + ... + xn
), so that elements of the
result are restricted to the set c(0, 1, NA)
.
This bug had also affected the result of sum(<[nl].TMatrix>)
.
dimnames(as(x, "matrix"))
is now NULL
for all x
inheriting from Matrix
,
when x@Dimnames
is the trivial list(NULL, NULL)
.
.bdiag(<named list>)
no longer propagates names
to the Dim
slot of the result.
as(<named vector>, "denseMatrix")
now correctly
propagates names
to the result.
as(<d.[CR]Matrix>, "lMatrix")
no longer drops
non-structural zeros, for greater consistency with analogous
coercions.
Matrix(x, doDiag)
now behaves as documented
for diagonal matrices x
with asymmetric dimnames
,
returning a diagonalMatrix
when doDiag = TRUE
,
rather than a triangularMatrix
.
Matrix(<n-dimensional table>) now works for n != 2
.
Matrix(<sparseVector>)
now works for vector lengths
other than 1, no longer giving an error about length mismatch
when neither of nrow
and ncol
are supplied.
Matrix(<diagonalMatrix>, doDiag = FALSE)
is now a symmetricMatrix
, not a diagonalMatrix
,
matching the documentation of doDiag
.
Matrix(<.geMatrix>, sparse = TRUE, forceCheck)
and Matrix(<.g[CRT]Matrix>, sparse = FALSE, forceCheck)
now respect forceCheck = FALSE
by always returning
generalMatrix
, i.e., not testing for symmetric
or triangular structure.
Matrix(0, nrow, )
, Matrix(0, , ncol)
now
throw (correct) errors for nrow
, ncol
in the
interval [0,1)
, consistent with base::matrix()
.
sparseDefault(<sparseMatrix>)
now counts zeros
without coercing to matrix
,
making Matrix(<sparseMatrix>, sparse = NULL)
much more
efficient.
Methods for group generic Math
no longer
preserve x@diag == "U"
or lose x@Dimnames
when f(0) == 0
and f(1) != 1
.
(The former happened for triangularMatrix
x
and the latter for diagonalMatrix
x
.)
image(Z)
for a completely “empty” (all 0)
sparseMatrix
works again (?!).
x[i, ] <- value
and y[, j] <- value
is now an error in more cases
for m
-by-0 CsparseMatrix
x
and 0-by-n
CsparseMatrix
y
.
In these cases, subassignment gave a (formally) invalid result.
chol(<ds[yp]Matrix>)
now calls the underlying
C-level routine exactly once. Previously, it was called
an extra time in order to test for positive definiteness,
with the result thrown away (!). Hence these methods should
become approximately two times faster.
dimnames(chol(x))
is identical to dimnames(x)
in all cases, now even when chol(x)
is constructed from a
cached MatrixFactorization
, for greater consistency with
base::chol.default()
.
chol(<generalMatrix>)
no longer looks at
Dimnames
when testing for symmetry.
lu(<dtCMatrix>)
no longer returns an invalid
sparseLU
object in the lower triangular case.
lu(x)
had sometimes incorrectly cached its
return value as element "lu"
(rather than "LU"
)
of x@factors
. Now it is always "LU"
.
"Compare"
operators, e.g., a > b
, x != y
,
now work correctly in more dense unitriangular and sparse 0-extent
cases.
!<nMatrix>
is now always an nMatrix
, never
an lMatrix
.
!<ndenseMatrix>
and which(<ndenseMatrix>)
now correctly handle NA
as TRUE
.
anyNA(<denseMatrix>) had incorrectly returned
anyNA(.@x)
in many cases, giving false positives
for some .(tr|sy)Matrix
and ndenseMatrix
.
Now methods respect the “rules” of these classes.
The boolean arithmetic product A %&% B
and e.g.,
crossprod(A, B, boolArith=TRUE)
now should behave as if
drop0(A)
and drop0(B)
were used, i.e., for formally
sparse matrices, the boolean product results should be stable with
respect to non-structural vs structural zeros.
t(<symmetricMatrix>)
now retains the factors
slot, avoiding recomputation.
qr(<large sparse>)
no longer segfaults in some cases,
but now warns about “Out of memory” and stops, fixing Matrix
bug #6610 reported by Benjamin Tyner.
Fixed <sparse> %*% <dense>
possible memory corruption,
visible via valgrind, fixing Matrix bug #6726 reported by David Cortes.
Fixed the (quite long standing) Matrix bug #6777,
reported by Manuel Koller: tcrossprod(<matrix>, <[dln]sCMatrix>)
has been wrong in some cases.
KhatriRao()
gets new sparseY = TRUE
option and
also works for more Matrix
classes.
Virtual class packedMatrix
gains methods for
pack
, unpack
, isSymmetric
,
isTriangular
, and isDiagonal
implemented in C,
replacing those defined for many subclasses individually.
New virtual class unpackedMatrix
containing
denseMatrix
_without_ packedMatrix
, with methods
for pack
, unpack
, isSymmetric
,
isTriangular
, isDiagonal
, t
, diag
,
and diag<-
implemented in C, replacing those defined for
many subclasses individually.
isTriangular
and isDiagonal
are now
implemented in C also for [CRT]sparseMatrix
and standard
matrix
. isSymmetric
is now implemented in C
for all denseMatrix
and all [CRT]sparseMatrix
,
though these C routines are currently only called when testing
for exact symmetry (always for [ln]Matrix
,
only when tol = 0
for dMatrix
).
Methods for isSymmetric
gain an argument
checkDN = TRUE
indicating whether symmetry of
Dimnames
should be checked. For backwards compatibility
and consistency with isSymmetric.matrix
from base,
the actual condition is checkDN && check.attributes
.
isTriangular(x, upper)
now has a kind
attribute if and only if x
is triangular and
upper
is NA
.
diag(<unpackedMatrix>) <- value
now behaves like
diag(<packedMatrix>) <- value
, supporting coercions
depending on typeof(value)
, consistent with diag<-
from base.
pack
and unpack
are now identity functions
for packedMatrix
and unpackedMatrix
arguments,
respectively (previously an error). pack(<.geMatrix>)
(previously an error) now behaves as pack(<matrix>)
,
i.e., by checking for symmetry or triangularity before packing.
unpack(<matrix>)
now works and is equivalent to
as(<matrix>, "unpackedMatrix")
, with result inheriting
from .(ge|tr|sy)Matrix
, as appropriate.
Many more validity methods implemented in C, for efficiency,
including methods for Matrix
, compMatrix
,
diagonalMatrix
, indMatrix
, pMatrix
,
corMatrix
, [liz]Matrix
, and ndenseMatrix
.
The validity method of dppMatrix
now follows
the validity method of dpoMatrix
, requiring non-negative
diagonal elements.
Validation of <Matrix>@Dimnames[[i]]
now tolerates
vector types other than character, which are coerced to character
in C via the new R_DimNames_fixup()
, for greater
consistency with base matrix()
.
band(x, k1, k2)
is optimized further for both
dense and sparse x
, returning triangularMatrix
,
symmetricMatrix
, and packedMatrix
in more cases.
band()
is now implemented also for
diagonalMatrix
(only tri[ul]()
worked before).
Coercions .ge<->.g[CRT]
, .t[rp]<->.t[CRT]
,
.s[yp]<->.s[CRT]
, and ..[CRT]<->matrix
are now
fully implemented and optimized, with minimal intermediate
allocations. These (and others) no longer rely on CHOLMOD,
which had handled integer types as double and required
preprocessing in many cases (with diagU2N()
, etc.).
Fixes in group methods (e.g., >
, &
, |
),
notably for matrices inheriting from class symmetricMatrix
,
triangularMatrix
, lMatrix
, or nMatrix
.
as.vector
, as.numeric
, and as.logical
are now implemented for all Matrix
.
Subassignment to indMatrix
is no longer prohibited,
now going via TsparseMatrix
.
indMatrix
gains methods for isTriangular
,
isDiagonal
, diag
, diag<-
, band
,
tri[ul]
, and forceSymmetric
. It also gains
coercions to more virtual classes (notably denseMatrix
)
and a coercion to pMatrix
.
solve(<ddenseMatrix>, <numLike>)
now works in all
cases.
determinant(<ds[yp]Matrix>)
is now much faster
in the positive definite case, no longer going via dgeMatrix
.
diag(<[CRT]sparseMatrix>)
is now done in C
and is highly optimized in the .[ts][CR]Matrix
case.
symmpart
and skewpart
are now done in C
for all denseMatrix
and all [CRT]sparseMatrix
.
Both now more faithfully preserve the “storage” of
their argument. (Previously, symmpart(<packedMatrix>)
was an unpackedMatrix
,
and (symm|skew)part(<[RT]sparseMatrix>)
was a CsparseMatrix
.)
as(<vector|matrix>, "([dln]?dense|[dlnCRT]?sparse)Matrix")
are now fully and more consistently implemented. In the vector case,
the result is now always a length
-by-1 generalMatrix
.
In the matrix case, structure is now always examined, hence the result
is a symmetricMatrix
or triangularMatrix
in more cases.
Matrix(<classed matrix>)
now works for classes
other than table
.
lu(<dt[rpCRT]Matrix>)
and lu(<ddiMatrix>)
now behave more consistently. In the diagonal, upper triangular,
and unit lower triangular cases, the result is obtained
“directly”, i.e., without pivoting. In the non-unit
lower triangular case, it is obtained with pivoting.
(Previously, pivoting was never done for dtCMatrix
and always done for dt[rpRT]Matrix
and ddiMatrix
.)
lu(x)
now caches its return value also for all
ds.Matrix
x
(by default).
readMM()
now warns if the number of entries found
is less than number reported in the header.
x[i]
now works for nMatrix
i
,
just as for lMatrix
i. This supports constructions
such as x[is.na(x)]
, where the logical operation
produces an nMatrix
because it is never NA
.
AZERO()
and friends gain an argument specifying
a zero constant (0 for int
arrays, 0.0 for double
arrays).
C-level utilities (R_)?[gs]et_factors()
have been
renamed (R_)?[gs]et_factor()
, as they only ever get and
set one factor.
The signature of set_factor()
has been changed to
match other set*()
functions:
to (object,name,value)
from (object,value,name)
.
For clarity, set_factor()
now returns void
and is used like other set*()
functions (i.e., for its
side effect). The R interface is unchanged: R_set_factor()
continues to return the value being set.
C-level utilities
make_[di]_matrix_(triangular|symmetric)()
,
packed_to_full_(double|int)()
,
full_to_packed_(double|int)()
, and
install_diagonal(_int)?()
are replaced by safer, more consistently named ones.
Previous versions allowed integer overflow.
C-level utilities dup_mMatrix_as_d?geMatrix()
are
replaced by the more general dense_as_general()
, which
takes arguments controlling memory allocation and the
“kind” of the .geMatrix
result.
New C-level utility DimNames_is_symmetric()
with R interface isSymmetricDN()
, which should be
used consistently to test for symmetry of [dD]imnames
.
Note that these are intended to behave consistently with
symmetricMatrix_validate()
,
by allowing, e.g., list(NULL, nms)
,
but not, e.g., list(A = NULL, B = nms)
.
Coercions to triangularMatrix
and
symmetricMatrix
are now almost all inherited from
Matrix
, whose methods simply call tri[ul]()
and forceSymmetric()
if isTriangular()
and
isSymmetric()
, respectively, return TRUE
.
Many of the exported .*2*
utilities have been
redefined as aliases or wrappers of new, more general functions
(see below). These not-yet-deprecated functions have been
centralized in ‘R/denseMatrix.R’ and ‘R/sparseMatrix.R’.
New C-level utilities
R_(dense|sparse)_as_kind()
for coercion from one “kind” to another;
R_(dense|sparse)_as_general()
for coercion from triangular and symmetric to general;
R_(dense|sparse)_band()
for coercion to triangular (and other banded);
R_(unpacked*|packed*|sparse)_force_symmetric()
for coercion to symmetric;
R_(dense|sparse)_as_(sparse|dense)()
for coercion between dense and sparse of the same “kind”
and “structure”;
R_diagonal_as_sparse()
for coercion from diagonalMatrix
to any
[CRT]sparseMatrix
;
R_(dense|sparse|geMatrix)_as_(matrix|vector)()
for coercion to base matrix and vector; and
tCRsparse_as_RCsparse()
for the idioms
as(t(<[CR]sparseMatrix>), "[RC]sparseMatrix")
.
These all have not-yet-exported R wrappers.
indTri()
and indDiag()
now in C,
with a new argument packed
for efficiently indexing
packedMatrix
. indDiag()
now behaves sensibly
in the n = 0
case.
.M.kind()
, .M.shape()
, and (new)
.M.repr()
are now done in C via R_check_class_etc()
,
requiring a class definition only in “rare” cases.
diag(x)
methods now mostly also keep names
from
dimnames(x)
by default and obey names=*
more generally.
New virtual class packedMatrix
containing packed (dense)
symmetric and triangular matrices. Methods for subscripting,
including diag()
, notably keeping names by default and for
t()
which are memory efficient, i.e., do not work via
unpacking, thanks to Mikael Jagan.
New dmperm()
implementing a Dulmage-Mendelsohn
decomposition, thanks to the persistency of Mauricio Vargas (@uc.cl).
Export more low-level conversion utilities:
.n2dgT
, .m2ngCn
, .m2ngTn
.
Provide some matrix multiplication methods for "RsparseMatrix"
.
Our C sources now use R_Calloc()
, R_Free()
etc, instead of the shorter versions without 'R_'. Consequently,
we get closer to STRICT_R_HEADERS
.
Also, include <float.h>
for DBL_EPSILON
.
PROTECT()
3 more; as from ‘rchk’ for Matrix 1.4-0.
Slightly better patch notably for Windows, for ‘src/SuiteSparse_config/SuiteSparse_config.h’
Fix to continue working for R 3.5.0 and newer, providing
tryInvokeRestart()
for older versions of R, thanking
Michael Chirico for the heads up.
Modified AZERO()
to work with R_xlen_t
and new
AZEROs()
for size_t
; other tweaks to evade
-Wconversion
warnings.
Update many ‘src/*.c’ preventing integer overflow in “pointer” and index computations for large (dense) matrices; prompted by Dario Strbenac's post to R-devel.
sparse.model.matrix(.., contrasts.arg = <.. ddiMatrix ..>)
now works correctly, fixing R-forge Matrix bug #6673 by Davor Josipovic.
sparse.model.matrix(..)
now also works in cases the
contrast matrix has become a "denseMatrix"
; e.g., in a case
using poly(.)
in the formula; now works correctly, fixing
R-forge Matrix bug #6657 and useful suggestions by Nick Hanewinckel.
Fixed the internal attr.all_Mat()
auxiliary for
all.equal()
, notably for the case when exactly one of the
matrices is a base matrix
.
Fixed long-standing bug in the rbind2()
method for
logical dense matrices, specifically "lgeMatrix"
, thanks to
the notice by Aaron Lun.
fix leak in C-level Csparse_to_dense()
thanks to Bill
Dunlap in R's PR#18204 and install_lu()
called from solve(<dgCMatrix>)
in PR#18206.
fix leak in crossprod(<dsTMatrix>), thanks to report and patch in PR#18205 by Bill Dunlap.
band(M, k1, k2)
now also works when k1 * k2
is
larger than 2^31-1, the maximal integer, fixing R-forge Matrix bug
6743 by Ariel Paulson. Further, it works when M
is a sparse
"symmetricMatrix"
but the band is not symmetric, k1 != -k2
.
fix leak in C-level code for cbind(m1,m2)
or
rbind(*)
when m1
is "n.Csparse"
and m2
is
not, thanks to Bill Dunlap's diagnosis and patch in R's PR#18210.
sparseVector(i=integer(), length=2^33)
now does show/print,
after fixing a bug in the head()
method for empty
sparseVectors. Reported by David Cortes as Matrix bug #6745.
inverting or solving dsCMatrix
no longer catches C level
warnings too early which would not free, but rather leak memory;
thanks to Bill Dunlap's analysis and patch in R's PR#18214.
Additionally, such warnings and error are message()
d when
getOption("Matrix.verbose")
is >= 1
.
‘test-tools-1.R’: Sys.memGB()
can no longer use
memory.limit()
on Windows; no returns NA.value = 2.10201
in such cases.
ss <- <sparseVector>[i]
gave an invalid sparseVector
ss
as ss@i
was not necessarily sorted; thanks to a
report by Quran Wu.
as(<dsyMatrix>, "generalMatrix")
and similar, sometimes
did not use (C-level) symmetric_Dimnames()
etc; report
(to R's PR#18250 by Mikael Jagan); fixed all on C level. As a
consequence, you will now see more preserved dimnames after
matrix transformations or operations which involved symmetric matrices.
as(<ddiMatrix>, "matrix")
no longer loses dimnames,
thanks to Mikael Jagan's report as Matrix bug #6751.
No longer include ‘Rdefines.h’ as it is somewhat deprecated.
Update matrix(<data>, n,m)
in ‘tests/*’ to work with
R-devel CMD check --as-cran
cBind()
and rBind()
are now defunct:
simply use cbind()
and rbind()
instead.
For now revert to R (>= 3.5.0)
dependency to accomodate
users on older R installations.
Fixed a thinko (in 1.3-2): Now direct coercion from
"ddiMatrix"
to "dgCMatrix"
, and hence, e.g.,
as(Matrix(1, sparse=TRUE), "dgCMatrix") now works.
Fixed error message in <dtrMatrix> multiplication.
Fixed long-standing bug in R[,j] <- v
when R
is "Rsparse*",
R-forge Matrix bug #6709 by David Cortes.
‘./include/cholmod.h’ and ‘./include/Matrix_stubs.h’ needed updating from SparseSuite update; R-forge Matrix bug #6714 by Kasper Kristensen (TMB pkg).
as.matrix()
and as.array()
now work for
"sparseVector"
s as expected; see Matrix bug #6708.
M[,]
(and similar) now work as in base R; ; R-forge Matrix bug #6720 by
David Cortes.
-S
now works also when S
has no 'factors' slot.
It signalled an error, e.g., for sparse triangular matrices S
;
R-forge Matrix bug #6656, reported by Chun Fung (Jackson) Kwok.
M*2
and similar no longer keep cached factorizations (in
'factors' slot), but drop them via internal new .empty.factors()
.
R-forge Matrix bug #6606, reported by Tomas Lumley.
removed the nowhere used (and unexported but still active)
class union "Mnumeric"
which actually trickled into many base
classes properties. Notably would it break validity of factor
with a proposed change in validity checking, as factors were also
"Mnumeric"
but did not fulfill its validity method.
Similarly removed (disabled) unused class union "numericVector"
.
removed a few duplicated .alias{.}
from ‘man/*.Rd’.
translation updates (of outlines only); finally added Italian (by Daniele Medri) to svn; updated French (by Philippe Grosjean), forgotten (R part of) Korean. New Lithuanian translations by Gabriele Stupuriene & Rimantas Zakauskas.
In internal diagOdiag()
method, no longer use
matrix(x, n,n)
when x
is longer than n*n.
Update tests/*.R to future matrix(x, n,k)
warning in more
mismatch cases.
Eliminating the need for ‘ftp://*’, add the very small
jgl009
MatrixMarket example to our ‘external/’ files.
rankMatrix()
tweaks for the singular values based methods,
notably method = "maybeGrad"
.
as(new("dtCMatrix", diag="U"), "matrix")
now works, as
C-level diagU2N()
now also works for 0-dimensional triangular
matrices; this also fixes a subsetting (“indexing”) bug of
such 0-dimensional matrices, thanks to a report by Aaron Lun.
logical subsetting of 0-dim. (diagonal/triangular) matrices fixes.
The new FCONE
macros added for newer Fortran/C compiler
combinations are now defined back compatibly with R >= 3.6.0.
chol(<diagonal dt[CRT]Matrix>)
now works.
‘rchk’: fix potentially unPROTECT
ed vars in
‘src/dsyMatrix.c’
rankMatrix(<dense>, method="qr.R")
no longer assumes
non-negative diagonal entries of the R
matrix.
Matrix(*, doDiag=TRUE)
where doDiag=TRUE
has
always been the default is now obeyed also in the sparse
case, as all "diagonalMatrix"
are also "sparseMatrix"
.
Matrix(0, 3,3)
returns a "ddiMatrix"
instead of a
"dsCMatrix"
previously. The latter is still returned from
Matrix(0, 3,3, doDiag=FALSE)
, and e.g., .symDiagonal(3,pi)
.
Also a triangular matrix, e.g., "dtrMatrix"
is detected now in
cases with NA
s.
This is both a bug fix and an API change which breaks code
that assumes Matrix(.)
to return a "CsparseMatrix"
in
cases where it now returns a "diagonalMatrix"
(which does
extend "sparseMatrix"
).
Subassignment to "diagonalMatrix"
now returns
sparse "triangularMatrix"
more often; also (sparse)
"symmetricMatrix"
.
nearPD()
gets new option: If base.matrix = TRUE
,
the resulting mat
component is a base matrix
, as
often used desired when nearPD()
is used outside the
Matrix package context.
Factored out new qr2rankMatrix()
utility from
rankMatrix()
.
New BunchKaufman(<matrix>)
method.
Added wrld_1deg
sparse matrix example to
distributed version of Matrix (no longer excluding it
via ‘.Rbuildignore’).
New (simple) mat2triplet()
function to be used instead
of summary(<sparseMatrix>)
in code.
Internal .diag2tT()
gains new option drop0 = TRUE
and hence now by default drops zero diagonal entries. Consequently,
e.g., as(<diagonalMatrix>, "CsparseMatrix")
now drops such
zeros, too.
Updated the crucial underlying C libraries from SuiteSparse,
from 4.2.1 to 5.7.1 (from 2020-02-20), visible in .SuiteSparse_version()
.
sparseMatrix()
gets new argument repr = "C"
,
superseding the (now deprecated) giveCsparse = TRUE
. Allows
to return "RsparseMatrix"
matrices.
Similarly, rsparsematrix()
, fac2sparse()
and fac2Sparse()
get the new repr
argument and their giveCsparse
is
deprecated, sometimes only informally for now.
sparse.model.matrix()
gets option sep = ""
, with,
e.g., sep = ":"
allowing to get easier column names; from
R-forge Matrix (non-)bug #6581, by Vitalie Spinu.
rankMatrix(<sparse>, method="qr")
now returns NA
(or NaN
) instead of signalling an error in the case the sparse
Q R
decomposition gave NA
s in diag(R)
.
Coercion (as(., .)
) from e.g., "lsyMatrix"
to
"CsparseMatrix"
silently made asymmetric dimnames symmetric,
as did the internal forceCspSymmetric(*, dimNames)
which may be called from forceSymmetric()
.
Adapt code to new Fortran requirements of passing length of character arguments, thanks to Brian Ripley.
(R-forge Matrix bug #6659, reported by Georg Kindermann):
<sparseVector>[i] <- val
bug fixed.
(R-forge Matrix bug #6666, reported by Ezra Tucker):
which(<ldiMatrix>, array.ind=TRUE)
thinko fixed.
For R-devel Dec 4, 2020: adapt all.equal() check of sparse matrix images (which contain panel functions with environments ..).
tried fixing warning 'cholmod_factorize_p' accessing 16 bytes in a region of size 8 [-Wstringop-overflow=] in ‘src/dsCMatrix.c’ (in two places); seen by pre-release-gcc11 compilation.
Fix last(?) PROTECT()
warning found by rchk
in
‘src/dense.c’'s ddense_skewpart()
.
as(m, "dgTMatrix")
does not lose dimnames
anymore
when m
is a (traditional) matrix
.
M[logical(0), ]
now has dimension 0 x k
for sparse
M
as for base matrices.
log(M, base)
(the 2-argument version of log()
)
wrongly gave the result for base = exp(1)
, i.e., the 1-argument default.
‘test-tools-Matrix.R’: Qidentical()
no longer assumes
class(<matrix>)
to be of length 1.
‘test-tools-1.R’: provide bug-fixed canCoerce()
in
old R versions.
(none)
Fix new PROTECT()
warnings (bugs?) found by rchk
.
Provide isFALSE()
for R < 3.5.0 as now need it for
sparseMatrix printing.
regression tests depending on sample()
now are future
proof reproducible, via RNGversion(.)
.
give information about #rows and #columns that are suppressed in print()ing if the matrix is larger than 'max.print'.
data(<Matrix-data>)
no longer attaches Matrix to
the search path.
"Ops"
group methods, i.e., "Arith", "Compare" & "Logic",
now should all work with 0-extent matrices as well, thanks to bug
reports by Aaron Lun, University of Cambridge.
when printing and formatting sparse matrices, see formatSpMatrix()
,
the maxp
option, e.g., from getOption("max.print")
, is
“rounded up” to 100, as very small values are very rarely appropriate.
image()
gets new optional argument border.color
.
image(Matrix(0, n,m))
now works.
German translation updates.
one more PROTECT()
.
Faster as(<matrix>, "sparseMatrix")
and coercion
"dgCMatrix"
, "ngCMatrix"
, etc, via new direct C
matrix_to_Csparse()
which does not go via
"dgeMatrix"
. This also works for large matrices
m
, i.e., when length(m) >= .Machine$integer.max
.
Also provide low-level R functions .m2dgC()
,
.m2lgC()
, and .m2ngC()
for these.
cbind(NULL,<Matrix>)
no longer return NULL
;
analogously for rbind()
, rbind2()
, cbind2()
,
fixing very long standing typo in the corresponsing cbind2()
and rbind2()
methods.
The deprecation warning (once per session) for
cBind()
and rBind()
finally works (fixing a simple thinko).
cbind()
and rbind()
for largish sparse
matrices no longer gives an error because of integer overflow
(in the default case where sparse
is not been specified
hence is chosen by a nnzero()
based heuristic).
.symDiagonal(5, 5:1)
and .trDiagonal(x = 4:1)
now work as expected.
Sp[i]
now is much more efficient for large sparse
matrices Sp
, notably when the result is short.
<sparseVector>[ <negative integer> ]
now also gives
the correct answer when the result is “empty”, i.e., all
zero or false.
large "dspMatrix"
and "dtpMatrix"
objects can
now be constructed via new(*, Dim = *, x = *)
also when
length(x)
is larger than 2^31 (as the C internal
validation method no longer suffers from integer overflow).
More ‘PROTECT()’ing to be “rather safe than sorry” thanks to Tomas Kalibera's check tools.
crossprod(x,y)
and kronecker(x,y)
have become
considerably more efficient for large "indMatrix"
objects
x, y
, thanks to private nudging by Boris Vaillant.
(R-forge Matrix bug #6185): c < 0
now also works for
derived sparse Matrices (which only contain Matrix
classes); via improving hidden MatrixClass()
. Part of
such derived matrices only work in R >= 3.5.0.
using Authors@R
in ‘../DESCRIPTION’ to list all
contributors.
solve(-m)
no longer should use a cached Cholesky
factorization (of m
).
S4 method dispatch no longer emits ambiguity
notes (by default) for everybody, apart from the package
maintainer. You can reactivate them by
options(Matrix.ambiguityNotes = TRUE)
rankMatrix(<matrix of all 0>)
now gives zero for all
methods, as it should be.
no longer calling length(NULL) <- <positive>
which
has been deprecated in R-devel since July.
qr.coef(<sparseQR>, y)
now finally has correct (row)
names (from pivot back permutation).
.trDiagonal()
utility is now exported.
quite a collection of new PROTECT(.)
's thanks to
Tomas Kalibera's ‘rprotect’ analysis.
"Ops"
between "table", "xtabs", and our matrices now work.
as(matrix(diag(3), 3, dimnames=rep(list(c("A","b","c")),2)),
"diagonalMatrix")@x
is no longer named.
norm(x, "2")
now works as well (and equivalently to base::norm
).
sparseVector()
now also works without x
argument.
c.sparseVector()
method for c()
of
sparseVectors (and available as regular function on purpose).
as(Diagonal(3), "denseMatrix")
no longer returns a
non-dense "ddiMatrix"
.
S[sel,] <- value
and similar no longer segfault, but
give a "not (yet?) supported"
error
for sparse matrices S
and logical sel
when
sel
contains NA
s.
The same error (instead of a low-level one) is signalled for
indexing (with NA-containing logical sel
), i.e.,
S[sel,]
.
which(x, arr.ind=TRUE, *)
(when x
is a
"lMatrix"
or "nMatrix"
) now works the same as
base::which
, obeying an optional useNames
argument
which defaults to TRUE
. Previously, the resulting
two-column matrix typically had empty dimnames
.
0-length matrix "Ops"
(binary operations) are now
compatible to R-devel (to be R 3.4.0).
C-API: SuiteSparse_long
is now defined as
int64_t
on all platforms, and we now include (C99) ‘inttypes.h’
x[.] <- value
now also works for
"sparseVector"
's, both as x
and as value
.
x[FALSE] <- value
now also works for "sparseVector"
's.
rep(x, *)
now works for "sparseVector"
s and
sparse and dense "Matrix"
-classed matrices x
.
solve(<sparse_LU>)
no gives an error in some cases of
singular matrices, where before the C code accessed illegal memory locations.
in C code, protect _POSIX_C_SOURCE by #ifdef __GLIBC__
cBind()
and rBind()
have been almost silently
deprecated in R >= 3.2.0
and now give a warning,
“once per session” only.
bandSparse(*, k=k, *)
now returns matrices inheriting from
"triangularMatrix"
when obvious from the diagonal indices k
.
KhatriRao(X,Y)
now also works when X
or
Y
is completely zero.
The 0-dim. Matrix multiplication fix in 1.2-5 did trigger wrong warnings in other diagonal matrix multiplications.
isSymmetric(m)
now also works for "indMatrix"
m
.
isSymmetric(m)
is faster for large dense asymmetric matrices.
Matrix multiplications (A %*% B
) now work correctly
when one of the matrices is diagonal and the other has a zero dimension.
sparseMatrix()
gets new argument triangular
and a smarter default for dims
when symmetric
or
triangular
is true.
as(<sparse>, "denseMatrix")
now works in more cases
when prod(dim(.))
is larger than 2^{31} - 1
.
Hence, e.g., !S
now works for much larger sparse matrices
S
.
creating very large dense matrices, e.g., by
as(<sparseM.>, "matrix")
would segfault (in case it could
allocate enough storage).
MatrixClass()
is exported now.
More exports of semi-internal functions (for speed, named
".<foo>"
, i.e., inofficial API), such as .solve.dgC.lu()
.
more Korean translations
Packages linking to Matrix (LinkingTo:
in ‘DESCRIPTION’) now find
‘alloca’ properly defined in ‘Matrix.h’ even for non-GNU
compilation environments such as on Solaris or AIX.
extended "n?CMatrix" classes (e.g., from setClass(.,
contains="ngCMatrix")
) now can be coerced via as(.)
to
"d.CMatrix"
.
The printing of largish sparse matrices is improved, notably
in the case where columns are suppressed, via new fitWidth =
TRUE
option in printSpMatrix2()
.
cbind2()
and rbind2()
no longer fail to
determine sparse
when it is unspecified and hence
NA
, fixing R-forge bug #6259.
Explicitly import from “base” packages such as "stats"
.
Our colSums(x)
, rowMeans(y)
, ..., methods
now “keep names”, i.e., if the result is a numeric vector,
and the matrix x
has column or row names, these become the
names(.)
of the result, fixing R-forge bug #6018.
"Matrix"
now has an initialization()
method
coercing 0-length dimnames components to NULL
and other
non-NULL
dimnames to character
. Before, e.g.,
numeric dimnames components partially worked, even though it has
always been documented that non-NULL
dimnames should be
character
.
For symmetricMatrix
objects which have symmetrical
dimnames by definition, it is allowed to only set one half of the
dimnames
to save storage, e.g., list(NULL, nms)
is
semantically equivalent to list(nms, nms)
.
as.vector(<sparseVector>)
etc, now work, too.
lu(<sparseMatrix>)
now keeps dimnames
.
better ‘NEWS.Rd’ (which pleases Kurt and tidy
;-)
S[] <- T
and S[] <- spV
now work (in more cases)
for sparse matrices S, T and sparseVector spV
.
Huge dense matrix multiplication did lead to segfaults, see R-help, “does segfault mean (always) a bug?”, May 5, 2015. Fixed by using C's Alloca() only in smallish cases.
Optional arguments in image()
, e.g., main=
<..>)
now also work for lgCMatrix
, nMatrix
etc;
thanks to a 4.5 years old report by Mstislav Elagin.
dimnames(A) <- val
now resets the factors
slot
to empty, as the factorizations now keep dimnames more often.
crossprod(<matrix>, Diagonal(<n>))
works again (and
these are tested more systematically).
Matrix products (%*%
, crossprod
, and
tcrossprod
) for "dtrMatrix"
are correct in all
cases, including keeping dimnames.
Matrix(d)
(and other coercions to "Matrix"
)
now correctly keeps dimnames
also when d
is a
traditional diagonal "matrix"
.
New %&%
for “boolean arithmetic” matrix product.
New argument boolArith = NA
in crossprod()
and
tcrossprod()
. boolArith = TRUE
now forces boolean
arithmetic, where boolArith = FALSE
forces numeric one.
Several of these products are more efficient thanks to new C
functionality based on our new chm_transpose_dense()
, and
others based on geMatrix_crossprod
,
geMatrix_matrix_mm
, etc.
Most dense matrix products, also for non-dgeMatrix
,
including "l..Matrix"
and "n..Matrix"
ones are now
directly handled by new .Call()
s.
"dMatrix"
(numeric) and "lMatrix"
(logical)
matrices can now be coerced to "nMatrix"
(non-zero pattern
or “boolean”) even when they contain NA
s, which then
become TRUE
s.
More thorough checking of cbind2()
and
rbind2()
methods, notably as they are called from cbind()
and rbind()
from R version 3.2.0 on.
rbind2(<dense>, <dense>)
is faster, being based on new C code.
symmetric Matrices (i.e., inheriting from
"symmetricMatrix"
) are allowed to have dimnames
of
the form list(NULL, <names>)
and now print correctly
and get correctly coerced to general matrices.
indMatrix
object (“index matrices”) no longer
need to be “skinny”.
rsparseMatrix()
now accepts rand.x = NULL
and
then creates a random pattern matrix
("nsparseMatrix"
).
anyDuplicatedT()
and uniqTsparse()
low level
utilities are exported now.
Partial Korean translations of messages.
For R \ge 3.2.0
, cBind()
and rBind()
are deprecated, as they are no longer needed since cbind()
and rbind()
do work automatically.
Fix some rbind2()
methods.
t()
now transposes the dimnames even for symmetric
matrices.
diag(M) <- val
did not always recycle val
to
full length, e.g., when M
was a "dtrMatrix"
.
crossprod(<indMatrix>)
was wrong in cases where the
matrix had all-zero columns.
Matrix products (%*%
, crossprod
, and
tcrossprod
) with one sparse and one dense argument now
return numeric (a "dMatrix"
) when they should, i.e.,
unless the new setting boolArith = TRUE
is applied.
More use of anyNA()
(for speedup).
Matrix products (%*%
, crossprod
,
tcrossprod
) now behave compatibly to R 3.2.0, i.e., more
lenient in matching dimensions for matrix - vector products.
isTriangular()
gets new optional argument upper = NA
.
crossprod()
and tcrossprod()
fixes for
several <diagonal> o <sparse> combinations.
rowMeans(<dgeMatrix>, na.rm=TRUE)
was wrong sometimes.
fix and speedup of coercions (as(., .)
) from and to
symmetric or triangular matrices.
invPerm()
coercion to integer
dimnames( solve(.,.) )
fix [r3036]
tril()
and triu()
now return correct uplo
.
names(dimnames(.))
now preserved, e.g. in
symmpart()
or subsetting (A[i,j]
).
new rsparsematrix()
for random sparse Matrices.
improved warnings, notably for unused arguments previously
swallowed into ...
.
crossprod(<vec>, <dsyMatrix>)
fixed.
crossprod()
and kronecker()
fixes for some
<indMatrix> cases.
%*%
and crossprod()
now also work with
sparseVector
s.
speedup of crossprod(v, <sparseM>)
, thanks to nudge
by Niels Richard Hansen.
new help page for all such matrix products (‘../man/matrix-products.Rd’).
image()
now gets correct ylim
again.
More consistent matrix products.
correct adaption to R 3.1.0
using tolerance
(and not ‘tol’) in all.equal()
export fast power-user coercion utilities
.dsy2mat()
, .dxC2mat()
, .T2Cmat()
, ..2dge()
.
matrix products now (mostly) work with sparseVector
s;
and correctly in some more cases.
Testing code's assertWarning()
adapted for R \le 3.0.1
.
Depends: R >= 2.15.2
eases checking.
image(.., xlim, ylim)
: nicer defaults
for the axis limits, and ylim
is sorted decreasingly; not
strictly back-compatible but should never harm.
rankMatrix(*, method="qr")
now using tol
T2graph()
and graph2T()
export old functionality explicitly.
Tweaks in conversions between "graph"
and
"sparseMatrix"
objects. Notably, as(<graph>,
<Matrix>)
now more often returns a (0/1 pattern) "n..Matrix".
sparseMatrix()
: new use.last.ij
argument.
KhatriRao()
: fix rownames (X <-> Y)
qr.coef()
, qr.fitted
, and qr.resid
now
also work with sparse RHS y
.
sparse matrix “sub assignments”, e.g., M[ii] <- v
,
speedup and fixes.
bug fixes also in M[negative indices] <- value
and
<sparseMatrix>[cbind(i,j)]
.
fac2sparse
and fac2Sparse
now exported, with a
new giveCsparse
option.
Update to latest SuiteSparse
C library by Tim Davis,
U. Florida.
ensuing “C API changes”
new .SuiteSparse_version()
function
Many ‘Imports:’ instead of ‘Depends:’.
fixed long lasting undetected solve(<dsCMatrix>, *)
bug.
Our all.equal()
methods no longer sometimes return
c("TRUE", "....difference..")
.
rankMatrix(<matrix>)
: fix the internal x.dense
definition.
Revert some wrong changes to solve(<sparse>, *)
from
1.0-13 (“stop gap fix” for R 3.0.2).
New (efficient) KhatriRao()
function by Michael Cysouw
New "indMatrix"
class of “index matrices”, a
generalization of "pMatrix"
, the permutation matrices, many
methods generalized from pMatrix to indMatrix. All (initial)
functionality contributed by Fabian Scheibl, Univ. Munich.
Export and document isDiagonal()
and
isTriangular()
as they are useful outside of Matrix.
rankMatrix(M, method="qr")
no longer needs
sval
which makes it considerably more useful for large
sparse M
.
Start providing anyNA
methods for R >= 3.1.0
.
solve(<sparse> a, <sparse> b)
: if a
is
symmetric, now compute sparse result.
nearPD()
gets new option conv.norm.type = "I"
.
determinant(<dpoMatrix>)
now uses chol()
, and
hence also an existing (‘cached’) Cholesky factor.
3 new C -> R
utilities (including hidden R function
.set.factors()
for caching also from R, not just in C).
M[] <- v
for unitriangular M
now correct.
lu(.)
no longer sometimes returns unsorted columns.
.
.
.
as(<csr>, "dgCMatrix")
(from package SparseM)
now works again.
.
.sparseDiagonal()
: new unitri
argument, and
more flexibility;
new solve(<dsCMatrix>, <missing>)
via efficient C code.
.
new sparseVector()
constructor function.
is.finite()
is.infinite()
now work for our
matrices and "*sparseVector" objects.
diag(.) <- V
now preserves symmetricity,
triangularity and even uni-triangularity sometimes.
Quite a few fixes for Ops
(arithmetic, logic, etc)
group methods.
Ditto for diagonalMatrix
methods.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
During Doug Bates' sabbatical in Zurich, Martin Maechler becomes co-author of the Matrix package.
Beginning of class reorganization with a more systematic naming scheme.
More (correct) coercions as(<from>, <to>)
.
lme4 / lmer specific R code moved out to lme4 package.
.
Doug Bates (only)
Sparse matrices, classes and methods, partly via
Interface to LDL, TAUCS, Metis and UMFPACK C libraries
.............................................
The first CRAN release of the Matrix package, titled “A Matrix library for R” authored by Douglas Bates (maintainer, principal author) and Saikat DebRoy.
Matrix()
constructor for R objects of class Matrix
.
Matrix.class()
returning informal subclasses such as
"Hermitian"
, "LowerTriangular"
is.Orthonormal()
, is.Hermitian()
,
is.UpperTriangular()
functions.
SVD()
, lu()
, and schur()
decomposition
generics with "Matrix"
methods.
rcond()
, norm()
, det()
;
expand()
and facmul()
.
C++ interface to LAPACK