Skip to content

Commit

Permalink
_unsafe_wrap: Allow ind NTuple to have mixed AbstractUnitRanges (#296)
Browse files Browse the repository at this point in the history
* Implement Base.unsafe_wrap for OffsetArrays

* Implement Base.unsafe_wrap for OffsetArrays

* _unsafe_wrap: Allow NTuple to have mixed AbstractUnitRanges

* Fix double free

* Bump version to 1.12.1
  • Loading branch information
mkitti authored May 29, 2022
1 parent c42fe3d commit a094f04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "OffsetArrays"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.12.0"
version = "1.12.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ function Base.replace_in_print_matrix(A::OffsetArray{<:Any,1}, i::Integer, j::In
end

# Actual unsafe_wrap implementation
@inline function _unsafe_wrap(pointer::Ptr{T}, inds::NTuple{N}; own = false, kw...) where {T,N}
@inline function _unsafe_wrap(pointer::Ptr{T}, inds::NTuple{N, OffsetAxisKnownLength}; own = false, kw...) where {T,N}
_checkindices(N, inds, "indices")
AA = Base.unsafe_wrap(Array, pointer, map(_indexlength, inds); own=own)
OffsetArray{T, N, typeof(AA)}(AA, map(_indexoffset, inds); kw...)
Expand Down
14 changes: 8 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2678,11 +2678,6 @@ include("origin.jl")
@test OffsetArrays._addoffset(3:2:9, 1) == 4:2:10
end

@info "Following deprecations are expected"
@testset "deprecations" begin
A = reshape(collect(1:9), 3, 3)
@test OffsetArrays.centered(A, RoundDown) == OffsetArrays.centered(A, RoundUp)
end
@testset "unsafe_wrap" begin
p = Ptr{UInt16}(Libc.malloc(2*3*4*2))
@test unsafe_wrap(OffsetArray, p, 2, 3, 4) isa OffsetArray{UInt16, 3}
Expand All @@ -2697,5 +2692,12 @@ end
@test unsafe_wrap(OffsetArray, p, 2:3, 3:5, 4:7) isa OffsetArray{UInt8, 3}
@test unsafe_wrap(OffsetArray, p, (2:3, 3:5, 4:7)) isa OffsetArray{UInt8, 3}
@test unsafe_wrap(OffsetVector, p, 1:(2*3*4) .- 1) isa OffsetVector{UInt8}
@test unsafe_wrap(OffsetMatrix, p, 1:(2*3) .+ 6, 4:7; own = true) isa OffsetMatrix{UInt8}
@test unsafe_wrap(OffsetMatrix, p, 1:(2*3) .+ 6, 4:7) isa OffsetMatrix{UInt8}
@test unsafe_wrap(OffsetMatrix, p, -5:5, Base.OneTo(3); own = true) isa OffsetMatrix{UInt8}
end

@info "Following deprecations are expected"
@testset "deprecations" begin
A = reshape(collect(1:9), 3, 3)
@test OffsetArrays.centered(A, RoundDown) == OffsetArrays.centered(A, RoundUp)
end

2 comments on commit a094f04

@jishnub
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/61265

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.12.1 -m "<description of version>" a094f04a6e75da1e67c6060fa2f4498d9a29c320
git push origin v1.12.1

Please sign in to comment.