From be7b9722df4f59a9780f626f9c75631d3f4d965a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 24 May 2022 21:36:52 +0400 Subject: [PATCH 1/2] more IOR broadcasting --- src/axes.jl | 14 ++++++++------ test/runtests.jl | 13 ++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 137e8df3..8d12cced 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -246,12 +246,14 @@ for R in [:IIUR, :IdOffsetRange] end # offset-preserve broadcasting -Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(-), r::IdOffsetRange{T}, x::Integer) where T = - IdOffsetRange{T}(r.parent .- x, r.offset) -Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(+), r::IdOffsetRange{T}, x::Integer) where T = - IdOffsetRange{T}(r.parent .+ x, r.offset) -Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(+), x::Integer, r::IdOffsetRange{T}) where T = - IdOffsetRange{T}(x .+ r.parent, r.offset) +Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(-), r::IdOffsetRange, x::Integer) = + IdOffsetRange(r.parent .- x, r.offset) +Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(+), r::IdOffsetRange, x::Integer) = + IdOffsetRange(r.parent .+ x, r.offset) +Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(+), x::Integer, r::IdOffsetRange) = + IdOffsetRange(x .+ r.parent, r.offset) +Broadcast.broadcasted(::Base.Broadcast.DefaultArrayStyle{1}, ::typeof(big), r::IdOffsetRange) = + IdOffsetRange(big.(r.parent), r.offset) Base.show(io::IO, r::IdOffsetRange) = print(io, IdOffsetRange, "(values=",first(r), ':', last(r),", indices=",first(eachindex(r)),':',last(eachindex(r)), ")") diff --git a/test/runtests.jl b/test/runtests.jl index f6327287..e142abcd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -158,8 +158,19 @@ end # broadcasting behavior with scalars (issue #104) r3 = (1 .+ OffsetArrays.IdOffsetRange(3:5, -1) .+ 1) .- 1 + @test r3 isa OffsetArrays.IdOffsetRange @test same_value(r3, 3:5) - check_indexed_by(r3, 0:2) + check_indexed_by(r3, axes(r3,1)) + + r = OffsetArrays.IdOffsetRange(3:5, -1) + rc = copyto!(similar(r), r) + n = big(typemax(Int)) + @test @inferred(broadcast(+, r, n)) == @inferred(broadcast(+, n, r)) == rc .+ n + @test @inferred(broadcast(-, r, n)) == rc .- n + @test @inferred(broadcast(big, r)) == big.(rc) + for n in Any[2, big(typemax(Int))] + @test @inferred(broadcast(+, r, n)) == @inferred(broadcast(+, n, r)) == rc .+ n + end @testset "Idempotent indexing" begin @testset "Indexing into an IdOffsetRange" begin From ee5f5ef68280094a8e9d0423e6f81c88430a7951 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 5 Jun 2022 12:56:33 +0400 Subject: [PATCH 2/2] version bump to v1.12.2 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index cc3ebcbe..99350f4d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "OffsetArrays" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.12.1" +version = "1.12.2" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"