-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
A grab bag of latency reductions #35714
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
Changes from all commits
f345c5f
b88d6df
1da1b8d
5206f93
4409d44
41264e4
f83a84c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,6 +310,11 @@ module IteratorsMD | |
convert(::Type{CartesianIndices{N,R}}, inds::CartesianIndices{N}) where {N,R} = | ||
CartesianIndices(convert(R, inds.indices)) | ||
|
||
# equality | ||
Base.:(==)(a::CartesianIndices{N}, b::CartesianIndices{N}) where N = | ||
all(map(==, a.indices, b.indices)) | ||
Base.:(==)(a::CartesianIndices, b::CartesianIndices) = false | ||
|
||
# AbstractArray implementation | ||
Base.axes(iter::CartesianIndices{N,R}) where {N,R} = map(Base.axes1, iter.indices) | ||
Base.IndexStyle(::Type{CartesianIndices{N,R}}) where {N,R} = IndexCartesian() | ||
|
@@ -937,56 +942,6 @@ function fill!(A::AbstractArray{T}, x) where T | |
A | ||
end | ||
|
||
""" | ||
copyto!(dest::AbstractArray, src) -> dest | ||
|
||
|
||
Copy all elements from collection `src` to array `dest`, whose length must be greater than | ||
or equal to the length `n` of `src`. The first `n` elements of `dest` are overwritten, | ||
the other elements are left untouched. | ||
|
||
# Examples | ||
```jldoctest | ||
julia> x = [1., 0., 3., 0., 5.]; | ||
|
||
julia> y = zeros(7); | ||
|
||
julia> copyto!(y, x); | ||
|
||
julia> y | ||
7-element Array{Float64,1}: | ||
1.0 | ||
0.0 | ||
3.0 | ||
0.0 | ||
5.0 | ||
0.0 | ||
0.0 | ||
``` | ||
""" | ||
copyto!(dest, src) | ||
|
||
function copyto!(dest::AbstractArray{T1,N}, src::AbstractArray{T2,N}) where {T1,T2,N} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this method really not needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not actually sure, for now this is just a guess. Have not yet run tests or benchmarks, to me that will be the proof of the pudding. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a good one: on master, julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
1 2
3 4
julia> b = [3, 1, 4, 2]
4-element Array{Int64,1}:
3
1
4
2
julia> copyto!(view(a, b), a)
4-element view(::Array{Int64,1}, [3, 1, 4, 2]) with eltype Int64:
1
3
1
1 vs julia> copyto!(view(a, b), copy(a))
4-element view(::Array{Int64,1}, [3, 1, 4, 2]) with eltype Int64:
1
3
2
4 I'm hoping to fix it in this PR, or will report it if not. |
||
isempty(src) && return dest | ||
src′ = unalias(dest, src) | ||
# fastpath for equal axes (#34025) | ||
if axes(dest) == axes(src) | ||
for I in eachindex(IndexStyle(src′,dest), src′) | ||
@inbounds dest[I] = src′[I] | ||
end | ||
# otherwise enforce linear indexing | ||
else | ||
isrc = eachindex(IndexLinear(), src) | ||
idest = eachindex(IndexLinear(), dest) | ||
ΔI = first(idest) - first(isrc) | ||
checkbounds(dest, last(isrc) + ΔI) | ||
for I in isrc | ||
@inbounds dest[I + ΔI] = src′[I] | ||
end | ||
end | ||
return dest | ||
end | ||
|
||
function copyto!(dest::AbstractArray{T1,N}, Rdest::CartesianIndices{N}, | ||
src::AbstractArray{T2,N}, Rsrc::CartesianIndices{N}) where {T1,T2,N} | ||
isempty(Rdest) && return dest | ||
|
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 would not expect this to make a difference; it doesn't affect inference and we will already avoid specializing this function on
f
.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.
Yeah, it doesn't seem to change anything.