Matrix \ge
1.8-0 depends on R
\ge
4.5.
Compilation uses preprocessor options -DSTRICT_R_HEADERS, -DR_NO_REMAP, and -DR_NO_REMAP_RMATH.
Warnings surfaced by -Wconversion (but not those originating in SuiteSparse) are squashed.
Matrix can be installed with parallel bmake
.
Thanks to Sebastian Meyer for the report and patch in Matrix PR#6861.
Coercions to dpoMatrix
or dppMatrix
are
deprecated. Coerce to new virtual class posdefMatrix
instead.
Methods for cov2cor
coerce the (symmetrized) argument
to new virtual class posdefMatrix
before scaling. Hence an
error is signaled where the (symmetrized) argument is not positive
definite. Use dimScale
(introduced in Matrix 1.5-2)
for more general scaling.
New virtual class posdefMatrix
representing positive
semidefinite matrices. It extends virtual class
symmetricMatrix
and is extended by nonvirtual classes
[dz]p[CRTop]Matrix
, of which dp[CRT]Matrix
and
zp[CRTop]Matrix
are new. posdefMatrix
are typically
obtained as the result of crossprod(x)
or
tcrossprod(x)
for Matrix
x
. Coercions to
posdefMatrix
attempt Cholesky factorization, which can fail
for near-singular positive semidefinite matrices.
New virtual classes idenseMatrix
and
isparseMatrix
representing dense and sparse integer
matrices. They extend iMatrix
(which existed
“forever” without an implementation) and are extended by
new nonvirtual classes i(ge|sy|sp|tr|tp|[gst][CRT])Matrix
.
New nonvirtual class idiMatrix
extending
diagonalMatrix
and iMatrix
, for diagonal integer
matrices.
New virtual classes zdenseMatrix
and
zsparseMatrix
representing dense and sparse complex
matrices. They extend zMatrix
(which existed
“forever” without an implementation) and are extended by
new nonvirtual classes z(ge|sy|sp|tr|tp|[gst][CRT])Matrix
.
zs[CRTyp]Matrix
have a trans
slot with value
"C"
or "T"
, used to distinguish between complex
Hermitian and complex symmetric matrices. They are extended by
zp[CRTop]Matrix
, which represent complex positive
semidefinite matrices (and so are contrained to have
trans="C"
)
New nonvirtual class zdiMatrix
extending
diagonalMatrix
and zMatrix
, for diagonal complex
matrices.
New generic function ct
for the conjugate transpose.
ct(x)
is equivalent to t(x)
except for complex
x
, for which it is intended to be at least as efficient as
(if not more efficient than) Conj(t(x))
.
The formal argument list of generic function
forceSymmetric
is changed from (x, uplo)
to
(x, ...)
, allowing methods to accept further arguments.
The generic function now dispatches only on x
.
The formal argument list of generic function nnzero
is changed from (x, na.counted)
to (x, ...)
,
allowing methods to accept further arguments.
The formal argument lists of generic functions
symmpart
, skewpart
, isDiagonal
, and
isTriangular
gain ...
, allowing methods to accept
further arguments.
Methods for generic functions isSymmetric
,
forceSymmetric
, symmpart
, and skewpart
gain
argument trans
to support Hermitian and symmetric modes for
complex matrices.
Methods for generic function symmpart
gain argument
uplo
for control over the uplo
slot of the result of
symmpart(<generalMatrix>)
.
sort(x, ...)
works for x
inheriting from
virtual class Matrix
or virtual class sparseVector
.
It is possible now that sort
is an implicit generic
function in package methods.
A method is defined for kappa(z, ...)
for z
inheriting from virtual class Matrix
. It computes the
reciprocal of rcond(z, ...)
and thus supports all of the
optional arguments of methods for rcond
. Hence, in
Matrix (unlike in base), kappa
and rcond
have “consistent” interfaces.
Methods for rcond
gain arguments exact
,
inverse
, and warn
providing more precise control
over behaviour and an interface more similar to the default method
for kappa
in base.
All methods for rcond
support the 2-norm.
Methods for Cholesky(A=<sparseMatrix>, ...)
gain a
logical argument force
, indicating which of
forceSymmetric(A)
and tcrossprod(A)
is factorized
when A
is not formally symmetric.
Methods for expm(x=<denseMatrix>)
are revised to
diagonalize Hermitian x
and to employ Higham's (2005)
implementation of the scaling and squaring algorithm for
non-Hermitian x
. The result for Hermitian x
is now
formally positive definite.
Methods for isSymmetric(<[dz]Matrix>)
consistently
pass countEQ = FALSE
, check.attributes = FALSE
, and
check.class = FALSE
to all.equal.numeric
. Methods
for isSymmetric(<[dz]sparseMatrix>)
consistently require a
symmetric nonzero pattern.
diag(<ndenseMatrix>)
replaces NA
with
TRUE
.
If the exact result of prod(dim(x))
is not
representable in double precision, then the result of
length(x)
is truncated towards zero and gets an attribute
off
such that the exact result of length(x) + off
is
the exact result of prod(dim(x))
.
C code uses new (since R 4.4.0) OBJSXP
in place of deprecated S4SXP
and TYPEOF(.) == OBJSXP
in place of (not specific enough) isS4(.)
.
C code is simplified using definitions in new header ‘M5.h’ for templated dispatch on object “kind” ‘[nlidz]’.
‘test-tools-1.R’: update relErrV()
, and use it
and relErr()
unconditionally to improve strict
reproducibility.
Installation under architecture-specific builds of R works again. It was broken in Matrix version 1.7-0, where changes to ‘src/Makevars’ resulted in CPPFLAGS not including -I"${R_INCLUDE_DIR}${R_ARCH}".
Internal SuiteSparse and METIS library sources are patched to avoid possible use of illegal entry points.
Registered routine sexp_as_cholmod_factor
no longer
calls cholmod_check_factor
before returning, leaving the
decision to check to the caller. Accordingly, most
cholmod_check_*
are registered; packages wanting to use
them need LinkingTo: Matrix (>= 1.7-1)
.
Non-API entry points OBJECT
, IS_S4_OBJECT
,
SET_OBJECT
, ATTRIB
, and SET_ATTRIB
are no
longer used.
Matrix \ge
1.7-0 depends on R
\ge
4.4.
The Matrix ABI version is incremented from 1 to 2.
Reverse LinkingTo
built under earlier versions of
Matrix should be rebuilt from sources by users and
maintainers of binary repositories.
The internal SuiteSparse library sources are updated from
version 5.10.1 to version 7.6.0. We have so far identified one
backwards incompatible change: since SuiteSparse version 7.3.0,
cholmod_sort(A)
sorts but does not pack the matrix
A
. It seems that now cholmod_sort
and
cholmod_copy
must be used in conjuction if a sorted
and packed result is desired. This change affects only
reverse LinkingTo
relying on the old behaviour. It seems
that currently there are no such packages on CRAN or Bioconductor.
CHOLMOD component Partition is compiled along with its dependencies (METIS, CAMD, CCOLAMD).
CXSparse is compiled instead of CSparse, which did not support complex matrices.
The internal SuiteSparse and METIS library sources are patched to squash a significant number of warnings surfaced by -Wall.
The diagonal elements of the R
factor computed by
qr(<sparseMatrix>)
are no longer constrained to be
non-negative, due to differences in the implementation of function
cs_house
between SuiteSparse libraries CSparse and
CXSparse.
indMatrix
no longer extends virtual class
compMatrix
and so no longer inherits a (never used)
factors
slot. Objects serialized under Matrix
<
1.7-0 and unserialized under Matrix \ge
1.7-0 remain valid, retaining a harmless factors
attribute.
Unexported class union replValueSp
is effectively
removed, now having zero members. Actual removal is delayed until
package binaries caching the old definition are rebuilt under
Matrix version 1.7-0.
The validity method for class sparseQR
no longer
requires non-negative diag(R)
.
The unary subscript x[i]
is correct again for
x
of class .s[CT]Matrix
and logical i
indexing entries outside of the stored triangle.
Registered routine cholmod_triplet_as_sexp
transposes
entries “opposite” the stype
when that is nonzero,
following CHOLMOD.
cholmod_defaults
is registered so that calls to
API function M_cholmod_defaults
actually work.
x[]
works for x
inheriting from virtual class
sparseVector
.
length(x)
is always an integer for x
inheriting from virtual class sparseVector
. Truncation did
not occur for x@length
of type "double"
equal to or
greater than .Machine[["integer.max"]] + 1
.
tril(<n-by-n>, -n)
now works again.
tri[ul](<indMatrix>, k)
now works correctly for
k != 0
.
%||%
is defined in the Matrix namespace only
for R <
4.4.0.
Warnings surfaced by -Wformat are squashed.
API function M_chm_triplet_to_SEXP
, removed in
Matrix version 1.6-2, is restored (as a macro). It was
“covertly” used by package Rmosek.
better deprecation message for ..2dge()
.
With an R built with configure
option
--disable-long-double, prod(M)
now very slightly
differs for two differently classed versions of M
.
checkMatrix()
from ‘test-tools-Matrix.R’ gets
optional MSG
argument for suppressing prod()
differences.
Matrix did not pass its checks under R version
3.5.0, implicitly violating Depends: R (>= 3.5)
. This
release restores compatibility.
Support is added for an ABI version relevant to packages
that link against Matrix. The ABI version is 1 in this
release and will be incremented by 1 in each future release that
changes the ABI. It is implicitly 0 in previous releases.
Versions and their components are defined in a header for use by
packages with LinkingTo: Matrix (>= 1.6-2)
in their
‘DESCRIPTION’. See ‘inst/include/Matrix/version.h’ and
(below) Matrix.Version
.
Reverse LinkingTo
built under earlier versions of
Matrix should be rebuilt from sources by users and
maintainers of binary repositories.
API headers are organized under ‘inst/include/Matrix/’
for easier namespacing. Packages should start using
LinkingTo: Matrix (>= 1.6-2)
and include the API headers
with, e.g., #include <Matrix/Matrix.h>
.
Packages including API headers can define macro
R_MATRIX_INLINE
, typically with
#define R_MATRIX_INLINE inline
, in order to allow the
compiler to inline stubs for registered routines.
Some API function prototypes and macros not used by any
reverse LinkingTo
are removed or remapped.
Several API function prototypes used const
qualifiers
where the registered routines do not.
The prototype of API function M_cholmod_band_inplace
did not match that of registered routine
cholmod_band_inplace
. The prototype of cholmod_band
was copied by mistake.
Methods for generic functions rbind2
, cbind2
,
%*%
, %&%
, crossprod
, and
tcrossprod
determine the class of the result using more
strict rules, designed to avoid “surprising” coercions
where possible. Notably, operations involving
RsparseMatrix
now return an RsparseMatrix
in more
cases. TsparseMatrix
and diagonalMatrix
may be
handled as CsparseMatrix
or as RsparseMatrix
,
depending on context.
New nonvirtual class ndiMatrix
representing diagonal
nonzero pattern matrices. It extends virtual classes
diagonalMatrix
and nMatrix
. ndiMatrix
are
typically obtained as the result of is.na
, is.nan
,
or is.infinite
applied to a diagonalMatrix
or as the
result of coercing a diagonalMatrix
to nMatrix
.
(The result of that coercion used to be an ntCMatrix
. It
is still possible to obtain an ntCMatrix
by coercion to
nsparseMatrix
.)
The validity method for class sparseVector
requires
length
not exceeding 2^53
, which on most platforms
is the minimum positive integer k
such that k + 1
is
not exactly representable in double precision.
A dsparseVector
with x
slot of type
"integer"
is formally invalid, as always intended.
Certain never or seldom used class unions are removed.
mean(<sparseVector>, trim=)
now works efficiently for
nonzero values of trim
.
rep(<sparseVector>, each=)
now works efficiently,
avoiding rep(., times = rep(each, times = length(.)))
.
.m2dense
and .m2sparse
gain an argument
trans
indicating if vectors that are not matrices should be
coerced to 1-row matrices rather than 1-column matrices.
.m2dense
and .m2sparse
can be called with one
argument. Their class
arguments admit new default values
".ge"
and ".gC"
.
.diag2dense
and .diag2sparse
gain an argument
kind
indicating the “kind” of the result.
New exports .M2V
and .m2V
, for coercing
Matrix
and matrix
(and in fact vector
) to
sparseVector
.
New exports isUniqueT
and asUniqueT
, with
optional argument byrow
allowing for row-major ordering of
entries. asUniqueT
supercedes uniqTsparse
, which is
no longer documented.
New export aggregateT
, for aggregating
TsparseMatrix
without sorting.
Methods for all.equal
now report the packages where
S4 classes are defined.
sum(x)
and prod(x)
no longer require a
coercion from symmetricMatrix
to generalMatrix
.
Results where coercions are now avoided may differ numerically due
to reordering of adds and multiplies, most commonly on systems
where sizeof(long double) == sizeof(double)
.
Methods for cbind2
and rbind2
did not in all
cases handle vectors as 1-column and 1-row matrices, respectively.
Methods for cbind2
and rbind2
did not handle
0-length vectors (including NULL
) correctly where the
result would have 0 rows and columns, respectively.
Methods for cbind2
and rbind2
did not handle
NA
in the x
slot of ndenseMatrix
correctly
(i.e., as TRUE
).
cbind2(<ndenseMatrix>, <ldenseMatrix>)
gave
ngeMatrix
instead of lgeMatrix
.
cbind2(<lsparseMatrix>, <lsparseMatrix>)
gave
dgCMatrix
instead of lgCMatrix
. Methods for
rbind2
had similar problems.
rcond(<0-by-0>)
now returns Inf
; see
PR#18543.
round(<dp[op]Matrix>)
and
signif(<dp[op]Matrix>)
now return ds[yp]Matrix
rather than dp[op]Matrix
and now discard factors
.
Methods for length
now return integer
rather
than double
if the result does not exceed INT_MAX
.
Methods for subscripting sparseVector
did not behave
compatibly with base when supplied with fractional,
NA
, or out-of-bounds subscripts.
symmpart(x)
, skewpart(x)
, band(x, k1,
k2)
, triu(x, k)
, and tril(x, k)
now always return a
.diMatrix
for x
inheriting from
diagonalMatrix
.
colSums(<(n|l|ind)Matrix>)
and
rowSums(<(n|l|ind)Matrix>)
now always give a result of type
"integer"
. Methods differed previously, some giving
"double"
(as base does, suboptimally, traditional
matrices of type "logical"
).
Some methods for generic function lu
did not transmit
Dimnames
to the result.
Some methods for group generic function Summary
ignored arguments matching ...
. Other methods did not
ignore the “garbage” elements of the x
slot of
dense, triangular matrices.
kronecker(<n.TMatrix>, <diagonalMatrix>)
threw an
error for attempting to access the nonexistent x
slot of
its first argument.
Matrix products now behave exactly as base when testing for conformable arguments.
Numeric products (%*%
) did not always return a
dMatrix
.
Methods for all.equal
now “see” attributes of
S4 objects that are not slots. This can be disabled by setting
argument check.attributes
to NA
, which is otherwise
equivalent to TRUE
.
prod(x)
is computed more diligently for x
inheriting from sparseMatrix
, sparseVector
, or
.t[rp]Matrix
, i.e., those x
that can be understood
to have “structural” zeros. Now, multiplication by zero
occurs at the position of the first structural zero in the matrix
or vector (when traversed by row in the case of
RsparseMatrix
). An exception is TsparseMatrix
, for
which multiplication by zero occurs before multiplication by any
stored entry, regardless of the position of the first structural
zero in the corresponding sorted matrix (to avoid the cost of
sorting).
tri[ul](<.t[rp]Matrix>, k)
was often wrong for
nonzero k
, setting too many bands to zero.
C-level tCsparse_diag
(formerly diag_tC
) now
handles structural zeros and NaN
on the main diagonal
correctly. Option "diagBack"
now works correctly.
expm(x)
failed for x
of class dtpMatrix
or dspMatrix
, since Matrix version 1.6-1.
.m2dense(x, ".ge")
allocated unnecessarily for
x
without attributes.
C code now refers to the symbol factors
as
Matrix_factorsSym
, rather than Matrix_factorSym
.
The content of ‘src/Mutils.[ch]’ has been migrated to more transparently named files: ‘src/attrib.[ch]’, ‘src/objects.[ch]’, etc. Similarly, much of ‘src/factorizations.[ch]’ have been migrated to ‘src/solve.[ch]’ and ‘src/determinant.[ch]’.
All matrix product code has been migrated to ‘products.[Rch]’.
Files in ‘po/’ and ‘inst/po/’ have been updated
due to more frequent use of gettextf
in ‘R/*.R’.
C code is prepared to handle complex matrices and their factorizations. Notably, new machinery in ‘src/cs-etc.[ch]’ will enable linking the CXSparse library instead of the CSparse library, the latter supporting numeric types but not complex ones.
Export the generics crossprod()
and
tcrossprod()
explicitly, needed for R-devel when they
become primitive internal generics.
Registered routine chm_sparse_to_SEXP
sorts and packs
its first argument before assigning any struct members to
variables, preventing use-after-free.
Four Valgrind-detected memory bugs are fixed.
Validity methods for classes Cholesky
and
pCholesky
test for a valid perm
slot.
Several new coercion utilities, exported and documented in
help("fastMisc")
. Some of these supercede ones made
available (experimentally) in Matrix 1.5-4; for example,
.M2m
makes both .dense2m
and .sparse2m
redundant. The superceded ones are not yet formally deprecated,
but are no longer documented.
drop0
is now implemented independently of
CHOLMOD
, becoming more efficient notably for logical
arguments, no longer requiring a coercion to double.
drop0
gains an argument give.Csparse
to
complement is.Csparse
. FALSE
indicates that
RsparseMatrix
, TsparseMatrix
, and indMatrix
arguments should be handled directly, without a coercion to
CsparseMatrix
. The default value is TRUE
, for
backwards compatibility.
<diagonalMatrix> %*% <RsparseMatrix>
works again.
diag(<non-square RsparseMatrix>) <- value
works
again, no longer giving a p
slot of length Dim[2]
rather than Dim[1]
.
as(<diagonalMatrix>, "symmetricMatrix")
now checks
for symmetric Dimnames
, for consistency.
as(<indMatrix>, "[nld](sparse)?Matrix") now returns a
.gRMatrix
or a .gCMatrix
depending on the
margin
slot.
as(<[CR]sparseMatrix>, "generalMatrix")
now checks if
the number of nonzero entries in the result would exceed
INT_MAX
and throws an error in that case.
Run speed-measuring tests only if(doExtras)
: these
were too slow when run under Valgrind.
Most coercion code has been migrated to ‘coerce.[Rch]’ from elsewhere.
The number of methods for generic functions coerce
and as.*
has been reduced substantially, from 306 to 194
(not counting deprecated ones), partly as a result of efforts to
do more fine-grained dispatch in C code.
Files in ‘po/’ and ‘inst/po/’ have been updated
(again), as many more C level messages now use format
strings as a result of vsnprintf
usage in
‘src/validity.c’.
The following “weak” dependencies, needed only for a small number of Rd cross references, are removed: MatrixModels, expm, igraph, maptools, sp, spdep. Links to CRAN or Bioconductor in Rd files are preserved.
sfsmisc is moved from Enhances
to
Suggests
, as Matrix does not formally enhance it with
methods or links to documentation.
grDevices and datasets are added to
Imports
and Suggests
, respectively, as Matrix
does import from grDevices and (in vignettes) does load data
from datasets.
Example, test, and vignette code no longer fails when
R_DEFAULT_PACKAGES is set to NULL
.
Example code uses requireNamespace
instead of
require
to preserve the user's search path.
Methods for generic function chol
that previously
returned an object of class p?Cholesky
now return an
equivalent object of class dtrMatrix
or dtpMatrix
.
Existing code that relied (correctly) on chol
to return the
upper triangular Cholesky factor as a Matrix
can be
expected to work as before.
Class indMatrix
gains a margin
slot with value
1L
or 2L
(1L
being the prototype and
previously implicit value), indicating that the object represents
a row or column index matrix, with ones at [i, perm[i]]
or
[perm[j], j]
, respectively.
Methods with indMatrix
or its subclass pMatrix
in
the signature have been adjusted to account for the new slot.
Notably, multiplication on the right by an indMatrix
with
margin = 2
is now implemented as a column subscript, and
the transpose of an indMatrix
is now the same object but
with “opposite” margin
.
Virtual class MatrixFactorization
gains a
Dimnames
slot. Now all factorizations preserve the
Dimnames
of the original, factorized Matrix
, whereas
previously classes Schur
, sparseLU
, sparseQR
,
dCHMsimpl
, and dCHMsuper
did not. Users can
get the value of the new Dimnames
slot with
dimnames(.)
and set it with dimnames(.) <- value
.
Classes p?BunchKaufman
and p?Cholesky
no
longer extend dtrMatrix
or dtpMatrix
and in turn no
longer extend Matrix
. They retain slots Dim
,
Dimnames
, uplo
, and x
, but not diag
.
This change implies that virtual classes Matrix
and
MatrixFactorization
no longer intersect.
Classes p?Cholesky
gain a perm
slot with
prototype integer(0L)
to support representation of pivoted
factorizations, as typically computed by LAPACK routine
dpstrf
. perm
of length 0 is valid and equivalent to
the identity permutation.
New nonvirtual class pcorMatrix
extending
dppMatrix
. It is the counterpart of corMatrix
using
packed storage, supporting more efficient storage of dense
correlation matrices. Now pack(<corMatrix>)
gives a
pcorMatrix
preserving the sd
slot, rather than a
dppMatrix
without an sd
slot.
New virtual classes BunchKaufmanFactorization
,
SchurFactorization
, and QR
, extended by existing
nonvirtual classes p?BunchKaufman
, Schur
, and
sparseQR
, respectively. These are parallel to the existing
virtual classes CholeskyFactorization
and LU
.
Packages defining new factorization classes may extend these.
Virtual class CHMfactor
and its subclasses gain
formal validity methods.
The validity method for class sparseQR
now tests that
the V
slot is lower trapezoidal and that the R
slot
has non-negative diagonal elements.
The validity method for class corMatrix
now tolerates
nonfinite elements in the sd
slot. It no longer tolerates
nonunit diagonal elements in the x
slot.
The prototype of the Dim
slot of virtual class
MatrixFactorization
is now integer(2L)
. It was
previously integer(0L)
, with the result that
validObject(new(<nonvirtual>))
was always an error.
The prototype of the L
slot of class sparseLU
is now formally lower triangular, so that
validObject(new("sparseLU"))
is not an error.
The prototypes of the Q
and T
slots of class
Schur
are now 0-by-0 dgeMatrix
, so that
validObject(new("Schur"))
is not an error.
New generic functions expand1
and expand2
,
intended to replace expand
and coercions from (subclasses
of) MatrixFactorization
to (subclasses of) Matrix
.
expand1
is used as
expand1(<MatrixFactorization>, <character string>)
and
constructs by name factors appearing in the factorization.
expand2
is used as expand2(<MatrixFactorization>)
and returns a named list of all factors appearing in the
factorization, in order and with row names on the first factor
and column names on the last factor. The result can be used to
reconstruct the factorized Matrix
as the product of the
elements of the list, namely
Reduce(`%*%`, expand2(.))
.
expand
and its methods are retained for backwards
compatibility. They may be formally deprecated in the future,
hence new code should use expand1
and expand2
.
Notably, expand1
and expand2
have methods for all
factorizations in Matrix, whereas expand
continues to
have methods only for denseLU
, sparseLU
, and
CHMfactor
. See help("expand-methods")
for a list of
methods, including useful optional arguments.
Methods for subscripting Matrix
now use the more
systematic code in ‘R/subscript.R’ and
‘src/subscript.c’, becoming more efficient for all
lsparseMatrix
(no longer coercing to dsparseMatrix
and back),
sparse symmetricMatrix
(no longer coercing to generalMatrix
and back when i
in x[i, i]
is monotone),
unpackedMatrix
(no longer coercing to matrix
and back), and
RsparseMatrix
(no longer coercing to TsparseMatrix
, then to
CsparseMatrix
, then back to TsparseMatrix
[!]).
x[i, j, drop = FALSE]
preserves the class of x
in
more cases where x
is a triangularMatrix
,
diagonalMatrix
, or pMatrix
, doing more complete
checks on i
and j
.
Notably, for x
inheriting from RsparseMatrix
, the
result is now always an RsparseMatrix
, rather than always a
TsparseMatrix
.
NULL
subscripts, as in x[NULL]
, x[NULL,
j]
, and x[i, NULL]
, are now supported for x
inheriting from Matrix
. They are handled as
integer(0)
, consistent with base.
Generic function Cholesky
gains methods for
denseMatrix
returning an object of class p?Cholesky
.
The method for subclass dsyMatrix
admits an argument
perm
indicating if the pivoted factorization should be
computed. The corresponding chol
method gains an argument
pivot
indicating the same. By default, Cholesky
pivots and chol
does not.
Many subclasses of MatrixFactorization
can now be
coerced to “nearby” subclasses of Matrix
. The
resulting Matrix
reflects the internal representation of
the factorization and not necessarily a particular matrix factor.
The new coercions are:
as(<denseLU>, "dgeMatrix")
,
as(<BunchKaufman>, "dtrMatrix")
,
as(<pBunchKaufman>, "dtpMatrix")
,
as(<Cholesky>, "dtrMatrix")
,
as(<pCholesky>, "dtpMatrix")
,
as(<CHMsimpl>, "dtCMatrix")
, and
as(<CHMsuper>, "dgCMatrix")
.
See help("denseLU-class")
(and similar) for details.
determinant(x, ...)
and solve(a, b, ...)
now work for x
and a
inheriting from
MatrixFactorization
, behaving as if x
and a
were replaced by the factorized Matrix
. The exception is
x
inheriting from CHMfactor
, where for backwards
compatibility the default behaviour is still to compute the
determinant of the Cholesky factor. This exception should be
considered temporary, hence defensive code will call
determinant
with (new) optional argument sqrt
set to
TRUE
or FALSE
explicitly, to not rely on the current
default value. See help("CHMfactor-class")
for details.
Generic function diag
gains methods for
p?Cholesky
and CHMfactor
. The result is a numeric
vector containing the diagonal entries of the diagonal matrix
D
, as defined in help("Cholesky-class")
and
help("CHMfactor-class")
.
The lu
and qr
methods for class
dgCMatrix
now admit an order
argument with value in
0:3
, allowing the expert user to choose among all ordering
methods made available by the CSparse library.
solve(<dgCMatrix>, b, sparse = TRUE)
is now handled
entirely in C code via cs_spsolve
from the
CSparse library.
New utilities invertPerm
, signPerm
,
isPerm
, and asPerm
for computing the inverse and
sign of a permutation vector, testing if an integer vector is a
permutation vector, and coercing a transposition vector to a
permutation vector. invertPerm
is a more general version
of the already exported function invPerm
, which is retained
as a wrapper around invertPerm
for backwards compatibility.
The qr.R
method for class sparseQR
gains a
backPermute
argument with default FALSE
, for
compatibility with base. Function qrR
, which existed
primarily to provide a back-permuting option, is retained for
backwards compatibility.
x[integer(0), ]
and x[, integer(0)]
now give a
generalMatrix
result when x
is a 0-by-0
diagonalMatrix
, for consistency with all other cases of
x[seq_len(n), ]
and x[, seq_len(n)]
, where x
is an n
-by-n
triangular, symmetric, or diagonal
matrix.
For x
inheriting from RsparseMatrix
,
subassignment of the form x[i, ] <- value
is now correctly
distinguished from x[i] <- value
.
rownames(x[integer(0), , drop = FALSE])
and
colnames(x[, integer(0), drop = FALSE])
are now always
NULL
and never character(0)
, consistent with the
implementation in base.
Subscript operations on Matrix
now correctly error
whenever the formal argument ... is matched, as in x[i,
j, drop]
, where x[i, j, drop = drop]
is almost always
intended.
x[i, ]
now correctly drops dimensions when x
is a 1-by-n
Matrix
and i
is TRUE
.
Methods for solve
now obey the following rules much
more strictly:
solve(a=<Matrix>, b=<vector>)
must return a vector.
solve(a=<denseMatrix>, b=<Matrix>)
must return a denseMatrix
.
solve(a=<sparseMatrix>, b=<Matrix>, sparse=FALSE)
must return a denseMatrix
.
solve(a=<sparseMatrix>, b=<Matrix>, sparse=TRUE)
must return a sparseMatrix
.
resolving some longstanding incompatibilities with base.
Note that methods for sparse a
and missing or sparse
b
have default sparse = TRUE
, while methods for
sparse a
and dense b
have default
sparse = FALSE
.
solve(<symmetricMatrix>)
now always gives a
symmetricMatrix
result. solve(<dpoMatrix>)
and
solve(<dppMatrix>)
preserve formal positive definiteness,
giving a dpoMatrix
and dppMatrix
, respectively.
BunchKaufman(<matrix>)
now works when argument
uplo
(documented to be optional) is missing.
Coercions to corMatrix
now set the diagonal elements
of the result to 1, consistent with cov2cor
.
dimnames(x) <- value
now validates x@Dim
before value
to avoid undefined behaviour in C-level check.
chol2inv(x)
now ignores the lower triangular part of
x
not inheriting from triangularMatrix
.
chol2inv(x)
now computes crossprod(solve(x))
instead of tcrossprod(solve(x))
for all formally lower
triangular x
. Previously, crossprod
was used only
for dense x
.
rcond(x, norm)
throws a nicer error for x
of
length 0.
Error messages due to invalid norm
in rcond(x,
norm)
now refer to the argument as norm
rather than
type
.
rcond(x, norm)
now validates norm
also for
x
of class d(sy|sp|po|pp)Matrix
, even if for such
x
all valid norm
give the same result.
which(<[RT]sparseMatrix>, ...)
now gives indices in
column-major order in all cases, to be consistent with
help("which")
.
Factorizations inheriting from virtual class LU
are
now cached under the name denseLU
or sparseLU
,
depending on the nonvirtual class, rather than always under the
name LU
. Note that user code should not rely on the
details of the cache and should instead rely on functions such as
lu
to retrieve cached factorizations.
Errors signaled by as(<dsyMatrix>, "dpoMatrix")
and
as(<dspMatrix>, "dppMatrix")
now clarify that the coercions
do not attempt to test for positive semidefiniteness when the
matrix is not positive definite.
invPerm(p)
no longer segfaults for p
that are
not valid permutation vectors. invPerm(NA)
was enough to
trigger a segfault.
C code interfacing the CSparse library tests in
more places for failed allocations inside of cs_*
.
Help pages for matrix factorization classes and methods have been broadly expanded and updated to use consistent notation.
The length of the Matrix namespace has been reduced by ~15%. More than 100 unused symbols have been removed.
Updates to ‘po/*.{po,pot}’ and ‘inst/po/*’ for translators.
‘src/Lapack-etc.h’ uses #ifdef PR18534fixed
,
adapting to PR#18534 without breaking installation under R
<
4.3.1.
sequence.default
is defined for R <
4.0.0.
‘Rinternals.h’ is included in
‘inst/include/Matrix.h’ instead of deprecated
‘Rdefines.h’. The inclusion is done outside of
extern "C"
.
The following low level coercion utilities, which were
previously exported but always “hidden” and undocumented,
are now deprecated: ..2dge
, .C2nC
, .T2Cmat
,
.asmatrix
, .dense2sy
, .diag2mat
,
.diag2sT
, .diag2tT
, .dsy2dsp
,
.dsy2mat
, .dxC2mat
, .m2dgC
, .m2lgC
,
.m2ngC
, .m2ngCn
, .m2ngTn
, .n2dgT
,
.nC2d
, .nC2l
.
The deprecations follow efforts to define more general and more
systematic (but still fast) coercion utilities, to allow expert
users to bypass S4 dispatch in more cases. The subset of these
currently exported is documented under help("fastMisc")
.
Deprecation warnings will suggest an appropriate replacement,
mostly from that list.
It is not always the case that the replacement can be
“dropped in”, hence users should consult the relevant
documentation when changing their code.
Warnings signaled by coercion methods deprecated in
Matrix 1.5-0 now correctly inherit from class
deprecatedWarning
.
Calls to sprintf
are replaced by equivalent calls
snprintf
to avoid potential buffer overflow.
C-level utilities Matrix_memset()
and
Matrix_memcpy()
, both new, are now used in many places
instead of API macros Memzero()
and Memcpy()
which
never check for overflow. C-level macro AZERO()
is no
longer defined.
C-level macro Calloc_or_Alloca_TO()
now
zero-initializes also in the alloca
-using case.
methods is moved from Imports
to Depends
as suggested in the WRE manual. Now as
and other basic S4
machinery are available whenever Matrix is attached. This
change affects R processes started with environment variable
R_DEFAULT_PACKAGES set to NULL
(or any list not
containing methods).
Test involving sparse POSIXlt
in
‘tests/Simple.R’ is adapted to possible (unconditional since
R version 4.3.0) existence of character component zone
.
dimScale(x)
with argument d1
missing is no
longer an error. (The default value had diag(x, FALSE)
instead of diag(x, names = FALSE)
.)
(dim|row|col)Scale(x)
is no longer an error for
traditional matrices x
without a dimnames
attribute.
Our cov2cor()
methods now again preserve
(symmetrized!) dimnames
, fixing Matrix PR#6783 reported by
Ben Bolker.
colSums()
and friends now always give a named
result when the marginal Dimnames
are non-NULL
.
(Names were “forgotten” for diagonalMatrix
and
indMatrix
arguments.)
colSums()
and friends now respect na.rm
when
handling diagonalMatrix
with NA
diagonal entries.
expand(<denseLU>)
now “copies-on-modify”, no
longer duplicating the m*n
-length x
slot in the
m == n
case, when it can be used directly.
lu(<m-by-0>)
, lu(<0-by-n>)
, and
BunchKaufman(<0-by-0>)
now give sensible (0-extent)
results, rather than a LAPACK error, for denseMatrix
.
Diagonal()
gets a new optional names
argument.
diag(x) <- value
is now done in C also for
[CRT]sparseMatrix
.
.diagU2N()
gets fast counterpart .diagN2U()
.
colSums()
and friends are now implemented more
efficiently for denseMatrix
and [CRT]sparseMatrix
.
Notably, methods for triangular and symmetric matrices no longer
go via generalMatrix
, and methods for
[CRT]sparseMatrix
now handle nonzero pattern and logical
matrices directly (no longer coercing to double, a constraint of
the earlier implementation using CHOLMOD).
determinant(<ds[yp]Matrix>)
is now computed via the
Bunch-Kaufman factorization. Factorizations are cached in the
factors
slot for future reuse.
C-level wrappers for LAPACK d..trf
routines gain an
argument warn
indicating how to handle info > 0
:
warn <= 0
is silent, warn = 1
is a warning, and
warn > 1
is an error. In the case of dp[op]trf
, for
which info > 0
implies an incomplete factorization,
info
is now returned as a length-1 integer.
The validity methods for classes l[st]CMatrix
now
correctly test for structurally nonzero entries on the wrong side
of the main diagonal, and fail in that case. Previously, this
test was performed only for d[st]Matrix
.
The validity method for virtual class sparseVector
is
more diligent, catching more edge cases such as NA
in the
length
or i
slot.
New validity methods for n[st][CRT]Matrix
,
Schur
, denseLU
, p?BunchKaufman
,
p?Cholesky
, sparseLU
, and sparseQR
. Notably,
the following properties of factorizations are now checked: the
dimensions of each factor, the orientation of each triangular (or
trapezoidal) factor, and the validity of each permutation vector.
lu(x)@L@uplo
is now "L"
, not "U"
, for
0-by-0 and 1-by-1 dgCMatrix
x
.
The validity method for corMatrix
now throws a better
error when the sd
slot is of type "integer"
rather
than "double"
.
.sparseDiagonal()
now agrees with Diagonal()
when called with no arguments, returning a 0-by-0 (rather than
1-by-1) diagonal Matrix
.
sparseMatrix(i, j)
with 0-length i
and
j
now returns a 0-by-0 matrix rather than throwing a
perplexing error.
sparseMatrix(dims = <list>)
and
sparseMatrix(x = <dMatrix>)
now produce errors.
diag(x) <- value
now coerces diagonalMatrix
x
if typeof(value)
is “higher” than
typeof(x@x)
in the usual hierarchy, for consistency with
methods for denseMatrix
and with base::`diag<-`
.
Methods for kronecker()
no longer ignore the
make.dimnames
argument.
Printing a sparseMatrix
with NA
row or column
names is no longer an error.
Products of two pMatrix
objects x
and y
are now computed correctly. Previously, y %*% x
was
returned instead of x %*% y
!
Products x %*% y
with x
a
diagonalMatrix
or indMatrix
and y
a
traditional matrix or vector, or with x
a traditional
matrix or vector and y
a diagonalMatrix
or
pMatrix
, now treat the unclassed argument as a
.geMatrix
and return a .geMatrix
, for greater
consistency with other products involving one Matrix
and
one non-Matrix
.
Similarly, kronecker(x, y)
with one of x
and
y
a Matrix
and the other a traditional matrix or
vector now treats the unclassed argument as a .geMatrix
.
dimnames(solve(x))
is now rev(dimnames(x))
for
denseMatrix
x
, consistent with the handling of
dimnames
by solve.default
. Methods for
sparseMatrix
x
have not been addressed (yet).
In many more (but not yet all) places, C
functions protect the values of R_do_slot
,
Rf_getAttrib
, Rf_mkString
, etc. from garbage
collections, squashing many new and some old rchk
warnings.
is.nan(x)
is now implemented for all x
inheriting from virtual class Matrix
or
sparseVector
.
Diagonal(n=, x=)
now recycles x
of any
positive length to length n
. Previously, recycling was
supported only for x
of length 1.
Products involving diagonalMatrix
or indMatrix
have been broadly improved as follows:
dimnames(A %*% B)
is now always
c(dimnames(A)[1], dimnames(B)[2])
.
t?crossprod()
methods involving indMatrix
or
its subclass pMatrix
gain a boolArith
argument.
Numeric and boolean products are always returned as
dMatrix
and nMatrix
, respectively, except in a few
special cases where the product can be represented as an
indMatrix
. (Previously, coercions were skipped when one
of the operands was unit diagonal.)
Products of diagonalMatrix
with dense
triangularMatrix
now correctly give a
triangularMatrix
result (and without unpacking).
Products of diagonalMatrix
with
[RT]sparseMatrix
now preserve storage, no longer coercing
to CsparseMatrix
.
crossprod(x, y)
no longer requires the product of
ncol(x)
and ncol(y)
to be less than 2^31
when both x
and y
are indMatrix
. (The new
implementation now always gives a dgTMatrix
result,
whereas previously the result would typically but not always be
a dgCMatrix
.)
kronecker(<Matrix>, <Matrix>)
now gives the correct
“shape” (general, [unit] triangular, symmetric, diagonal)
in all cases where it can be known without checking.
kronecker(<[CR]sparseMatrix>, <Matrix>)
now retains
the storage of the first argument, no longer coercing to
TsparseMatrix
.
New exported functions dimScale
, rowScale
, and
colScale
, for scaling rows and columns of a
[mM]atrix
without losing dimnames
and where
appropriate without losing symmetry.
ASan-detected memory bugs are fixed in C
functions Tsparse_as_CRsparse
and pMatrix_validate
.
The former was triggered by .T2C(<0-by-0>)
and the latter
was triggered by as(<length-10000 integer>, "pMatrix")
.
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.
New virtual class unpackedMatrix
representing dense
matrices in unpacked format. It extends denseMatrix
and is
extended by [nld](ge|sy|tr)Matrix
, i.e., the subclasses of
denseMatrix
not extending packedMatrix
.
The validity method for dppMatrix
requires
non-negative diagonal elements, matching the validity method for
dpoMatrix
.
The validity method for Matrix
tolerates vector types
other than "character"
for Dimnames[[i]]
.
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 PR#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.
Fixed the (quite long standing) Matrix PR#6777, reported
by Manuel Koller: tcrossprod(<matrix>, <[dln]sCMatrix>)
has
been wrong in some cases.
qr(<big sparse>)
could segfault due to integer
overflow inside of cs_multiply
. Now an error is signaled
indicating “out of memory”. Reported by Benjamin Tyner
as Matrix PR#6610.
Valgrind warning originating in cholmod_sdmult
is squashed. Reported by David Cortes as Matrix PR#6726.
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.
Virtual class unpackedMatrix
gains 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
.
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.
Some warnings surfaced by -Wconversion are squashed.
tryInvokeRestart
is defined for R <
4.0.0.
Thanks to Michael Chirico for the report.
The patch for header ‘SuiteSparse_config/SuiteSparse_config.h’ is improved for Windows.
New virtual class packedMatrix
representing dense
matrices in packed format. It extends denseMatrix
and is
extended by [nld](sp|tp)Matrix
.
Protection stack imbalances detected by rchk
are
fixed.
diag(x)
methods now mostly also keep names
from dimnames(x)
by default and obey names=*
more
generally.
Methods for subscripting packedMatrix
, 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
.
Modified AZERO()
to work with R_xlen_t
and new
AZEROs()
for size_t
.
‘inst/test-tools-1.R’: Sys.memGB
returns
NA.value = 2.10201
on Windows, no longer calling
memory.limit
which is a stub since R version 4.2.0.
Several low level functions are adjusted to avoid integer
overflow in i+j*m
or similar. Reported by Dario Strbenac
on the R-devel mailing list (“dgTMatrix Segmentation
Fault”, June 10, 2021).
Leak in as(<dtCMatrix>, "denseMatrix")
when the
argument is unit triangular is fixed. Thanks to Bill Dunlap for
the report and patch in PR#18204.
Leak in crossprod(<dsCMatrix>)
is fixed. Thanks to
Bill Dunlap for the report and patch in PR#18205.
Leaks in solve(<dgCMatrix>, <ddenseMatrix>)
and
lu(<dgCMatrix>)
and when the argument is near-singular (or
when memory is exhausted) are fixed. Thanks to Bill Dunlap for
the report and patch in PR#18206.
Leaks in [cr]bind2(x, y)
when both arguments are
sparse and exactly one is nonzero pattern are fixed. Thanks to
Bill Dunlap for the report and patch in PR#18210.
solve(<dsCMatrix>, ...)
restarts after catching
warnings signaled from dsCMatrix_*_solve
so that memory is
freed rather than leaked. Thanks to Bill Dunlap for the report
and patch in PR#18214.
sparse.model.matrix(.., contrasts.arg = <.. ddiMatrix
..>)
now works correctly, fixing Matrix PR#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
Matrix PR#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.
band(M, k1, k2)
now also works when k1 * k2
is
larger than 2^31-1, the maximal integer, fixing Matrix PR#6743 by
Ariel Paulson. Further, it works when M
is a sparse
symmetricMatrix
but the band is not symmetric,
k1 != -k2
.
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 PR#6745.
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 PR#6751.
No longer include ‘Rdefines.h’ as it is somewhat deprecated.
Tests are further revised for length mismatch warning in
matrix(data, nrow, ncol)
under R \ge
4.2.0.
Matrix \ge
1.3-3 depends on R
\ge
3.5, relaxing the dependency on R \ge
3.6 introduced in Matrix version 1.3-0.
Tests are revised for length mismatch warning in
matrix(data, nrow, ncol)
under R \ge
4.2.0.
‘inst/include/cholmod.h’ and ‘inst/include/Matrix_stubs.c’ needed adjustment after the SparseSuite update in Matrix version 1.3-0. Matrix PR#6714 reported by Kasper Kristensen, who maintains TMB.
cBind()
and rBind()
are now defunct: simply
use cbind()
and rbind()
instead.
Class unions Mnumeric
and numericVectors
are
removed. These were unexported and unused but nonetheless
visible to users, appearing as superclasses of many basic classes.
Notably, a proposed change to the validity method for
Mnumeric
would have broken class factor
, which
extended Mnumeric
but would not have been valid under the
proposal.
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 an RsparseMatrix
, Matrix PR#6709 by David Cortes.
as.matrix()
and as.array()
now work for
sparseVector
as expected; see Matrix PR#6708.
M[,]
(and similar) now work as in base R;
Matrix PR#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
; Matrix PR#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()
. Matrix PR#6606, reported by Thomas Lumley.
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.
Eliminating the need for ‘ftp://*’, add the very small
jgl009
MatrixMarket example to our ‘external/’ files.
USE_FC_LEN_T
is defined before ‘Rconfig.h’ is
included. Under R \ge
3.6.2, the effect is that
FC_LEN_T
is defined when ‘R_ext/BLAS.h’ is included,
and the result is that ‘R_ext/BLAS.h’ defines FCONE
as a nonempty value suitable for passing character lengths from
C to Fortran.
matrix_trf
protects two more objects from garbage
collection, squashing two rchk
warnings.
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.
chol(<diagonal dt[CRT]Matrix>)
now works.
rankMatrix(<dense>, method="qr.R")
no longer assumes
non-negative diagonal entries of the R
matrix.
Matrix \ge
1.3-0 depends on R
\ge
3.6.
Macro FCONE
is defined and used to pass character
lengths from C to Fortran under R \ge
3.6.2 (without breaking installation under older R). Thanks
to Brian Ripley.
The internal SuiteSparse library sources are updated from
version 4.2.1 to version 5.7.1. The change is visible in
.SuiteSparse_version()
.
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.
sparseMatrix()
gets new argument repr = "C"
,
superseding the (now deprecated) giveCsparse = TRUE
.
Allows to return RsparseMatrix
.
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 Matrix PR#6581, by Vitalie Spinu.
The second argument in calls to cholmod_factorize_p
from internal_chm_factor
was a pointer to 1 double
instead of a double
array of length 2, resulting in buffer
overflow there.
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()
.
Matrix PR#6659, reported by Georg Kindermann:
<sparseVector>[i] <- val
bug is fixed.
Matrix PR#6666, reported by Ezra Tucker:
which(<ldiMatrix>, array.ind=TRUE)
thinko is fixed.
For R-devel Dec 4, 2020: adapt all.equal() check of sparse matrix images (which contain panel functions with environments).
‘inst/test-tools-1.R’: a bug-fixed canCoerce
is used under R <
3.6.2.
ddense_skewpart
protects another object from garbage
collection, squashing a remaining rchk
warning.
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.
isFALSE
is defined for R <
3.5.0.
C functions protect more objects from garbage
collection, squashing several rchk
warnings.
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.
dgCMatrix_cholsol
protects one more object from
garbage collection, squashing an rchk
warning.
Faster as(<matrix>, "sparseMatrix")
and coercion to
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.
C functions protect more objects from garbage
collection, to be “rather safe than sorry”. Thanks to
Tomas Kalibera's rchk
tools.
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).
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.
Matrix PR#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 \ge
3.5.0.
using Authors@R
in ‘../DESCRIPTION’ to list all
contributors.
solve(-m)
no longer should use a cached Cholesky
factorization (of m
).
length(<NULL>) <- value
is avoided as it is
deprecated in R \ge
3.5.0.
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.
qr.coef(<sparseQR>, y)
now finally has correct (row)
names (from pivot back permutation).
.trDiagonal()
utility is now exported.
C functions protect more objects from garbage
collection. Thanks to Tomas Kalibera's rchk
tools.
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
.
Methods for Ops
handle 0-length operands more
consistently, matching changes planned for R version 3.4.0.
SuiteSparse_long
is defined as int64_t
on all
platforms. Hence we now include C99 header ‘inttypes.h’.
The internal CSparse library sources are patched to avoid
buffer overflow in cs_usolve
and cs_utsolve
when
U
is singular.
x[.] <- value
now also works for
sparseVector
, both as x
and as value
.
x[FALSE] <- value
now also works for
sparseVector
.
rep(x, *)
now works for sparseVector
and
sparse and dense Matrix
-classed matrices x
.
_POSIX_C_SOURCE
is defined conditionally with
#ifdef __GLIBC__
.
cBind()
and rBind()
have been almost silently
deprecated in R \ge
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).
‘inst/include/Matrix.h’ tries harder to define
‘alloca’ correctly for compilers that do not define
__GNUC__
.
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
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 Matrix PR#6259.
Objects are more systematically imported from “base” packages like stats. It is no longer assumed that those packages are attached.
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 Matrix PR#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
.
as.vector(<sparseVector>)
etc, now work, too.
lu(<sparseMatrix>)
now keeps dimnames
.
better ‘NEWS.Rd’ (which pleases Kurt and
tidy
;-)
Using alloca
to perform large allocations could
overflow the stack, leading in some cases to a segfault. Now
alloca
is used only for small allocations. Thanks to a
report on the R-help mailing list (“does segfault mean
(always) a bug?”, May 5, 2015).
S[] <- T
and S[] <- spV
now work (in more
cases) for sparse matrices S, T and sparseVector spV
.
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 generic function %&%
for boolean matrix
multiplication: that is, matrix multiplication using boolean
arithmetic.
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 \ge
3.2.0.
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.
Methods for matrix multiplication (%*%
,
crossprod
, tcrossprod
) are revised to match the
behaviour of R \ge
3.2.0, which better tolerates
matrix-vector products.
More use of anyNA()
(for speedup).
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.
Matrix \ge
1.1-1.1 depends on R
\ge
2.15.2 to ease checking.
‘inst/test-tools-1.R’: assertCondition
is
defined for R <
3.0.2 and used by assertWarning
there.
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)]
.
methods, stats, utils, and lattice
are moved from Depends
to Imports
.
The internal SuiteSparse library sources are updated to the
latest version. Use new function .SuiteSparse_version
to
get the version in use.
‘inst/include/cholmod.h’ is updated to reflect changes
in SuiteSparse. Notably, there were changes in the layout of the
various cholmod_*_struct
.
fac2sparse
and fac2Sparse
now exported, with a
new giveCsparse
option.
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 nonvirtual class indMatrix
representing row index
matrices, i.e., matrices whose rows are standard unit vectors. It
extends sparseMatrix
and is extended by pMatrix
, the
class of permutation matrices.
New generic functions isTriangular
and
isDiagonal
for testing if the argument is (upper or lower)
triangular or diagonal. These were defined previously but never
exported or documented.
Many methods for pMatrix
are generalized to support
indMatrix
. All (initial) functionality was contributed by
Fabian Scheibl, Univ. Munich.
New (efficient) KhatriRao()
function by Michael
Cysouw
rankMatrix(M, method="qr")
no longer needs
sval
which makes it considerably more useful for large
sparse M
.
Start providing anyNA
methods for R \ge
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 Douglas Bates' sabbatical in Zurich, Martin Maechler becomes co-author of Matrix.
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.
.
Matrix version 0.8-2 is a full refactor. Classes, generic functions, and methods are newly implemented in S4. S3 machinery is removed. The remaining items in this section describe the state of things in version 0.8-2 rather than changes since version 0.3-26.
Matrix \ge
0.8-2 depends on R
\ge
1.9.0.
Depends: methods
is added to ‘DESCRIPTION’.
Douglas Bates becomes the sole author of Matrix.
The package is retitled “Classes and Methods for Numerical Linear Algebra using LAPACK, LDL, TAUCS, METIS, and UMFPACK”.
The package sources are now maintained in a Subversion repository.
The default expressions of formal arguments transpose
and left
of generic function facmul
are changed from
F
and T
to FALSE
and TRUE
, as only the
latter are reserved words.
S3 generic function determinant
is removed as it was
ported to R \ge
1.8.0.
A namespace for Matrix is defined using directives in ‘NAMESPACE’.
S3 generic functions eigen
, expand
,
facmul
, lu
, norm
, rcond
, schur
,
and unpack
are exported.
S3 methods are registered and not exported, hence they continue to be available but only through calls to exported S3 generic functions.
Functions Matrix
, SVD
, as.Matrix
,
diagDet
, and hilbert
are exported.
Functions Matrix.class
, *.test
, and
is.*
are exported but intended only for internal use.
Functions asObject
and prependClass
are not
exported.
Load hook .First.lib
is removed and replaced by a
useDynLib
directive in ‘NAMESPACE’.
S3 generic function det
is renamed
determinant
.
determinant.Matrix
(formerly det.Matrix
)
computes the LU
factorization of its argument instead of the
QR
factorization.
Matrix \ge
0.3-23 depends on R
\ge
1.7.0.
‘configure’, ‘configure.in’, ‘configure.win’,
‘cleanup’, ‘src/Makevars.in’, and
‘src/Makevars.win’ are removed and replaced by a simple
‘src/Makevars’ arranging for Matrix to use R's
LAPACK_LIBS
and BLAS_LIBS
. The simplification is
made possible by R version 1.7-0, which is configured by
default to build, link against, and install a shared LAPACK.
Empty directory ‘data’ is removed.
The package is retitled “Classes and Methods for Numerical Linear Algebra using LAPACK”.
‘configure.win’ and ‘src/Makevars.win’ are added to support installation under Windows, thanks to Brian Ripley.
More #undef
in the C++ sources to support
installation under Windows, thanks to Brian Ripley.
‘configure.ac’ sets CFLAGS
before expanding
AC_PROG_CC
and sets FLIBS
before expanding
ACX_BLAS
and ACX_LAPACK
.
Autoconf macro OCTAVE_BLAS_LIBS
, which is no longer
used, is removed from ‘aclocal.m4’.
Unwanted Autoconf output is removed from ‘aclocal.m4’.
PACKAGE = "Matrix"
is passed to .Call
to
restrict name lookup to Matrix.
The C++ sources use qualified name lookup (as in
std::<name>
) in more places.
The C++ sources get pointers to matrix data without taking the address of the first element, which is wrong for a matrix of length 0.
*_ELT
macros are no longer defined for R <
1.2.0 as Matrix depends on R \ge
1.5.0.
Matrix \ge
0.3-17 depends on R
\ge
1.5.0.
‘configure.in’ is replaced by ‘configure.ac’
contributed by Kurt Hornik. ‘configure.ac’ makes use of
R CMD config
, a utility added in R version 1.5-0.
Autoconf macros ACX_BLAS
and ACX_LAPACK
,
written by Steven G. Johnson, are added to ‘aclocal.m4’ and
expanded in ‘configure.ac’.
The configured value of LAPACK_LIBS
is prepended to
PKG_LIBS
in ‘src/Makevars.in’.
A preliminary ‘ChangeLog’.
Rd files are adapted to use \method{}{}
markup
introduced in R version 1.2.2.
One usage of .Alias
, deprecated in R version
1.4.1, is removed.
S3 methods gain formal argument ...
where needed to
match the generic function.
The name of a class member function in ‘src/tgmd.h’ was was spuriously qualified.
The configured value of BLAS_LIBS
is prepended to
PKG_LIBS
in ‘src/Makevars.in’.
The C++ sources undefine macros length
and
append
in many places to allow for class member functions
with those names.
The C++ sources use qualified name lookup (as in
std::<name>
) in more places.
The C++ sources no longer write to stderr
and (in most places) stdout
, no longer use the
assert
macro, and no longer call exit
.
‘DESCRIPTION’ gets a Maintainer
field and
Douglas Bates is named there.
Removes around 100 non-source files wrongly bundled in Matrix version 0.3-7.
FLIBS
is appended to PKG_LIBS
in
‘src/Makevars.in’.
A basic ‘README’.
Matrix \ge
0.3-6 depends on R
\ge
1.1.1.
‘configure’ makes use of HAVE_F77_UNDERSCORE
in
‘Rconfig.h’.
PKG_LIBS
and PKG_LDFLAGS
to the configured
values of LIBS
and LDFLAGS
in ‘src/Makevars.in’.
eigen.Matrix
argument schur
, which was unused,
is removed.
An S3 method schur.Matrix
interfacing LAPACK routine
dgeesx
. It returns list(values, schur, vectors)
.
For arguments not inheriting from Matrix
subclass
Hermitian
, eigen.Matrix
is now an interface to
LAPACK routine dgeevx
, and its optional arguments
balance
and rcond
, which were unused, can now be
used to request balancing and the reciprocal condition numbers of
the eigenvalues and right eigenvectors. The return value is now
list(values, vectors, rcond)
with
vectors = list(left, right)
and
rcond = list(values, vectors)
.
‘configure’ skips the check for BLAS in the Sun
Performance Library if the C compiler is gcc
.
STRING_ELT
, SET_STRING_ELT
, VECTOR_ELT
,
and SET_VECTOR_ELT
are used in place of STRING
and
VECTOR
. *_ELT
macros are defined for R <
1.2.0 to not break compatibility.
SVD(x, nu = 0, nv)$u
and SVD(x, nu, nv = 0)$vt
are NULL
rather than empty matrices.
An S3 method lu.Matrix
interfacing LAPACK routine
dgetrf
. It returns list(l, u, permutation)
, with
attribute norms = list(one, infinity)
containing the one
and infinity norms. An optional argument is provided to disable
computation of one
and infinity
.
SVD(x, nu, nv)
allocated for the right singular
values a matrix with dimensions c(ncol(x), nv)
instead of
c(nv, ncol(x))
. Buffer overflow could occur in LAPACK
routine dgesvd
if nv < ncol(x)
.
S3 generic function eigen
.
An S3 method eigen.Matrix
interfacing LAPACK routines
dgeev
and dsyev
, the latter only for arguments
inheriting from Matrix
subclass Hermitian
. It
returns list(values, vectors)
, where vectors
is
list(left, right)
for non-Hermitian
arguments and a
numeric matrix for Hermitian
arguments. An optional
argument is provided to disable computation of vectors
.
S3 methods det.Matrix
, det.UpperTriangular
,
det.UnitUpperTriangular
, det.LowerTriangular
, and
det.UnitLowerTriangular
computing the modulus of the
determinant or its logarithm. These return
list(modulus, sign)
. Component modulus
has a
logical attribute logarithm
indicating if the determinant
is sign * exp(modulus)
or sign * modulus
.
det.Matrix
computes the QR
factorization of its
argument using LAPACK routine dgeqrf
.
Matrix.class(x)
could be incomplete or contain bad
elements for orthogonal x
.
A function as.Matrix
for coercing an object to
class Matrix
, parallel to as.matrix
. The return
value inherits from subclasses of Matrix
if tests for
structure are satisfied.
Functions asObject
and prependClass
for
setting and prepending to the class
attribute of the
argument.
A function diagDet
for computing the determinant of a
triangular matrix given the diagonal entries.
A ‘configure’ script detecting options for linking BLAS
and LAPACK. It is generated from ‘configure.in’ which makes
use of an Autoconf macro OCTAVE_BLAS_LIBS
defined in
‘aclocal.m4’.
‘src/Makevars’ is now generated from ‘src/Makevars.in’.
A ‘cleanup’ script removing generated files.
A Texinfo manual ‘R-Matrix.texi’ containing implementation details and describing how LAPACK++ was modified for Matrix.
An S3 method rcond.Matrix
interfacing LAPACK routines
d*con
.
Exceptions thrown by LAPACK++ are caught and handled as R errors.
UpperTriangular.test
and LowerTriangular.test
returned a maximum rather than a maximum modulus for real
arguments.
Matrix version 0.2-1 is the first one to be distributed by CRAN.
The package is titled “A Matrix Library for R”.
Douglas Bates is the maintainer and principal author. Saikat DebRoy is a co-author.
Matrix \ge
0.2-1 depends on R
\ge
1.1.0.
A modified LAPACK++ (Linear Algebra PACKage in C++, version 1.1a) is compiled alongside the Matrix sources. LAPACK++ is a C++ interface to LAPACK originally developed by Roldan Pozo.
S3 class Matrix
with subclasses Hermitian
,
UpperTriangular
(recursively, UnitUpperTriangular
),
and LowerTriangular
(recursively,
UnitLowerTriangular
). Objects are traditional numeric
matrices with a class
attribute indicating their
structural properties. Objects are interfaced in C++
using the parallel class hierarchy defined by LAPACK++.
S3 generic functions det
, expand
,
facmul
, lu
, norm
, rcond
, schur
,
and unpack
.
An S3 method norm.Matrix
interfacing LAPACK routines
dlan*
.
An S3 method solve.Matrix
interfacing LAPACK routines
d*trf
and d*trs
.
An S3 method as.matrix.Matrix
just dropping the class
attribute.
An S3 method print.Matrix
just printing the
as.matrix
result.
A function Matrix
constructing objects of class
Matrix
from numeric vectors and matrices, parallel to
base function matrix
.
A function Matrix.class
returning a character vector
containing the subclasses of Matrix
that would be valid for
the argument.
Functions Hermitian.test
,
UpperTriangular.test
, LowerTriangular.test
,
Orthogonal.test
, and Orthonormal.test
returning a
maximum modulus distance useful for testing the respective
property.
Functions is.Hermitian
, is.UpperTriangular
,
is.LowerTriangular
, and is.Orthonormal
testing if
the *.test
value does not exceed a tolerance.
Function SVD
interfacing LAPACK routine
dgesvd
. SVD(x, nu, nv)
returns
list(d, u, vt)
containing the singular values (sorted
non-increasingly), first nu
left singular vectors (stored
column-wise), and first nv
right singular vectors (stored
row-wise).
Function hilbert
constructing the n
-by-n
Hilbert matrix.