Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for Matrix package #103

Open
jwijffels opened this issue Aug 12, 2022 · 1 comment
Open

update for Matrix package #103

jwijffels opened this issue Aug 12, 2022 · 1 comment

Comments

@jwijffels
Copy link
Contributor

Matrix 1.4-2 will formally deprecate 187 coercion methods. More
precisely, coercions of the form

as(object, Class)

where

  • 'object' inherits from the virtual class Matrix, is a traditional
    matrix, or is a logical or numeric vector

  • 'Class' specifies a non-virtual subclass of Matrix, such as
    dgCMatrix, but really any subclass matching the pattern

    ^[dln]([gts][CRT]|di|ge|tr|sy|tp|sp)Matrix$
    

will continue to work as before but signal a deprecation message or
warning (message in the widely used dg.Matrix and d.CMatrix cases).

By default, the message or warning will be signaled with the first
deprecated method call and suppressed after that. Signaling can be
controlled via option Matrix.warnDeprecatedCoerce:

<=0 = be completely silent [[ at your own risk ! ]]
1 = warn each time

=2 = error each time [[ for debugging ]]
NA = message or warn once then be silent [[ the default ]]

Deprecated coercions in your package sources (including examples,
tests, and vignettes) should be revised to go via virtual classes
only, as has been advocated for quite some time in

vignette("Design-issues", package = "Matrix")

For example, rather than

as(, "dgCMatrix")

we recommend (the full, a "permutation", or a simplification given the
context of)

as(as(as(, "dMatrix"), "generalMatrix"), "CsparseMatrix")

To simplify the revision process, the development version of Matrix
provides Matrix:::.as.via.virtual(), taking a pair of class names and
returning as a call the correct nesting of coercions:

Matrix:::.as.via.virtual("matrix", "dgCMatrix")
as(as(as(from, "dMatrix"), "generalMatrix"), "CsparseMatrix")
Matrix:::.as.via.virtual("matrix", "lsTMatrix")
as(as(as(from, "lMatrix"), "symmetricMatrix"), "TsparseMatrix")
Matrix:::.as.via.virtual("dgCMatrix", "dtrMatrix")
as(as(from, "triangularMatrix"), "unpackedMatrix")

We suggest checking package tarballs built with

options(Matrix.warnDeprecatedCoerce = n) # where n >= 1

in the .onLoad() hook (see ?.onLoad), so that all deprecated coercions
are exposed in the check output. (If you find that a warning or error
has been signaled from 'Matrix' itself, then we'd welcome a report
containing a minimal reproducible example, so that we may revise our
own code.)

jwijffels added a commit that referenced this issue Aug 12, 2022
jwijffels added a commit that referenced this issue Aug 13, 2022
jwijffels added a commit that referenced this issue Aug 13, 2022
jwijffels added a commit that referenced this issue Aug 13, 2022
@jwijffels
Copy link
Contributor Author

jwijffels commented Aug 16, 2022

New mail from Matrix authors:

One important remark however:
In the mean time we have decided to keep

as(<traditional_R_matrix>, "dgCMatrix")

non-deprecated as it is used in so many places.
This is the only example of non-deprecation and is really only
for traditional R matrices (class(.) |--> "matrix"), and
not Matrix-package matrices.

Really, I'd rather quite strongly recommend to only replace
as(, "dgCMatrix") by
as(, "CsparseMatrix")

in most situations, where you already know from context that
your (traditional R) matrix is numeric (and not 'logical').
In your case where you want to pass the result to C code which
only works for "dgCMatrix" and nothing else, you may need to at
least use the 2-step

as(as(, "CsparseMatrix"), "generalMatrix")

such that you don't get
"dsCMatrix" (symmetricMatrix) or
"dtCMatrix" (triangularMatrix)

but in most cases - where no restrictive C code is involved -
your code, or rather the Matrix-package code you and your users
would automatically use on the resulting matrix should work
automatically (and more efficiently in some cases !!) also for
the triangular or symmetric classed matrices that result from
the simple as(, "CsparseMatrix")

which would be my own preference.

@jwijffels jwijffels reopened this Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant