JuliaArrays / PaddedViews.jl

Add virtual padding to the edges of an array
Other
49 stars 9 forks source link

allow users to explicity specify filltype #27

Closed johnnychen94 closed 4 years ago

johnnychen94 commented 4 years ago

Continues #25 and #26

Users now can control the eltype of PaddedView using PaddedView{T}(fillvalue, data, ...). If T is not provided, it infers the appropriate type from fillvalue and data using filltype, which is the previous behavior.

However, it's expected that the benchmark is not optimistic if we're abusing the usage:

UInt -> Int:

julia> A = UInt.(repeat(collect(1:512), 1, 512));
julia> B_Int = PaddedView{Int}(0.0, A, (-2:515, -2:515));
julia> B_UInt = PaddedView{UInt}(0.0, A, (-2:515, -2:515));

julia> @btime collect(A);
  90.161 μs (2 allocations: 2.00 MiB)

julia> @btime collect($B_UInt); # baseline # PaddedViews 0.5.3: 240.691 μs
  241.527 μs (2 allocations: 2.05 MiB)

julia> @btime collect($B_Int); # slower
  291.259 μs (2 allocations: 2.05 MiB)

Int -> UInt:

julia> A = Int.(repeat(collect(1:512), 1, 512));
julia> B_Int = PaddedView{Int}(0.0, A, (-2:515, -2:515));
julia> B_UInt = PaddedView{UInt}(0.0, A, (-2:515, -2:515));

julia> @btime collect(A);
  87.306 μs (2 allocations: 2.00 MiB)

julia> @btime collect($B_Int); # baseline # PaddedViews 0.5.3: 165.079 μs
  172.315 μs (2 allocations: 2.05 MiB)

julia> @btime collect($B_UInt); # slower
  297.698 μs (2 allocations: 2.05 MiB)

P.S., Is there anything we can do inside this package to reduce the timing difference between collect(A) and collect(B)?

timholy commented 4 years ago

Thanks! It all just keeps getting better!