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

make similar(A, [T,] shape...) for structured A yield a sparse rather than dense array #24170

Merged
merged 3 commits into from
Oct 20, 2017

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Oct 16, 2017

This pull request makes similar(A<:Union{Diagonal,Bidiagonal,Tridiagonal,SymTridiagonal}, [neweltype,] shape...) yield a sparse rather than dense array, consistent with e.g. broadcast. For example, this pull request makes similar(Diagonal(rand(4)), Float32, (3, 3)) yield a SparseMatrixCSC{Float32} rather than the present Matrix{Float32}.

This pull request also fixes a minor bug where lufact(A<:Tridiagonal{T}) where !(T<:AbstractFloat) would hit lufact!(B, ...) for non-Tridiagonal rather than Tridiagonal B downstream.

Ref. JuliaLang/LinearAlgebra.jl#271. Best!

@@ -416,6 +416,14 @@ function lufact!(A::Tridiagonal{T,V}, pivot::Union{Val{false}, Val{true}} = Val(
LU{T,Tridiagonal{T,V}}(B, ipiv, convert(BlasInt, info))
end

# Absent the following methods, if A::Tridiagonal{T} where !(T<:AbstractFloat), then the
# method lufact(A) hits sends copy!(similar(A, afloattype, size(A)), A) (which is not a
# Tridagonal given the (unnecessary?) shape argument to similar) to lufact! rather than
Copy link
Member

Choose a reason for hiding this comment

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

I think it is unnecessary so probably better to remove the size argument instead of introducing this method

Copy link
Member Author

Choose a reason for hiding this comment

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

Nixing the shape argument sounds good. That removing the shape argument might break other consumers of the general lufact method motivated the present conservative solution. Let's see whether CI complains :). Best!

@andreasnoack
Copy link
Member

For some reason, this triggers a test error in special.

@Sacha0
Copy link
Member Author

Sacha0 commented Oct 19, 2017

For some reason, this triggers a test error in special.

Should be fixed. Absent objections or requests for time and assuming CI clears, I plan to merge these changes this evening. (If someone beats me to it, not squashing the commits might be best for future bug sleuthing.) Best!

@Sacha0 Sacha0 force-pushed the similarstruc branch 2 times, most recently from 965b884 to b3d12fd Compare October 20, 2017 02:09
…er than dense array.

Also fix a minor bug where lufact(A::Tridiagonal{T}) for !(T<:AbstractFloat) would dispatch to lufact!(B, ...) for non-tridiagonal rather than tridiagonal B downstream.
@Sacha0 Sacha0 merged commit 40607f9 into JuliaLang:master Oct 20, 2017
@Sacha0 Sacha0 deleted the similarstruc branch October 20, 2017 15:45
@Sacha0
Copy link
Member Author

Sacha0 commented Oct 20, 2017

Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants