-
Notifications
You must be signed in to change notification settings - Fork 39
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
Handle changed copy_oftype
#172
Conversation
This PR assumes that the following behavior is correct (Julia 1.8-beta1): julia> LinearAlgebra.copy_oftype(1:5, Int)
5-element Vector{Int64}:
1
2
3
4
5 versus the old behavior (Julia 1.7.2) julia> LinearAlgebra.copy_oftype(1:5, Int)
1:5 EDIT: Daniel Karrasch (the reviewer of JuliaLang/julia#40831) responded on Slack on a question of mine about whether this behavior is correct. He said the following:
|
To verify this PR, I've ran the tests at JuliaArrays/LazyArrays.jl#205 with this PR. On Julia 1.7.2 all tests pass and on Julia 1.8-beta1, only 2 tests fail. Those 2 failing tests are due to problems with @dlfivefifty What do you think? |
No this won't due as we need to promote the type. I think just copy over the old Really LinearAlgebra should call it |
Codecov Report
@@ Coverage Diff @@
## master #172 +/- ##
==========================================
+ Coverage 96.90% 96.94% +0.03%
==========================================
Files 4 4
Lines 646 654 +8
==========================================
+ Hits 626 634 +8
Misses 20 20
Continue to review full report at Codecov.
|
Hmm, |
In this case, I copied the But well, you guys know more so just let me know what you prefer 👍 |
That's what I did. I copied the content of the method that was called. |
As far as I'm concerned, whatever works :-) I'm just making suggestions to resolve any issues here caused by changes to |
With julia> (1:5) .+ Zeros(5)
1:5 This is the correct output here. With julia> (1:5) .+ Zeros(5)
5-element Vector{Float64}:
1.0
2.0
3.0
4.0
5.0 which is the original problem and caused by julia> UnitRange{Int} <: AbstractVector{Int}
true
julia> Vector{Int} <: AbstractVector{Int}
true The method for Julia 1.7 for copy_oftype(A::AbstractArray{T}, ::Type{T}) where {T} = copy(A) If there is some case where |
The correct output for that example is |
Thanks. I was wrong indeed. I've experimented a bit more with |
Hmm, please don't solve it like this. (You are now copying an old internal function from LinearAlgebra with unclear semantics, without changing its name, while the function in LinearAlgebra has meanwhile changed.) There is an underlying problem and it may be better to fix that. In your example, the problem is, I think, not with FillArrays or with julia> convert(AbstractVector{Float64}, 1:5)
5-element Vector{Float64}:
1.0
2.0
3.0
4.0
5.0 This is a result I would disagree with in principle, but some code out there relies on this conversion returning a mutable array. So it would be a breaking change to change it in Base and I didn't even raise the issue. (I did check for occurrences of The choice in Base so far has been to support the syntax julia> map(Float64, 1:5)
1.0:1.0:5.0 Could you experiment with that? I don't think it will work for all structured matrices though, as they all have to support this syntax and I don't think they all do. On the other hand, Sorry for the hassle! |
Ideally, you no longer use |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried this is a bit too much of a "pun". In particular, it requires types to overload map
and so won't work if only copy
or convert
is overloaded, which is the case for the structured matrix packages.
This is my proposal, add the following function and call it:
_copy_oftype(A::AbstractArray{T,N}, ::Type{T}) where {T,N} = copy(A)
_copy_oftype(A::AbstractArray{T,N}, ::Type{S}) where {T,N,S} = convert(AbstractArray{S,N}, A)
_copy_oftype(A::AbstractRange{T}, ::Type{T}) where T = copy(A)
_copy_oftype(A::AbstractRange{T}, ::Type{S}) where {T,S} = map(S, A)
I think the problem is the name of the new |
Fair enough I think. It is indeed intended to be mutable. |
By the way, can we use this same fix for ArrayLayouts.jl? Then, I'll make a PR there too |
Probably. I would just call |
Is it correct that it really just comes down to the behaviour of ranges after conversion, or am I missing something? Is there another example where the new |
This fixes the tests on Julia 1.8-beta1. This fixes the underlying problem of JuliaArrays/LazyArrays.jl#205:
For example, on Julia 1.8:
which used to be
This was caused in changes to
LinearAlgebra.copy_oftype
in JuliaLang/julia#40831. As far as I understand, the meaning ofcopy_oftype
used to be wrong and is now correct. I've solved the problem here by callingcopy
directly instead ofcopy_oftype
.