Fix to copyto!(::ArrayPartition,::ArrayPartition) and copyto!(::Array,::ArrayPartition) - #69
Merged
Merged
Conversation
| @@ -0,0 +1,23 @@ | |||
| using RecursiveArrayTools, BenchmarkTools | |||
|
|
|||
| function Base.copyto!(A::ArrayPartition,src::ArrayPartition) | |||
Member
There was a problem hiding this comment.
what's this file for?
Contributor
Author
There was a problem hiding this comment.
sorry just used for benchmarking, will remove.
| @inbounds for i in 1:length(A.x) | ||
| A.x[i] .= @view(src[cur:(cur+length(A.x[i])-1)]) | ||
| cur += length(A.x[i]) | ||
| if size.(A.x) == size.(src.x) |
Member
There was a problem hiding this comment.
does this need if all(...)?
Contributor
Author
There was a problem hiding this comment.
It seems to be working without all... I guess when using all you would need .==?
Contributor
Author
There was a problem hiding this comment.
It seems we have to use size.(A.x) == size.(src.x). If partition don't agree this can happen:
julia> x = ArrayPartition(randn(3,2),randn(2)); y = ArrayPartition(randn(3),randn(3),randn(2));
julia> all(size.(x.x) .== size.(y.x))
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")
nantonel
commented
Aug 7, 2019
| Base.any(f,A::ArrayPartition) = any(f,(any(f,x) for x in A.x)) | ||
| Base.any(f::Function,A::ArrayPartition) = any(f,(any(f,x) for x in A.x)) | ||
| function Base.copyto!(dest::Array,A::ArrayPartition) | ||
| function Base.copyto!(dest::AbstractArray,A::ArrayPartition) |
Contributor
Author
There was a problem hiding this comment.
this seems more general
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addressing #68
I've also added a fix to the method
copyto!(::Array,::ArrayPartition)and added some tests.Concerning the method
copyto!(::ArrayPartition,::ArrayPartition)I finally went for a "hybrid solution".Since
x.=yis way faster that the implementation I've proposed in #68 and most of the time it is expected forArrayPartitions to be partitioned equally I'm calling thex.=ywhen this is the case.It is not so elegant but still it allows for different partitioning and adds only little overhead when
ArrayPartitions have the same partitioning.Let me know if you think there is room for improvement!