NEWS | R Documentation |
News for R Package Matrix
Changes in version 1.7-1 (2024-10-17 r4948)
Bug Fixes
Installation under architecture-specific builds of R works again. It was broken in version 1.7-0, where changes to ‘src/Makevars’ resulted in CPPFLAGS not including -I"${R_INCLUDE_DIR}${R_ARCH}".
Misc
Registered routine
sexp_as_cholmod_factor
no longer callscholmod_check_factor
before returning, leaving the decision to check to the caller. Accordingly, mostcholmod_check_*
are now registered, though packages calling them must useLinkingTo: Matrix (>= 1.7-1)
.Internal SuiteSparse and METIS libraries are further patched to avoid possible use of illegal entry points.
Non-API entry points
OBJECT
,IS_S4_OBJECT
,SET_OBJECT
,ATTRIB
, andSET_ATTRIB
are no longer used.
Changes in version 1.7-0 (2024-03-16 r4662)
Significant User-Visible Changes
The internal collection of SuiteSparse libraries is updated from version 5.10.1 to version 7.6.0. Hence 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.
We have so far identified one backwards incompatible change: since SuiteSparse version 7.3.0,cholmod_sort(A)
sorts but does not pack the matrixA
. It seems that nowcholmod_sort
andcholmod_copy
must be used in conjuction if a sorted and packed result is desired. This change affects only reverseLinkingTo
relying on the old behaviour. (It seems that currently there are no such packages on CRAN or Bioconductor.)The diagonal elements of the
R
factor computed byqr(<sparseMatrix>)
are no longer constrained to be non-negative, due to differences in the implementation of functioncs_house
between SuiteSparse libraries CSparse and CXSparse. Accordingly, the validity method for classsparseQR
no longer complains about negativediag(R)
.-
indMatrix
no longer extends virtual classcompMatrix
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 harmlessfactors
attribute. -
Matrix version 1.7-0 and higher strictly depend on R
\ge
4.4.0.
New Features
CHOLMOD component Partition is now compiled along with its dependencies (METIS, CAMD, CCOLAMD).
CXSparse is now compiled instead of CSparse, which did not support complex matrices.
Bug Fixes
CHOLMOD sources are patched to address the significant number of compiler warnings surfaced by -Wall.
The unary subscript
x[i]
is correct again forx
of class.s[CT]Matrix
and logicali
indexing entries outside of the stored triangle.
Misc
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 1.7-0.
Changes in version 1.6-5 (2024-01-06 r4560)
Bug Fixes
-
x[]
works forx
inheriting from virtual classsparseVector
. -
length(x)
is always an integer forx
inheriting from virtual classsparseVector
. Truncation did not occur forx@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 fork != 0
. -
C API function
cholmod_triplet_as_sexp
transposes entries “opposite” thestype
when that is nonzero, following CHOLMOD. -
R_init_Matrix
did not registercholmod_defaults
, so calls to the corresponding stub did not work.
Misc
-
%||%
is defined in the Matrix namespace only for R<
4.4.0.
Changes in version 1.6-4 (2023-11-29 r4523)
Bug Fixes
-
printf
format mismatches detected by R-devel are fixed in 3 ‘src/*.c’. better deprecation message for
..2dge()
.
Misc
Entry point
M_chm_triplet_to_SEXP
, removed in Matrix version 1.6-2, is restored (as a macro). It was “covertly” used by package Rmosek.
Changes in version 1.6-3 (2023-11-13 r4513)
Misc
With an R built with
configure
option --disable-long-double,prod(M)
now very slightly differs for two differently classed versions ofM
.-
checkMatrix()
from ‘test-tools-Matrix.R’ gets optionalMSG
argument for suppressingprod()
differences.
Changes in version 1.6-2 (2023-11-05 r4503)
Significant User-Visible Changes
Methods for generic functions
rbind2
,cbind2
,%*%
,%&%
,crossprod
, andtcrossprod
determine the class of the result using more strict rules, designed to avoid “surprising” coercions where possible. Notably, operations involvingRsparseMatrix
now return anRsparseMatrix
in more cases.TsparseMatrix
anddiagonalMatrix
may be handled asCsparseMatrix
or asRsparseMatrix
, depending on context.
New Features
New R function
Matrix.Version
, taking no arguments and returninglist(package, abi, suitesparse)
, a list containing the numeric versions of the package, its ABI, and the internal SuiteSparse library. ABI versioning is new: the version is 1 in this release and will be incremented by 1 in each future release that changes the ABI. Versions and their components are defined in a header for use by packages withLinkingTo: Matrix
in ‘DESCRIPTION’. See ‘inst/include/Matrix/version.h’.New nonvirtual class
ndiMatrix
, extending virtual classesdiagonalMatrix
andnMatrix
, for nonzero pattern diagonal matrices. It is used to represent the result ofis.na
,is.nan
,is.infinite
applied todiagonalMatrix
, as well as diagonal boolean products. Coercionsas(<diagonalMatrix>, "nMatrix")
now givendiMatrix
instead ofntCMatrix
. The latter can for now still be obtained by coercing tonsparseMatrix
instead ofnMatrix
.New C-level validity methods for
sparseVector
and[nlidz]sparseVector
, now requiringlength
not exceeding2^53
, which on most platforms is the maximum integer representable exactly asdouble
.-
mean(<sparseVector>, trim=)
now works efficiently for nonzero values oftrim
. -
rep(<sparseVector>, each=)
now works efficiently, avoidingrep(., times = rep(each, times = length(.)))
. -
.m2dense
and.m2sparse
gain an argumenttrans
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. Theirclass
arguments admit new default values".ge"
and".gC"
. -
.diag2dense
and.diag2sparse
gain an argumentkind
indicating the “kind” of the result. New exports
.M2V
and.m2V
, for coercingMatrix
andmatrix
(and in factvector
) tosparseVector
.New exports
isUniqueT
andasUniqueT
, with optional argumentbyrow
allowing for row-major ordering of entries.asUniqueT
supercedesuniqTsparse
, which is no longer documented.New export
aggregateT
, for aggregatingTsparseMatrix
without sorting.Methods for
all.equal
now report the packages where S4 classes are defined.-
sum(x)
andprod(x)
no longer require a coercion fromsymmetricMatrix
togeneralMatrix
. Results where coercions are now avoided may differ numerically due to reordering of adds and multiplies, most commonly on systems wheresizeof(long double) == sizeof(double)
.
Bug Fixes
Methods for
cbind2
andrbind2
did not in all cases handle vectors as 1-column and 1-row matrices, respectively.Methods for
cbind2
andrbind2
did not handle 0-length vectors (includingNULL
) correctly where the result would have 0 rows and columns, respectively.Methods for
cbind2
andrbind2
did not handleNA
in thex
slot ofndenseMatrix
correctly (i.e., asTRUE
).-
cbind2(<ndenseMatrix>, <ldenseMatrix>)
gavengeMatrix
instead oflgeMatrix
.cbind2(<lsparseMatrix>, <lsparseMatrix>)
gavedgCMatrix
instead oflgCMatrix
. Methods forrbind2
had similar problems. -
rcond(<0-by-0>)
now returnsInf
; see PR#18543. -
round(<dp[op]Matrix>)
andsignif(<dp[op]Matrix>)
now returnds[yp]Matrix
rather thandp[op]Matrix
and now discardfactors
. Methods for
length
now returninteger
rather thandouble
if the result does not exceedINT_MAX
.-
dsparseVector
withx
slot of typeinteger
are now formally invalid, as always intended. 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)
, andtril(x, k)
now always return a.diMatrix
forx
inheriting fromdiagonalMatrix
. -
colSums(<(n|l|ind)Matrix>)
androwSums(<(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 transmitDimnames
to the result.Some methods for group generic function
Summary
ignored arguments matching...
. Other methods did not ignore the “garbage” elements of thex
slot of dense, triangular matrices.-
kronecker(<n.TMatrix>, <diagonalMatrix>)
threw an error for attempting to access the nonexistentx
slot of its first argument. Matrix products now behave exactly as base when testing for conformable arguments.
Numeric products (
%*%
) did not always return adMatrix
.Methods for
all.equal
now “see” attributes of S4 objects that are not slots. This can be disabled by setting argumentcheck.attributes
toNA
, which is otherwise equivalent toTRUE
.-
prod(x)
is computed more diligently forx
inheriting fromsparseMatrix
,sparseVector
, or.t[rp]Matrix
, i.e., thosex
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 ofRsparseMatrix
). An exception isTsparseMatrix
, 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 nonzerok
, setting too many bands to zero. C-level
tCsparse_diag
(formerlydiag_tC
) now handles structural zeros andNaN
on the main diagonal correctly. Option"diagBack"
now works correctly.The prototype of API function
M_cholmod_band_inplace
was wrongly copied fromcholmod_band
, instead of fromcholmod_band_inplace
.Many API function prototypes wrongly used
const
qualifiers where the registered routines do not.-
expm(x)
failed forx
of classdtpMatrix
ordspMatrix
, since Matrix version 1.6-1. -
.m2dense(x, ".ge")
allocated unnecessarily forx
without attributes.
Misc
C code now refers to the symbol
factors
asMatrix_factorsSym
, rather thanMatrix_factorSym
.Certain never or seldom used class unions are removed.
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.
Some API declarations and macros not used by any reverse
LinkingTo
are removed or remapped.API headers are now nested under ‘inst/include/Matrix/’ for better namespacing. Where possible, packages should start to use
LinkingTo: Matrix (>= 1.6-2)
and include files from the new subdirectory, e.g., with#include <Matrix/Matrix.h>
.Users including API headers can define macro
R_MATRIX_INLINE
, typically with#define R_MATRIX_INLINE inline
, to allow the compiler to inline stubs for registered routines.-
Matrix did not pass its checks under R 3.5.0, implicitly violating
Depends: R (>= 3.5.0)
. This release restores compatibility.
Changes in version 1.6-1.1 (2023-09-08)
Misc
Export the generics
crossprod()
andtcrossprod()
explicitly, needed for R-devel when they become primitive internal generics.
Changes in version 1.6-1 (2023-08-11 r4228)
New Features
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 ofCHOLMOD
, becoming more efficient notably for logical arguments, no longer requiring a coercion to double. -
drop0
gains an argumentgive.Csparse
to complementis.Csparse
.FALSE
indicates thatRsparseMatrix
,TsparseMatrix
, andindMatrix
arguments should be handled directly, without a coercion toCsparseMatrix
. The default value isTRUE
, for backwards compatibility.
Bug Fixes
Fix four Valgrind-detected memory bugs.
-
<diagonalMatrix> %*% <RsparseMatrix>
works again. -
diag(<non-square RsparseMatrix>) <- value
works again, no longer giving ap
slot of lengthDim[2]
rather thanDim[1]
. -
as(<diagonalMatrix>, "symmetricMatrix")
now checks for symmetricDimnames
, for consistency. as(<indMatrix>, "[nld](sparse)?Matrix") now returns a
.gRMatrix
or a.gCMatrix
depending on themargin
slot.-
as(<[CR]sparseMatrix>, "generalMatrix")
now checks if the number of nonzero entries in the result would exceedINT_MAX
and throws an error in that case. Validity checks on the
perm
slot of classesCholesky
andpCholesky
have been enabled (forgotten in Matrix 1.6-0).API C function
chm_sparse_to_SEXP
now sorts and packs its first argument before assigning struct members to variables, no longer accessing blocks of memory freed bycholmod_sort
.
Misc
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
andas.*
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’.
Changes in version 1.6-0 (2023-06-30 r4125)
Significant User-Visible Changes
Class
indMatrix
gains amargin
slot with value1L
or2L
(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 withindMatrix
or its subclasspMatrix
in the signature have been adjusted to account for the new slot. Notably, multiplication on the right by anindMatrix
withmargin = 2
is now implemented as a column subscript, and the transpose of anindMatrix
is now the same object but with “opposite”margin
.Virtual class
MatrixFactorization
gains aDimnames
slot. Now all factorizations preserve theDimnames
of the original, factorizedMatrix
, whereas previously classesSchur
,sparseLU
,sparseQR
,dCHMsimpl
, anddCHMsuper
did not. Users can get the value of the newDimnames
slot withdimnames(.)
and set it withdimnames(.) <- value
.Classes
p?BunchKaufman
andp?Cholesky
no longer extenddtrMatrix
ordtpMatrix
and in turn no longer extendMatrix
. They retain slotsDim
,Dimnames
,uplo
, andx
, but notdiag
. This change implies that virtual classesMatrix
andMatrixFactorization
no longer intersect.Classes
p?Cholesky
gain aperm
slot with prototypeinteger(0L)
to support representation of pivoted factorizations, as typically computed by LAPACK routinedpstrf
.perm
of length 0 is valid and equivalent to the identity permutation.Methods for generic function
chol
that previously returned an object of classp?Cholesky
now return an equivalent object of classdtrMatrix
ordtpMatrix
. Existing code that relied (correctly) onchol
to return the upper triangular Cholesky factor as aMatrix
can be expected to work as before.
New Features
Methods for subscripting
Matrix
now use the more systematic code in ‘R/subscript.R’ and ‘src/subscript.c’, becoming more efficient for alllsparseMatrix
(no longer coercing todsparseMatrix
and back), sparsesymmetricMatrix
(no longer coercing togeneralMatrix
and back wheni
inx[i, i]
is monotone),unpackedMatrix
(no longer coercing tomatrix
and back), andRsparseMatrix
(no longer coercing toTsparseMatrix
, then toCsparseMatrix
, then back toTsparseMatrix
[!]).
x[i, j, drop = FALSE]
preserves the class ofx
in more cases wherex
is atriangularMatrix
,diagonalMatrix
, orpMatrix
, doing more complete checks oni
andj
.
Notably, forx
inheriting fromRsparseMatrix
, the result is now always anRsparseMatrix
, rather than always aTsparseMatrix
.-
NULL
subscripts, as inx[NULL]
,x[NULL, j]
, andx[i, NULL]
, are now supported forx
inheriting fromMatrix
. They are handled asinteger(0)
, consistent with base. New nonvirtual class
pcorMatrix
extendingdppMatrix
. It is the counterpart ofcorMatrix
using packed storage, supporting more efficient storage of dense correlation matrices. Nowpack(<corMatrix>)
gives apcorMatrix
preserving thesd
slot, rather than adppMatrix
without ansd
slot.New virtual classes
BunchKaufmanFactorization
,SchurFactorization
, andQR
, extended by existing nonvirtual classesp?BunchKaufman
,Schur
, andsparseQR
, respectively. These are parallel to the existing virtual classesCholeskyFactorization
andLU
. 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 checks that theV
slot is lower trapezoidal and that theR
slot has non-negative diagonal elements.New generic functions
expand1
andexpand2
, intended to eventually replaceexpand
and certain coercions from (subclasses of)MatrixFactorization
to (subclasses of)Matrix
.expand1
is used asexpand1(<MatrixFactorization>, <character string>)
and constructs by name factors appearing in the factorization.expand2
is used asexpand2(<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 factorizedMatrix
as the product of the elements of the list, namelyReduce(`%*%`, expand2(.))
.
expand
and its methods are retained for backwards compatibility. They may be formally deprecated in the future, hence new code should useexpand1
andexpand2
. Notably,expand1
andexpand2
have methods for all factorizations in Matrix, whereasexpand
continues to have methods only fordenseLU
,sparseLU
, andCHMfactor
. Seehelp("expand-methods")
for a list of methods, including useful optional arguments.Generic function
Cholesky
gains methods fordenseMatrix
returning an object of classp?Cholesky
. The method for subclassdsyMatrix
admits an argumentperm
indicating if the pivoted factorization should be computed. The correspondingchol
method gains an argumentpivot
indicating the same. By default,Cholesky
pivots andchol
does not.Many subclasses of
MatrixFactorization
can now be coerced to “nearby” subclasses ofMatrix
. The resultingMatrix
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")
, andas(<CHMsuper>, "dgCMatrix")
. Seehelp("denseLU-class")
(and similar) for details.-
determinant(x, ...)
andsolve(a, b, ...)
now work forx
anda
inheriting fromMatrixFactorization
, behaving as ifx
anda
were replaced by the factorizedMatrix
. The exception isx
inheriting fromCHMfactor
, 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 calldeterminant
with (new) optional argumentsqrt
set toTRUE
orFALSE
explicitly, to not rely on the current default value. Seehelp("CHMfactor-class")
for details. Generic function
diag
gains methods forp?Cholesky
andCHMfactor
. The result is a numeric vector containing the diagonal entries of the diagonal matrixD
, as defined inhelp("Cholesky-class")
andhelp("CHMfactor-class")
.The
lu
andqr
methods for classdgCMatrix
now admit anorder
argument with value in0: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 viacs_spsolve
from the CSparse library. New utilities
invertPerm
,signPerm
,isPerm
, andasPerm
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 functioninvPerm
, which is retained as a wrapper aroundinvertPerm
for backwards compatibility.The
qr.R
method for classsparseQR
gains abackPermute
argument with defaultFALSE
, for compatibility with base. FunctionqrR
, which existed primarily to provide a back-permuting option, is retained for backwards compatibility.
Bug Fixes
-
x[integer(0), ]
andx[, integer(0)]
now give ageneralMatrix
result whenx
is a 0-by-0diagonalMatrix
, for consistency with all other cases ofx[seq_len(n), ]
andx[, seq_len(n)]
, wherex
is ann
-by-n
triangular, symmetric, or diagonal matrix. For
x
inheriting fromRsparseMatrix
, subassignment of the formx[i, ] <- value
is now correctly distinguished fromx[i] <- value
.-
rownames(x[integer(0), , drop = FALSE])
andcolnames(x[, integer(0), drop = FALSE])
are now alwaysNULL
and nevercharacter(0)
, consistent with the implementation in base. Subscript operations on
Matrix
now correctly error whenever the formal argument ... is matched, as inx[i, j, drop]
, wherex[i, j, drop = drop]
is almost always intended.-
x[i, ]
now correctly drops dimensions whenx
is a 1-by-n
Matrix
andi
isTRUE
. 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 adenseMatrix
. -
solve(a=<sparseMatrix>, b=<Matrix>, sparse=FALSE)
must return adenseMatrix
. -
solve(a=<sparseMatrix>, b=<Matrix>, sparse=TRUE)
must return asparseMatrix
.
resolving some longstanding incompatibilities with base.
Note that methods for sparsea
and missing or sparseb
have defaultsparse = TRUE
, while methods for sparsea
and denseb
have defaultsparse = FALSE
.-
-
solve(<symmetricMatrix>)
now always gives asymmetricMatrix
result.solve(<dpoMatrix>)
andsolve(<dppMatrix>)
preserve formal positive definiteness, giving adpoMatrix
anddppMatrix
, respectively. The prototype of the
Dim
slot of virtual classMatrixFactorization
is nowinteger(2L)
. Previously it wasinteger(0L)
, with the result thatvalidObject(new("<nonvirtual subclass>"))
was always an error.The prototype of the
L
slot of classsparseLU
is now formally lower triangular, so thatvalidObject(new("sparseLU"))
is not an error.The prototypes of the
Q
andT
slots of classSchur
are now 0-by-0dgeMatrix
, so thatvalidObject(new("Schur"))
is not an error.-
BunchKaufman(<matrix>)
now works when argumentuplo
(documented to be optional) is missing. The validity method for class
corMatrix
now tolerates nonfinite elements in thesd
slot. It no longer tolerates nonunit diagonal elements in thex
slot.Coercions to
corMatrix
now set the diagonal elements of the result to 1, consistent withcov2cor
.-
dimnames(x) <- value
now validatesx@Dim
beforevalue
to avoid undefined behaviour in C-level check. -
invPerm(p)
no longer segfaults forp
that are not valid permutation vectors. (invPerm(NA)
was enough to trigger a segfault.) -
chol2inv(x)
now ignores the lower triangular part ofx
not inheriting fromtriangularMatrix
. -
chol2inv(x)
now computescrossprod(solve(x))
instead oftcrossprod(solve(x))
for all formally lower triangularx
. Previously,crossprod
was used only for densex
. -
rcond(x, norm)
throws a nicer error forx
of length 0. Error messages due to invalid
norm
inrcond(x, norm)
now refer to the argument asnorm
rather thantype
.-
rcond(x, norm)
now validatesnorm
also forx
of classd(sy|sp|po|pp)Matrix
, even if for suchx
all validnorm
give the same result. -
which(<[RT]sparseMatrix>, ...)
now gives indices in column-major order in all cases, to be consistent withhelp("which")
. Factorizations inheriting from virtual class
LU
are now cached under the namedenseLU
orsparseLU
, depending on the nonvirtual class, rather than always under the nameLU
. Note that user code should not rely on the details of the cache and should instead rely on functions such aslu
to retrieve cached factorizations.Errors signaled by
as(<dsyMatrix>, "dpoMatrix")
andas(<dspMatrix>, "dppMatrix")
now clarify that the coercions do not attempt to test for positive semidefiniteness when the matrix is not positive definite.
Misc
Help pages for matrix factorization classes and methods have been broadly expanded and updated to use consistent notation.
C code interfacing the CSparse library now checks in more places for failed allocations inside of
cs_*()
.The length of the Matrix namespace has been reduced by ~15%. More than 100 unused symbols have been removed.
The following dependencies, needed only for a small number of
Rd
cross references, have been removed: MatrixModels, expm, igraph, maptools, sp, spdep. Links to CRAN and Bioconductor in ‘.Rd’ files are preserved throughout.-
sfsmisc has been moved from
Enhances
toSuggests
, as Matrix does not formally enhance it by providing methods, etc. -
grDevices and datasets have been added to
Imports
andSuggests
, respectively, as ‘NAMESPACE’ does import from grDevices and vignettes do load data (albeit unconditionally) from datasets. Example, test, and vignette code no longer fails when R_DEFAULT_PACKAGES is set to
NULL
, thanks to additional “invisible”library
calls in the problematic source files.Examples now use
requireNamespace
instead ofrequire
, preserving the user search path in more cases.Updates to ‘po/*.{po,pot}’ and ‘inst/po/*’ for translators.
Changes in version 1.5-4.1 (2023-05-16)
Misc
Use
#ifdef PR18534fixed
to adapt to R's Lapack header fix for PR#18534.
Changes in version 1.5-4 (2023-04-02 r3837)
Deprecated and Defunct
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 underhelp("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
.
Bug Fixes
Defining
sequence.default
for R<
4.0.0, so thatkronecker(<CsparseMatrix>, <CsparseMatrix>)
,kronecker(<CsparseMatrix>, <diagonalMatrix>)
, and<diagonalMatrix> %*% <denseMatrix>
continue to work there.
Misc
C-level utilities
Matrix_memset()
andMatrix_memcpy()
, both new, are now used in many places instead of API macrosMemzero()
andMemcpy()
which never check for overflow. C-level macroAZERO()
is no longer defined.C-level macro
Calloc_or_Alloca_TO()
now zero-initializes also in thealloca
-using case.Replace deprecated
Rdefines.h
withRinternals.h
and move inclusion outside ofextern "C"
wrapper in API header ‘inst/include/Matrix.h’.Replace
sprintf
withsnprintf
globally to avoid potential buffer overflows.
Changes in version 1.5-3 (2022-11-10 r3772)
Bug Fixes
-
dimScale(x)
with argumentd1
missing is no longer an error. (The default value haddiag(x, FALSE)
instead ofdiag(x, names = FALSE)
.) -
(dim|row|col)Scale(x)
is no longer an error for traditional matricesx
without adimnames
attribute. Our
cov2cor()
methods now again preserve (symmetrized!)dimnames
, fixing Matrix bug #6783 reported by Ben Bolker.-
colSums()
and friends now always give a named result when the marginalDimnames
are non-NULL
. (Names were “forgotten” fordiagonalMatrix
andindMatrix
arguments.) -
colSums()
and friends now respectna.rm
when handlingdiagonalMatrix
withNA
diagonal entries. -
expand(<denseLU>)
now “copies-on-modify”, no longer duplicating them*n
-lengthx
slot in them == n
case, when it can be used directly. -
lu(<m-by-0>)
,lu(<0-by-n>)
, andBunchKaufman(<0-by-0>)
now give sensible (0-extent) results, rather than a LAPACK error, fordenseMatrix
.
New Features
-
Diagonal()
gets a new optionalnames
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 fordenseMatrix
and[CRT]sparseMatrix
. Notably, methods for triangular and symmetric matrices no longer go viageneralMatrix
, 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 thefactors
slot for future reuse.
Misc
Package methods has been moved from
Imports
toDepends
, as suggested in the WRE manual. Nowas()
and other basic S4 machinery are available whenever Matrix is attached. This change affects R processes started with environment variable R_DEFAULT_PACKAGES set toNULL
(or some list not containing methods).-
‘Simple.R’ test for sparse
"POSIXlt"
example adapted to latest R-devel always having"zone"
which is character. C-level wrappers for LAPACK
d..trf
routines gain an argumentwarn
indicating how to handleinfo > 0
:warn <= 0
is silent,warn = 1
is a warning, andwarn > 1
is an error. In the case ofdp[op]trf
, for whichinfo > 0
implies an incomplete factorization,info
is now returned as a length-1 integer.
Changes in version 1.5-2 (2022-10-21 r3702)
Bug Fixes
C-level functions now
PROTECT()
the result ofR_do_slot()
,getAttrib()
,mkString()
, etc. in many more (but not yet all) places, resolving many new and some oldrchk
warnings.-
lu(x)@L@uplo
is now"L"
, not"U"
, for 0-by-0 and 1-by-1dgCMatrix
x
. The validity methods for classes
l[ts]CMatrix
now correctly test for structurally nonzero entries on the wrong side of the diagonal, and fail in that case. This test was previously only performed ford[ts]Matrix
.The validity and initialization methods for virtual class
sparseVector
are more diligent, i.e., catching more edge cases such asNA
in thelength
ori
slot.The validity method for
corMatrix
now throws a better error when thesd
slot is of type"integer"
rather than"double"
.-
.sparseDiagonal()
now agrees withDiagonal()
when called with no arguments, returning a 0-by-0 (rather than 1-by-1) diagonalMatrix
. -
sparseMatrix(i, j)
with 0-lengthi
andj
now returns a 0-by-0 matrix rather than throwing a perplexing error. -
sparseMatrix(dims = <list>)
andsparseMatrix(x = <dMatrix>)
now produce errors. -
diag(x) <- value
now coercesdiagonalMatrix
x
iftypeof(value)
is “higher” thantypeof(x@x)
in the usual hierarchy, for consistency with methods fordenseMatrix
and withbase::`diag<-`
. Methods for
kronecker()
no longer ignore themake.dimnames
argument.Printing a
sparseMatrix
withNA
row or column names is no longer an error.Products of two
pMatrix
objectsx
andy
are now computed correctly. Previously,y %*% x
was returned instead ofx %*% y
!Products
x %*% y
withx
adiagonalMatrix
orindMatrix
andy
a traditional matrix or vector, or withx
a traditional matrix or vector andy
adiagonalMatrix
orpMatrix
, now treat the unclassed argument as a.geMatrix
and return a.geMatrix
, for greater consistency with other products involving oneMatrix
and one non-Matrix
.Similarly,
kronecker(x, y)
with one ofx
andy
aMatrix
and the other a traditional matrix or vector now treats the unclassed argument as a.geMatrix
.-
dimnames(solve(x))
is nowrev(dimnames(x))
fordenseMatrix
x
, consistent with the handling ofdimnames
bysolve.default
. Methods forsparseMatrix
x
have not been addressed (yet).
New Features
-
is.nan(x)
is now implemented for allx
inheriting from virtual classMatrix
orsparseVector
. New C-level validity methods for
n[ts][CRT]Matrix
,p?Cholesky
,p?BunchKaufman
,Schur
,denseLU
,sparseLU
, andsparseQR
. Notably, in theMatrixFactorization
cases, the following properties are now checked: the dimensions of each factor, the orientation of each triangular (or trapezoidal) factor, and the validity of each permutation vector.-
Diagonal(n=, x=)
now recyclesx
of any positive length to lengthn
. Previously, recycling was supported only forx
of length 1. Products involving
diagonalMatrix
orindMatrix
have been broadly improved as follows:-
dimnames(A %*% B)
is now alwaysc(dimnames(A)[1], dimnames(B)[2])
. -
t?crossprod()
methods involvingindMatrix
or its subclasspMatrix
gain aboolArith
argument. Numeric and boolean products are always returned as
dMatrix
andnMatrix
, respectively, except in a few special cases where the product can be represented as anindMatrix
. (Previously, coercions were skipped when one of the operands was unit diagonal.)Products of
diagonalMatrix
with densetriangularMatrix
now correctly give atriangularMatrix
result (and without unpacking).Products of
diagonalMatrix
with[RT]sparseMatrix
now preserve storage, no longer coercing toCsparseMatrix
.-
crossprod(x, y)
no longer requires the product ofncol(x)
andncol(y)
to be less than2^31
when bothx
andy
areindMatrix
. (The new implementation now always gives adgTMatrix
result, whereas previously the result would typically but not always be adgCMatrix
.)
-
-
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 toTsparseMatrix
. New exported functions
dimScale
,rowScale
, andcolScale
, for scaling rows and columns of a[mM]atrix
without losingdimnames
and where appropriate without losing symmetry.
Changes in version 1.5-1 (2022-09-12 r3642)
Bug Fixes
ASAN-detected bugs fixed in C-level functions
Tsparse_as_CRsparse()
(triggered by.T2C(<0-by-0>)
) andpMatrix_validate()
(triggered byas(<length-10000 integer>, "pMatrix")
).
Changes in version 1.5-0 (2022-09-09 r3636)
Deprecated and Defunct
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 optionMatrix.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, theNA
case signals messages rather than warnings with coercions to the most-used non-virtual subclasses ofMatrix
, namelydg.Matrix
andd.CMatrix
. This may change in the future.
Bug Fixes
Symmetrization of
<Matrix>@Dimnames
anddimnames(<matrix>)
now goes through C utilitysymmDN()
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 avoidsisNewList
, which had allowed an error message suggesting thatNULL
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 adpoMatrix
. Now the result is always one of the more general.(ge|tr|sy|tp|sp)Matrix
. -
t(<corMatrix>)
no longer clears thesd
slot.t(<p?BunchKaufman>)
now returns one of the more generaldt[rp]Matrix
, rather than preserving class and clearing theperm
slot. -
t(<symmetricMatrix>)
no longer reverses theDimnames
slot. Symmetrization ofdn <- x@Dimnames
andt(x)@Dimnames
had given different results whendn[[1]]
anddn[[2]]
were non-NULL
and asymmetric. -
isTriangular(x, upper)
had incorrectly returnedFALSE
forx
of classtriangularMatrix
whenupper = TRUE
andx@uplo = "L"
or whenupper = FALSE
andx@uplo = "U"
.isTriangular
is now equivalent toisDiagonal
in those cases. -
isSymmetric()
was equivalent toisDiagonal()
for triangular matrices, not allowing numerical fuzz via an argumenttol
. Atol
argument is now implemented for all subclasses ofdMatrix
except for those inheriting fromsymmetricMatrix
ordiagonalMatrix
. Methods for
isSymmetric
now also look atDimnames
andnames(Dimnames)
, followingisSymmetric.matrix
from base. See also New Features.-
band(x, -k, k)
for sparsex
usedisSymmetric(x)
(which tolerates numerical fuzz) to test for symmetry, resulting in loss of information in some cases. Now it tests thatx
inherits fromsymmetricMatrix
, and so returnssymmetricMatrix
in fewer cases. -
triu(x, k)
andtril(x, k)
incorrectly requiredk <= m
(instead ofk <= n
), form
-by-n
sparsex
. They now accept allk
from-m
ton
, with fewer errors in them < n
case. -
crossprod(<Rsparse>, <Tsparse>)
and similar now work again (optionalboolArith
was not passed on), fixing Matrix bug #6766 by David Cortes. Ditto fortcrossprod()
, 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 viaMatrix()
, for greater consistency with coercions todMatrix
andlMatrix
. (Previously, the result was always anngTMatrix
.) -
forceSymmetric(<[RT]sparseMatrix>)
are now more efficient, returning symmetric[RT]sparseMatrix
without intermediate coercions toCsparseMatrix
. -
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 thefactors
slot in more cases.Coercions of overallocated
l.TMatrix
todenseMatrix
orCsparseMatrix
now giveTRUE
instead ofNA
in theNA || TRUE
case, following conventional logic.Methods for unpacking and indexing
packedMatrix
and for coercing from[CRT]sparseMatrix
todenseMatrix
now check more consistently for overflow ofR_XLEN_T_MAX
.-
solve(<ddenseMatrix>, <ANY>)
is removed from the method list. It had allowed infinite recursion, e.g., withsolve(new("dgeMatrix"), NULL)
. -
is.na(<ndenseMatrix>)
gaveTRUE
where thex
slot hadNA
. Now the result is always a zero matrix. -
is.na(<.t[rp]Matrix>)
andis.infinite(<.t[rp]Matrix>)
ignored thediag
slot, behaving always as thoughdiag == "N"
. They now giveFALSE
on the diagonal in thediag != "N"
case. Now only “nontrivial” matrix elements determine whether
is.na(<denseMatrix>)
is anndenseMatrix
or annsparseMatrix
.-
is.na(<ddenseMatrix>)
coerced tolMatrix
. This unnecessary step is avoided now, saving a potentially nontrivial allocation. -
solve(<ddenseMatrix>, b)
coerced the first argument todgeMatrix
whenb
was not addenseMatrix
or traditionalmatrix
. This unnecessary step is avoided now, so that specialized methods ford(tr|sy|po|tp|sp|pp)Matrix
are used where possible (including forb
inheriting from[ln]denseMatrix
,sparseMatrix
, ornumLike
). -
`dim<-`(x, -x@Dim)
is now an error, no longer yielding an invalidMatrix
object. -
`dim<-`(x, x@Dim)
is now faster, returningx
without allocation in all cases. -
`dim<-`(x, value)
gives a better error whenvalue
containsNA
or elements exceedingINT_MAX
. -
`dim<-`(<RsparseMatrix>, value)
is now anRsparseMatrix
, rather than aTsparseMatrix
. For consistency with other methods,
symmpart(<diagonalMatrix>)
now always inherits from bothdMatrix
andsymmetricMatrix
, andskewpart(<diagonalMatrix>)
now always has symmetricDimnames
.Zeros on the diagonal of
skewpart(<[CRT]sparseMatrix>)
are now structural.-
as(<ndenseMatrix>, "(vector|matrix|[dl]Matrix)")
andnnzero(<ndenseMatrix>)
now correctly treatNA
in thex
slot asTRUE
. -
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 setc(0, 1, NA)
. This bug had also affected the result ofsum(<[nl].TMatrix>)
. -
dimnames(as(x, "matrix"))
is nowNULL
for allx
inheriting fromMatrix
, whenx@Dimnames
is the triviallist(NULL, NULL)
. -
.bdiag(<named list>)
no longer propagates names to theDim
slot of the result. -
as(<named vector>, "denseMatrix")
now correctly propagatesnames
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 matricesx
with asymmetricdimnames
, returning adiagonalMatrix
whendoDiag = TRUE
, rather than atriangularMatrix
. 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 ofnrow
andncol
are supplied. -
Matrix(<diagonalMatrix>, doDiag = FALSE)
is now asymmetricMatrix
, not adiagonalMatrix
, matching the documentation ofdoDiag
. -
Matrix(<.geMatrix>, sparse = TRUE, forceCheck)
andMatrix(<.g[CRT]Matrix>, sparse = FALSE, forceCheck)
now respectforceCheck = FALSE
by always returninggeneralMatrix
, i.e., not testing for symmetric or triangular structure. -
Matrix(0, nrow, )
,Matrix(0, , ncol)
now throw (correct) errors fornrow
,ncol
in the interval[0,1)
, consistent withbase::matrix()
. -
sparseDefault(<sparseMatrix>)
now counts zeros without coercing tomatrix
, makingMatrix(<sparseMatrix>, sparse = NULL)
much more efficient. Methods for group generic
Math
no longer preservex@diag == "U"
or losex@Dimnames
whenf(0) == 0
andf(1) != 1
. (The former happened fortriangularMatrix
x
and the latter fordiagonalMatrix
x
.)-
image(Z)
for a completely “empty” (all 0)sparseMatrix
works again (?!). -
x[i, ] <- value
andy[, j] <- value
is now an error in more cases form
-by-0CsparseMatrix
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 todimnames(x)
in all cases, now even whenchol(x)
is constructed from a cachedMatrixFactorization
, for greater consistency withbase::chol.default()
. -
chol(<generalMatrix>)
no longer looks atDimnames
when testing for symmetry. -
lu(<dtCMatrix>)
no longer returns an invalidsparseLU
object in the lower triangular case. -
lu(x)
had sometimes incorrectly cached its return value as element"lu"
(rather than"LU"
) ofx@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 annMatrix
, never anlMatrix
. -
!<ndenseMatrix>
andwhich(<ndenseMatrix>)
now correctly handleNA
asTRUE
. -
anyNA(<denseMatrix>)
had incorrectly returnedanyNA(.@x)
in many cases, giving false positives for some.(tr|sy)Matrix
andndenseMatrix
. 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 ifdrop0(A)
anddrop0(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 thefactors
slot, avoiding recomputation. -
qr(<large sparse>)
no longer segfaults in some cases, but now warns about “Out of memory” and stops, fixing Matrix bug #6610 reported by Benjamin Tyner. Fixed
<sparse> %*% <dense>
possible memory corruption, visible via valgrind, fixing Matrix bug #6726 reported by David Cortes.Fixed the (quite long standing) Matrix bug #6777, reported by Manuel Koller:
tcrossprod(<matrix>, <[dln]sCMatrix>)
has been wrong in some cases.
New Features
-
KhatriRao()
gets newsparseY = TRUE
option and also works for moreMatrix
classes. Virtual class
packedMatrix
gains methods forpack
,unpack
,isSymmetric
,isTriangular
, andisDiagonal
implemented in C, replacing those defined for many subclasses individually.New virtual class
unpackedMatrix
containingdenseMatrix
_without_packedMatrix
, with methods forpack
,unpack
,isSymmetric
,isTriangular
,isDiagonal
,t
,diag
, anddiag<-
implemented in C, replacing those defined for many subclasses individually.-
isTriangular
andisDiagonal
are now implemented in C also for[CRT]sparseMatrix
and standardmatrix
.isSymmetric
is now implemented in C for alldenseMatrix
and all[CRT]sparseMatrix
, though these C routines are currently only called when testing for exact symmetry (always for[ln]Matrix
, only whentol = 0
fordMatrix
). Methods for
isSymmetric
gain an argumentcheckDN = TRUE
indicating whether symmetry ofDimnames
should be checked. For backwards compatibility and consistency withisSymmetric.matrix
from base, the actual condition ischeckDN && check.attributes
.-
isTriangular(x, upper)
now has akind
attribute if and only ifx
is triangular andupper
isNA
. -
diag(<unpackedMatrix>) <- value
now behaves likediag(<packedMatrix>) <- value
, supporting coercions depending ontypeof(value)
, consistent withdiag<-
from base. -
pack
andunpack
are now identity functions forpackedMatrix
andunpackedMatrix
arguments, respectively (previously an error).pack(<.geMatrix>)
(previously an error) now behaves aspack(<matrix>)
, i.e., by checking for symmetry or triangularity before packing.unpack(<matrix>)
now works and is equivalent toas(<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
, andndenseMatrix
.The validity method of
dppMatrix
now follows the validity method ofdpoMatrix
, requiring non-negative diagonal elements.Validation of
<Matrix>@Dimnames[[i]]
now tolerates vector types other than character, which are coerced to character in C via the newR_DimNames_fixup()
, for greater consistency with basematrix()
.-
band(x, k1, k2)
is optimized further for both dense and sparsex
, returningtriangularMatrix
,symmetricMatrix
, andpackedMatrix
in more cases. -
band()
is now implemented also fordiagonalMatrix
(onlytri[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 (withdiagU2N()
, etc.).Fixes in group methods (e.g.,
>
,&
,|
), notably for matrices inheriting from classsymmetricMatrix
,triangularMatrix
,lMatrix
, ornMatrix
.-
as.vector
,as.numeric
, andas.logical
are now implemented for allMatrix
. Subassignment to
indMatrix
is no longer prohibited, now going viaTsparseMatrix
.-
indMatrix
gains methods forisTriangular
,isDiagonal
,diag
,diag<-
,band
,tri[ul]
, andforceSymmetric
. It also gains coercions to more virtual classes (notablydenseMatrix
) and a coercion topMatrix
. -
solve(<ddenseMatrix>, <numLike>)
now works in all cases. -
determinant(<ds[yp]Matrix>)
is now much faster in the positive definite case, no longer going viadgeMatrix
. -
diag(<[CRT]sparseMatrix>)
is now done in C and is highly optimized in the.[ts][CR]Matrix
case. -
symmpart
andskewpart
are now done in C for alldenseMatrix
and all[CRT]sparseMatrix
. Both now more faithfully preserve the “storage” of their argument. (Previously,symmpart(<packedMatrix>)
was anunpackedMatrix
, and(symm|skew)part(<[RT]sparseMatrix>)
was aCsparseMatrix
.) -
as(<vector|matrix>, "([dln]?dense|[dlnCRT]?sparse)Matrix")
are now fully and more consistently implemented. In the vector case, the result is now always alength
-by-1generalMatrix
. In the matrix case, structure is now always examined, hence the result is asymmetricMatrix
ortriangularMatrix
in more cases. -
Matrix(<classed matrix>)
now works for classes other thantable
. -
lu(<dt[rpCRT]Matrix>)
andlu(<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 fordtCMatrix
and always done fordt[rpRT]Matrix
andddiMatrix
.) -
lu(x)
now caches its return value also for allds.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 fornMatrix
i
, just as forlMatrix
i
. This supports constructions such asx[is.na(x)]
, where the logical operation produces annMatrix
because it is neverNA
.
Misc
-
AZERO()
and friends gain an argument specifying a zero constant (0 forint
arrays, 0.0 fordouble
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 otherset*()
functions: to(object,name,value)
from(object,value,name)
.For clarity,
set_factor()
now returnsvoid
and is used like otherset*()
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)()
, andinstall_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 generaldense_as_general()
, which takes arguments controlling memory allocation and the “kind” of the.geMatrix
result.New C-level utility
DimNames_is_symmetric()
with R interfaceisSymmetricDN()
, which should be used consistently to test for symmetry of[dD]imnames
. Note that these are intended to behave consistently withsymmetricMatrix_validate()
, by allowing, e.g.,list(NULL, nms)
, but not, e.g.,list(A = NULL, B = nms)
.Coercions to
triangularMatrix
andsymmetricMatrix
are now almost all inherited fromMatrix
, whose methods simply calltri[ul]()
andforceSymmetric()
ifisTriangular()
andisSymmetric()
, respectively, returnTRUE
.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 fromdiagonalMatrix
to any[CRT]sparseMatrix
;R_(dense|sparse|geMatrix)_as_(matrix|vector)()
for coercion to base matrix and vector; andtCRsparse_as_RCsparse()
for the idiomsas(t(<[CR]sparseMatrix>), "[RC]sparseMatrix")
. These all have not-yet-exported R wrappers.-
indTri()
andindDiag()
now in C, with a new argumentpacked
for efficiently indexingpackedMatrix
.indDiag()
now behaves sensibly in then = 0
case. -
.M.kind()
,.M.shape()
, and (new).M.repr()
are now done in C viaR_check_class_etc()
, requiring a class definition only in “rare” cases.
Changes in version 1.4-1 (2022-03-21 r3446)
Bug Fixes
-
diag(x)
methods now mostly also keepnames
fromdimnames(x)
by default and obeynames=*
more generally.
New Features
New virtual class
packedMatrix
containing packed (dense) symmetric and triangular matrices. Methods for subscripting, includingdiag()
, notably keeping names by default and fort()
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"
.
Misc
Our C sources now use
R_Calloc()
,R_Free()
etc, instead of the shorter versions without 'R_'. Consequently, we get closer toSTRICT_R_HEADERS
. Also, include<float.h>
forDBL_EPSILON
.-
PROTECT()
3 more; as from ‘rchk’ for Matrix 1.4-0. Slightly better patch notably for Windows, for ‘src/SuiteSparse_config/SuiteSparse_config.h’
Fix to continue working for R 3.5.0 and newer, providing
tryInvokeRestart()
for older versions of R, thanking Michael Chirico for the heads up.Modified
AZERO()
to work withR_xlen_t
and newAZEROs()
forsize_t
; other tweaks to evade-Wconversion
warnings.
Changes in version 1.4-0 (2021-12-08 r3419)
Bug Fixes
Update many ‘src/*.c’ preventing integer overflow in “pointer” and index computations for large (dense) matrices; prompted by Dario Strbenac's post to R-devel.
-
sparse.model.matrix(.., contrasts.arg = <.. ddiMatrix ..>)
now works correctly, fixing R-Forge Matrix bug #6673 by Davor Josipovic. -
sparse.model.matrix(..)
now also works in cases the contrast matrix has become a"denseMatrix"
; e.g., in a case usingpoly(.)
in the formula; now works correctly, fixing R-Forge Matrix bug #6657 and useful suggestions by Nick Hanewinckel. Fixed the internal
attr.all_Mat()
auxiliary forall.equal()
, notably for the case when exactly one of the matrices is a basematrix
.Fixed long-standing bug in the
rbind2()
method for logical dense matrices, specifically"lgeMatrix"
, thanks to the notice by Aaron Lun.fix leak in C-level
Csparse_to_dense()
thanks to Bill Dunlap in R's PR#18204 andinstall_lu()
called fromsolve(<dgCMatrix>)
in PR#18206.fix leak in crossprod(<dsTMatrix>), thanks to report and patch in PR#18205 by Bill Dunlap.
-
band(M, k1, k2)
now also works whenk1 * k2
is larger than 2^31-1, the maximal integer, fixing R-Forge Matrix bug #6743 by Ariel Paulson. Further, it works whenM
is a sparse"symmetricMatrix"
but the band is not symmetric,k1 != -k2
. fix leak in C-level code for
cbind(m1,m2)
orrbind(*)
whenm1
is"n.Csparse"
andm2
is not, thanks to Bill Dunlap's diagnosis and patch in R's PR#18210.-
sparseVector(i=integer(), length=2^33)
now does show/print, after fixing a bug in thehead()
method for empty sparseVectors. Reported by David Cortes as Matrix bug #6745. inverting or solving
dsCMatrix
no longer catches C level warnings too early which would not free, but rather leak memory; thanks to Bill Dunlap's analysis and patch in R's PR#18214. Additionally, such warnings and error aremessage()
d whengetOption("Matrix.verbose")
is>= 1
.-
‘test-tools-1.R’:
Sys.memGB()
can no longer usememory.limit()
on Windows; no returnsNA.value = 2.10201
in such cases. -
ss <- <sparseVector>[i]
gave an invalid sparseVectorss
asss@i
was not necessarily sorted; thanks to a report by Quran Wu. -
as(<dsyMatrix>, "generalMatrix")
and similar, sometimes did not use (C-level)symmetric_Dimnames()
etc; report (to R's PR#18250 by Mikael Jagan); fixed all on C level. As a consequence, you will now see more preserved dimnames after matrix transformations or operations which involved symmetric matrices. -
as(<ddiMatrix>, "matrix")
no longer loses dimnames, thanks to Mikael Jagan's report as Matrix bug #6751.
Misc
No longer include ‘Rdefines.h’ as it is somewhat deprecated.
Changes in version 1.3-4 (2021-05-24 r3392)
Misc
Update
matrix(<data>, n,m)
in ‘tests/*’ to work withR-devel CMD check --as-cran
Changes in version 1.3-3 (2021-05-01 r3390)
Deprecated and Defunct
-
cBind()
andrBind()
are now defunct: simply usecbind()
andrbind()
instead.
Dependency
For now revert to
Depends: R (>= 3.5.0)
to accomodate users on older R installations.
Bug Fixes
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
whenR
is "Rsparse*", R-Forge Matrix bug #6709 by David Cortes.-
‘./include/cholmod.h’ and ‘./include/Matrix_stubs.h’ needed updating from SparseSuite update; R-Forge Matrix bug #6714 by Kasper Kristensen (TMB package).
-
as.matrix()
andas.array()
now work for"sparseVector"
s as expected; see Matrix bug #6708. -
M[,]
(and similar) now work as in base R; R-Forge Matrix bug #6720 by David Cortes. -
-S
now works also whenS
has no 'factors' slot. It signalled an error, e.g., for sparse triangular matricesS
; R-Forge Matrix bug #6656, reported by Chun Fung (Jackson) Kwok. -
M*2
and similar no longer keep cached factorizations (in 'factors' slot), but drop them via internal new.empty.factors()
. R-Forge Matrix bug #6606, reported by Tomas Lumley. removed the nowhere used (and unexported but still active) class union
"Mnumeric"
which actually trickled into many base classes properties. Notably would it break validity offactor
with a proposed change in validity checking, as factors were also"Mnumeric"
but did not fulfill its validity method. Similarly removed (disabled) unused class union"numericVector"
.removed a few duplicated
.alias{.}
from ‘man/*.Rd’.
Misc
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 usematrix(x, n,n)
whenx
is longer than n*n.Update tests/*.R to future
matrix(x, n,k)
warning in more mismatch cases.Eliminating the need for ‘ftp://*’, add the very small
jgl009
MatrixMarket example to our ‘external/’ files.
Changes in version 1.3-2 (2021-01-05 r3362)
Bug Fixes
-
rankMatrix()
tweaks for the singular values based methods, notablymethod = "maybeGrad"
. -
as(new("dtCMatrix", diag="U"), "matrix")
now works, as C-leveldiagU2N()
now also works for 0-dimensional triangular matrices; this also fixes a subsetting (“indexing”) bug of such 0-dimensional matrices, thanks to a report by Aaron Lun. logical subsetting of 0-dim. (diagonal/triangular) matrices fixes.
The new
FCONE
macros added for newer Fortran/C compiler combinations are now defined back compatibly with R\ge
3.6.0.-
chol(<diagonal dt[CRT]Matrix>)
now works. -
‘rchk’: fix potentially un
PROTECT
ed vars in ‘src/dsyMatrix.c’
Changes in version 1.3-1 (2020-12-23 r3352)
Bug Fixes
-
rankMatrix(<dense>, method="qr.R")
no longer assumes non-negative diagonal entries of theR
matrix.
Changes in version 1.3-0 (2020-12-15 r3351)
Significant User-Visible Change
-
Matrix(*, doDiag=TRUE)
wheredoDiag=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 fromMatrix(0, 3,3, doDiag=FALSE)
, and e.g.,.symDiagonal(3,pi)
.Also a triangular matrix, e.g.,
"dtrMatrix"
is detected now in cases withNA
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"
).
New Features
Subassignment to
"diagonalMatrix"
now returns sparse"triangularMatrix"
more often; also (sparse)"symmetricMatrix"
.-
nearPD()
gets new option: Ifbase.matrix = TRUE
, the resultingmat
component is a basematrix
, as often used desired whennearPD()
is used outside the Matrix package context. Factored out new
qr2rankMatrix()
utility fromrankMatrix()
.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 ofsummary(<sparseMatrix>)
in code.Internal
.diag2tT()
gains new optiondrop0 = TRUE
and hence now by default drops zero diagonal entries. Consequently, e.g.,as(<diagonalMatrix>, "CsparseMatrix")
now drops such zeros, too.Updated the crucial underlying C libraries from SuiteSparse, from 4.2.1 to 5.7.1 (from 2020-02-20), visible in
.SuiteSparse_version()
.-
sparseMatrix()
gets new argumentrepr = "C"
, superseding the (now deprecated)giveCsparse = TRUE
. Allows to return"RsparseMatrix"
matrices.Similarly,
rsparsematrix()
,fac2sparse()
andfac2Sparse()
get the newrepr
argument and theirgiveCsparse
is deprecated, sometimes only informally for now. -
sparse.model.matrix()
gets optionsep = ""
, with, e.g.,sep = ":"
allowing to get easier column names; from R-Forge Matrix (non-)bug #6581, by Vitalie Spinu.
Bug Fixes
-
rankMatrix(<sparse>, method="qr")
now returnsNA
(orNaN
) instead of signalling an error in the case the sparseQ R
decomposition gaveNA
s indiag(R)
. Coercion (
as(., .)
) from e.g.,"lsyMatrix"
to"CsparseMatrix"
silently made asymmetric dimnames symmetric, as did the internalforceCspSymmetric(*, dimNames)
which may be called fromforceSymmetric()
.Adapt code to new Fortran requirements of passing length of character arguments, thanks to Brian Ripley.
(R-Forge Matrix bug #6659, reported by Georg Kindermann):
<sparseVector>[i] <- val
bug fixed.(R-Forge Matrix bug #6666, reported by Ezra Tucker):
which(<ldiMatrix>, array.ind=TRUE)
thinko fixed.For R-devel Dec 4, 2020: adapt all.equal() check of sparse matrix images (which contain panel functions with environments ..).
tried fixing warning 'cholmod_factorize_p' accessing 16 bytes in a region of size 8 [-Wstringop-overflow=] in ‘src/dsCMatrix.c’ (in two places); seen by pre-release-gcc11 compilation.
Changes in version 1.2-18 (2019-11-26, manually picked from svn)
Bug Fixes
Fix last(?)
PROTECT()
warning found byrchk
in ‘src/dense.c’'sddense_skewpart()
.-
as(m, "dgTMatrix")
does not losedimnames
anymore whenm
is a (traditional)matrix
. -
M[logical(0), ]
now has dimension0 x k
for sparseM
as for base matrices. -
log(M, base)
(the 2-argument version oflog()
) wrongly gave the result forbase = exp(1)
, i.e., the 1-argument default. -
‘test-tools-Matrix.R’:
Qidentical()
no longer assumesclass(<matrix>)
to be of length 1. -
‘test-tools-1.R’: provide bug-fixed
canCoerce()
in old R versions.
Changes in version 1.2-17 (2019-03-20, svn r3294)
New Features
(none)
Bug Fixes
Fix new
PROTECT()
warnings (bugs?) found byrchk
.Provide
isFALSE()
for R<
3.5.0 as now need it for sparseMatrix printing.
Changes in version 1.2-16 (2019-03-04, svn r3291)
New Features
regression tests depending on
sample()
now are future proof reproducible, viaRNGversion(.)
.give information about #{rows} and #{columns} that are suppressed in print()ing if the matrix is larger than
max.print
.
Bug Fixes
-
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()
, themaxp
option, e.g., fromgetOption("max.print")
, is “rounded up” to 100, as very small values are very rarely appropriate.
Changes in version 1.2-15 (2018-08-20, svn r3283)
New Features
-
image()
gets new optional argumentborder.color
.
Bug Fixes
-
image(Matrix(0, n,m))
now works.
Changes in version 1.2-14 (2018-04-08, svn r3278)
New Features
German translation updates.
Bug Fixes
one more
PROTECT()
.
Changes in version 1.2-13 (2018-03-25, svn r3275)
New Features
Faster
as(<matrix>, "sparseMatrix")
and coercion"dgCMatrix"
,"ngCMatrix"
, etc, via new direct Cmatrix_to_Csparse()
which does not go via"dgeMatrix"
. This also works for large matricesm
, i.e., whenlength(m) >= .Machine$integer.max
.Also provide low-level R functions
.m2dgC()
,.m2lgC()
, and.m2ngC()
for these.
Bug Fixes
-
cbind(NULL,<Matrix>)
no longer returnNULL
; analogously forrbind()
,rbind2()
,cbind2()
, fixing very long standing typo in the corresponsingcbind2()
andrbind2()
methods. The deprecation warning (once per session) for
cBind()
andrBind()
finally works (fixing a simple thinko).-
cbind()
andrbind()
for largish sparse matrices no longer gives an error because of integer overflow (in the default case wheresparse
is not been specified hence is chosen by annzero()
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 matricesSp
, 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 vianew(*, Dim = *, x = *)
also whenlength(x)
is larger than 2^31 (as the C internal validation method no longer suffers from integer overflow).More ‘PROTECT()’ing to be “rather safe than sorry” thanks to Tomas Kalibera's check tools.
Changes in version 1.2-12 (2017-11-10, svn r3239)
New Features
-
crossprod(x,y)
andkronecker(x,y)
have become considerably more efficient for large"indMatrix"
objectsx, y
, thanks to private nudging by Boris Vaillant.
Bug Fixes
(R-Forge Matrix bug #6185):
c < 0
now also works for derived sparse Matrices (which only contain Matrix classes); via improving hiddenMatrixClass()
. 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 (ofm
).
Changes in version 1.2-11 (2017-08-10, svn r3225)
New Features
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)
Bug Fixes
-
rankMatrix(<matrix of all 0>)
now gives zero for all methods, as it should be. no longer calling
length(NULL) <- <positive>
which has been deprecated in R-devel since July.-
qr.coef(<sparseQR>, y)
now finally has correct (row) names (from pivot back permutation). -
.trDiagonal()
utility is now exported.
Changes in version 1.2-10 (2017-04-19, svn r3216)
Bug Fixes
quite a collection of new
PROTECT(.)
's thanks to Tomas Kalibera's ‘rprotect’ analysis.
Changes in version 1.2-9 (2017-03-08, svn r3211)
New Features
-
"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 tobase::norm
). -
sparseVector()
now also works withoutx
argument. -
c.sparseVector()
method forc()
of sparseVectors (and available as regular function on purpose).
Bug Fixes
-
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 matricesS
and logicalsel
whensel
containsNA
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, *)
(whenx
is a"lMatrix"
or"nMatrix"
) now works the same asbase::which
, obeying an optionaluseNames
argument which defaults toTRUE
. Previously, the resulting two-column matrix typically had emptydimnames
.
Changes in version 1.2-8 (2017-01-16, svn r3201)
New Features
0-length matrix
"Ops"
(binary operations) are now compatible to R-devel (to be R 3.4.0).C-API:
SuiteSparse_long
is now defined asint64_t
on all platforms, and we now include (C99) ‘inttypes.h’
Bug Fixes
-
x[.] <- value
now also works for"sparseVector"
's, both asx
and asvalue
. -
x[FALSE] <- value
now also works for"sparseVector"
's. -
rep(x, *)
now works for"sparseVector"
s and sparse and dense"Matrix"
-classed matricesx
. -
solve(<sparse_LU>)
no gives an error in some cases of singular matrices, where before the C code accessed illegal memory locations.
Changes in version 1.2-7.1 (2016-08-29, svn r3187)
in C code, protect _POSIX_C_SOURCE by #ifdef __GLIBC__
Changes in version 1.2-7 (2016-08-27, svn r3185)
New Features
-
cBind()
andrBind()
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 indicesk
.
Bug Fixes
-
KhatriRao(X,Y)
now also works whenX
orY
is completely zero.
Changes in version 1.2-6 (2016-04-27, svn r3175)
Bug Fixes
The 0-dim. Matrix multiplication fix in 1.2-5 did trigger wrong warnings in other diagonal matrix multiplications.
Changes in version 1.2-5 (2016-04-14, svn r3170)
New Features
-
isSymmetric(m)
now also works for"indMatrix"
m
. -
isSymmetric(m)
is faster for large dense asymmetric matrices.
Bug Fixes
Matrix multiplications (
A %*% B
) now work correctly when one of the matrices is diagonal and the other has a zero dimension.
Changes in version 1.2-4 (2016-02-29, svn r3162)
New Features
-
sparseMatrix()
gets new argumenttriangular
and a smarter default fordims
whensymmetric
ortriangular
is true. -
as(<sparse>, "denseMatrix")
now works in more cases whenprod(dim(.))
is larger than2^{31} - 1
. Hence, e.g.,!S
now works for much larger sparse matricesS
.
Bug Fixes
creating very large dense matrices, e.g., by
as(<sparseM.>, "matrix")
would segfault (in case it could allocate enough storage).
Changes in version 1.2-3 (2015-11-19, svn r3155)
New Features
-
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
Bug Fixes
Packages linking to Matrix (
LinkingTo:
in ‘DESCRIPTION’) now find ‘alloca’ properly defined in ‘Matrix.h’ even for non-GNU compilation environments such as on Solaris or AIX.extended "n?CMatrix" classes (e.g., from
setClass(., contains="ngCMatrix")
) now can be coerced viaas(.)
to"d.CMatrix"
.The printing of largish sparse matrices is improved, notably in the case where columns are suppressed, via new
fitWidth = TRUE
option inprintSpMatrix2()
.-
cbind2()
andrbind2()
no longer fail to determinesparse
when it is unspecified and henceNA
, fixing R-Forge bug #6259.
Changes in version 1.2-2 (2015-07-03, svn r3131)
New Features
Explicitly import from “base” packages such as stats.
Bug Fixes
Our
colSums(x)
,rowMeans(y)
, ..., methods now “keep names”, i.e., if the result is a numeric vector, and the matrixx
has column or row names, these become thenames(.)
of the result, fixing R-Forge bug #6018.
Changes in version 1.2-1 (2015-05-30, svn r3127)
New Features
-
"Matrix"
now has aninitialization()
method coercing 0-length dimnames components toNULL
and other non-NULL
dimnames tocharacter
. Before, e.g., numeric dimnames components partially worked, even though it has always been documented that non-NULL
dimnames should becharacter
. For
symmetricMatrix
objects which have symmetrical dimnames by definition, it is allowed to only set one half of thedimnames
to save storage, e.g.,list(NULL, nms)
is semantically equivalent tolist(nms, nms)
.-
as.vector(<sparseVector>)
etc, now work, too. -
lu(<sparseMatrix>)
now keepsdimnames
. better ‘NEWS.Rd’ (which pleases Kurt and
tidy
;-)
Bug Fixes
-
S[] <- T
andS[] <- spV
now work (in more cases) for sparse matrices S, T and sparseVectorspV
. Huge dense matrix multiplication did lead to segfaults, see R-help, “does segfault mean (always) a bug?”, May 5, 2015. Fixed by using C's Alloca() only in smallish cases.
Optional arguments in
image()
, e.g.,main= <..>)
now also work forlgCMatrix
,nMatrix
etc; thanks to a 4.5 years old report by Mstislav Elagin.-
dimnames(A) <- val
now resets thefactors
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
, andtcrossprod
) for"dtrMatrix"
are correct in all cases, including keeping dimnames.-
Matrix(d)
(and other coercions to"Matrix"
) now correctly keepsdimnames
also whend
is a traditional diagonal"matrix"
.
Changes in version 1.2-0 (2015-04-03, svn r3096)
New Features
New
%&%
for “boolean arithmetic” matrix product.New argument
boolArith = NA
incrossprod()
andtcrossprod()
.boolArith = TRUE
now forces boolean arithmetic, whereboolArith = 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 ongeMatrix_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 containNA
s, which then becomeTRUE
s. More thorough checking of
cbind2()
andrbind2()
methods, notably as they are called fromcbind()
andrbind()
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 havedimnames
of the formlist(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 acceptsrand.x = NULL
and then creates a random pattern matrix ("nsparseMatrix"
). -
anyDuplicatedT()
anduniqTsparse()
low level utilities are exported now. Partial Korean translations of messages.
Deprecation
For R
\ge
3.2.0,cBind()
andrBind()
are deprecated, as they are no longer needed sincecbind()
andrbind()
do work automatically.
Bug Fixes
Fix some
rbind2()
methods.-
t()
now transposes the dimnames even for symmetric matrices. -
diag(M) <- val
did not always recycleval
to full length, e.g., whenM
was a"dtrMatrix"
. -
crossprod(<indMatrix>)
was wrong in cases where the matrix had all-zero columns. Matrix products (
%*%
,crossprod
, andtcrossprod
) with one sparse and one dense argument now return numeric (a"dMatrix"
) when they should, i.e., unless the new settingboolArith = TRUE
is applied.
Changes in version 1.1-5 (2015-01-18, svn r3037)
New Features
More use of
anyNA()
(for speedup).Matrix products (
%*%
,crossprod
,tcrossprod
) now behave compatibly to R 3.2.0, i.e., more lenient in matching dimensions for matrix - vector products.-
isTriangular()
gets new optional argumentupper = NA
.
Bug Fixes
-
crossprod()
andtcrossprod()
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()
andtriu()
now return correctuplo
. -
names(dimnames(.))
now preserved, e.g. insymmpart()
or subsetting (A[i,j]
).
Changes in version 1.1-4 (2014-06-14, svn r2994)
New Features
new
rsparsematrix()
for random sparse Matrices.improved warnings, notably for unused arguments previously swallowed into
...
.
Bug Fixes
-
crossprod(<vec>, <dsyMatrix>)
fixed. -
crossprod()
andkronecker()
fixes for some <indMatrix> cases.
Changes in version 1.1-3 (2014-03-30, svn r2982)
New Features
-
%*%
andcrossprod()
now also work withsparseVector
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’).
Bug Fixes
-
image()
now gets correctylim
again. More consistent matrix products.
Changes in version 1.1-2-2 (2014-03-04, svn r2966)
Bug Fixes
correct adaption to R 3.1.0
using
tolerance
(and not ‘tol’) inall.equal()
Changes in version 1.1-2 (2014-01-28, svn r2962)
New Features
export fast power-user coercion utilities
.dsy2mat()
,.dxC2mat()
,.T2Cmat()
,..2dge()
.
Bug Fixes
matrix products now (mostly) work with
sparseVector
s; and correctly in some more cases.
Changes in version 1.1-1.1 (2013-12-30, svn r2957)
Testing code's
assertWarning()
adapted for R\le
3.0.1.-
Depends: R (>= 2.15.2)
eases checking.
Changes in version 1.1-1 (2013-12-28)
New Features
-
image(.., xlim, ylim)
: nicer defaults for the axis limits, andylim
is sorted decreasingly; not strictly back-compatible but should never harm. -
rankMatrix(*, method="qr")
now usingtol
-
T2graph()
andgraph2T()
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()
: newuse.last.ij
argument.
Bug Fixes
-
KhatriRao()
: fix rownames (X <-> Y) -
qr.coef()
,qr.fitted
, andqr.resid
now also work with sparse RHSy
. 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)]
.
Changes in version 1.1-0 (2013-10-21, svn r2930)
New Features
-
fac2sparse
andfac2Sparse
now exported, with a newgiveCsparse
option. Update to latest
SuiteSparse
C library by Tim Davis, U. Florida.ensuing “C API changes”
new
.SuiteSparse_version()
functionMany ‘Imports:’ instead of ‘Depends:’.
Bug Fixes
fixed long lasting undetected
solve(<dsCMatrix>, *)
bug.Our
all.equal()
methods no longer sometimes returnc("TRUE", "....difference..")
.-
rankMatrix(<matrix>)
: fix the internalx.dense
definition.
Changes in version 1.0-14 (2013-09-12, svn r2907)
Bug Fixes
Revert some wrong changes to
solve(<sparse>, *)
from 1.0-13 (“stop gap fix” for R 3.0.2).
Changes in version 1.0-13 (2013-09-10, svn r2904)
New Features
New (efficient)
KhatriRao()
function by Michael CysouwNew
"indMatrix"
class of “index matrices”, a generalization of"pMatrix"
, the permutation matrices, many methods generalized from pMatrix to indMatrix. All (initial) functionality contributed by Fabian Scheibl, Univ. Munich.Export and document
isDiagonal()
andisTriangular()
as they are useful outside of Matrix.-
rankMatrix(M, method="qr")
no longer needssval
which makes it considerably more useful for large sparseM
. Start providing
anyNA
methods for R\ge
3.1.0.-
solve(<sparse> a, <sparse> b)
: ifa
is symmetric, now compute sparse result. -
nearPD()
gets new optionconv.norm.type = "I"
. -
determinant(<dpoMatrix>)
now useschol()
, 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).
Bug Fixes
-
M[] <- v
for unitriangularM
now correct. -
lu(.)
no longer sometimes returns unsorted columns.
Changes in version 1.0-12 (2013-03-26, svn r2872)
New Features
.
Bug Fixes
.
Changes in version 1.0-11 (2013-02-02)
New Features
.
Bug Fixes
-
as(<csr>, "dgCMatrix")
(from package SparseM) now works again. .
Changes in version 1.0-10 (2012-10-22)
New Features
-
.sparseDiagonal()
: newunitri
argument, and more flexibility; new
solve(<dsCMatrix>, <missing>)
via efficient C code.
Bug Fixes
.
Changes in version 1.0-9 (2012-09-05)
New Features
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.
Bug Fixes
Quite a few fixes for
Ops
(arithmetic, logic, etc) group methods.Ditto for
diagonalMatrix
methods.
Changes in version 1.0-6 (2012-03-16, publ. 2012-06-18)
New Features
.
Bug Fixes
.
Changes in version 1.0-5 (2012-03-15)
New Features
.
Bug Fixes
.
Changes in version 1.0-4 (2012-02-21)
New Features
.
Bug Fixes
.
Changes in version 1.0-3 (2012-01-13)
New Features
.
Bug Fixes
.
Changes in version 1.0-2 (2011-11-19)
New Features
.
Bug Fixes
.
Changes in version 1.0-1 (2011-10-18)
New Features
.
Bug Fixes
.
Changes in version 1.0-0 (2011-10-04)
New Features
.
Bug Fixes
.
Changes in version 0.9996875-3 (2011-08-13)
New Features
.
Bug Fixes
.
Changes in version 0.9996875-2 (2011-08-09)
New Features
.
Bug Fixes
.
Changes in version 0.9996875-1 (2011-08-08)
New Features
.
Bug Fixes
.
Changes in version 0.999375-50 (2011-04-08)
New Features
.
Bug Fixes
.
Changes in version 0.95-1 (2005-02-18, svn r561)
Authorship
During Doug Bates' sabbatical in Zurich, Martin Maechler becomes co-author of the Matrix package.
New Features
Beginning of class reorganization with a more systematic naming scheme.
Bug Fixes
More (correct) coercions
as(<from>, <to>)
.
Changes in version 0.9-1 (2005-01-24, svn r451)
New Features
lme4 / lmer specific R code moved out to lme4 package.
Bug Fixes
.
Changes in version 0.8-2 (2004-04-06, svn r51)
Authorship
Doug Bates (only)
New Features
Sparse matrices, classes and methods, partly via
Interface to LDL, TAUCS, Metis and UMFPACK C libraries
Version 0.2-4
..., 0.3-1, 0.3-n (n=3,5,...,26): 22 more CRAN releases
.............................................
Version 0.2-1 (2000-07-15)
The first CRAN release of the Matrix package, titled “A Matrix library for R” authored by Douglas Bates (maintainer, principal author) and Saikat DebRoy.
Features
-
Matrix()
constructor for R objects of classMatrix
. -
Matrix.class()
returning informal subclasses such as"Hermitian"
,"LowerTriangular"
-
is.Orthonormal()
,is.Hermitian()
,is.UpperTriangular()
functions. -
SVD()
,lu()
, andschur()
decomposition generics with"Matrix"
methods. -
rcond()
,norm()
,det()
;expand()
andfacmul()
. C++ interface to LAPACK