Skip to content

Replace Base.convert(::Type{SparseArrays.SparseMatrixCSC}, J::SUNMat… #316

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

Merged
merged 1 commit into from
Jul 14, 2021
Merged

Replace Base.convert(::Type{SparseArrays.SparseMatrixCSC}, J::SUNMat… #316

merged 1 commit into from
Jul 14, 2021

Conversation

sjdaines
Copy link
Contributor

Replace Base.convert(::Type{SparseArrays.SparseMatrixCSC}, J::SUNMatrix) with copyto!

Fix for #315

Proximate cause was that the SUNMatrix sparse Jacobian was not fully initialised,
hence failed the SparseMatrixCSC consistency checks introduces with
Julia 1.7

More fundamentally, given that Sundials uses zero-based index arrays,
convert(::Type{SparseArrays.SparseMatrixCSC}, J::SUNMatrix)
would either need to allocate, or is inherently unsafe as an in-place
version that applied a 1-based index conversion would create an
invalid SUNMatrix.
Also the convert code here looks like it modified colptr but
not rowptr, so couldn't have worked anyway... (cvodejac and similar
used to overwrite this, which is why those calls worked).

…ix) with copyto!

Fix for #315

Proximate cause was that the SUNMatrix sparse Jacobian was not fully initialised,
hence failed the SparseMatrixCSC consistency checks introduces with
Julia 1.7

More fundamentally, given that Sundials uses zero-based index arrays,
convert(::Type{SparseArrays.SparseMatrixCSC}, J::SUNMatrix)
would either need to allocate, or is inherently unsafe as an in-place
version that applied a 1-based index conversion would create an
invalid SUNMatrix.
Also the convert code here looks like it modified colptr but
not rowptr, so couldn't have worked anyway... (cvodejac and similar
used to overwrite this, which is why those calls worked).
Copy link
Member

@ChrisRackauckas ChrisRackauckas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a lot more sane.

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Merging #316 (7505efe) into master (6cdf6b4) will decrease coverage by 0.00%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #316      +/-   ##
==========================================
- Coverage   24.66%   24.65%   -0.01%     
==========================================
  Files          23       23              
  Lines        5732     5726       -6     
==========================================
- Hits         1414     1412       -2     
+ Misses       4318     4314       -4     
Impacted Files Coverage Δ
src/common_interface/function_types.jl 82.50% <50.00%> (+2.26%) ⬆️
src/types_and_consts_additions.jl 81.25% <100.00%> (ø)
src/common_interface/integrator_utils.jl 67.01% <0.00%> (+1.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cdf6b4...7505efe. Read the comment docs.

@ChrisRackauckas ChrisRackauckas merged commit 782efcd into SciML:master Jul 14, 2021
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

Successfully merging this pull request may close these issues.

3 participants