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

fix-diag to sparse conversion #21

Merged
merged 3 commits into from
Jul 8, 2019
Merged

fix-diag to sparse conversion #21

merged 3 commits into from
Jul 8, 2019

Conversation

GiggleLiu
Copy link
Member

No description provided.

@GiggleLiu GiggleLiu requested a review from Roger-luo July 2, 2019 01:15
@Roger-luo
Copy link
Member

CI is not pass.

@@ -19,6 +19,11 @@ function SparseMatrixCSC(M::PermMatrix)
SparseMatrixCSC(n, n, collect(1:n+1), order, M.vals[order])
end

function SparseMatrixCSC(M::Diagonal)
n = size(M, 1)
SparseMatrixCSC(n, n, collect(1:n+1), collect(1:n), M.diag)
Copy link
Member

Choose a reason for hiding this comment

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

seems this line is using the wrong args.

Copy link
Member Author

Choose a reason for hiding this comment

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

What is the correct one?

@Roger-luo
Copy link
Member

XRef: JuliaLang/julia#32466
issue: JuliaLang/julia#31770

I'll patch it here for now. But this PR should be in the coming release, so should be removed after 1.3 is out this year, or we would contain type piracy.

This issue is because the conversion was defined in sparse instead of SparseMatrixCSC, not just because the lack of constructors.

https://github.com/JuliaLang/julia/blob/55e36cc308b66d3472990a06b2797f9f9154ea0a/stdlib/SparseArrays/src/sparsematrix.jl#L778

I don't think it would appear in v1.2, but should be in v1.3 period, not sure if this would get backported, and I think you missed the type conversion of the diagonal part,
it should be copied instead of view (Diagonal is not sub array, should use an explicit type for diagonal view to avoid heap allocation or use UnsafeArray).

function sparse(D::Diagonal{T}) where T
    m = length(D.diag)
    return SparseMatrixCSC(m, m, Vector(1:(m+1)), Vector(1:m), Vector{T}(D.diag))
end

@Roger-luo
Copy link
Member

Roger-luo commented Jul 8, 2019

PS. I think this is one reason you want to get rid of this kind of auto conversion interface like sparse, the same as mat we should use explicit constructors more (if possible) in the future.

@codecov
Copy link

codecov bot commented Jul 8, 2019

Codecov Report

Merging #21 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
+ Coverage   70.86%   70.98%   +0.11%     
==========================================
  Files          12       12              
  Lines         484      486       +2     
==========================================
+ Hits          343      345       +2     
  Misses        141      141
Impacted Files Coverage Δ
src/conversions.jl 32.75% <100%> (+2.4%) ⬆️

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 ad75099...5969916. Read the comment docs.

@Roger-luo Roger-luo merged commit 2fb0e56 into master Jul 8, 2019
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.

2 participants