Skip to content

Commit a094f04

Browse files
authored
_unsafe_wrap: Allow ind NTuple to have mixed AbstractUnitRanges (#296)
* 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
1 parent c42fe3d commit a094f04

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OffsetArrays"
22
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
3-
version = "1.12.0"
3+
version = "1.12.1"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/OffsetArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ function Base.replace_in_print_matrix(A::OffsetArray{<:Any,1}, i::Integer, j::In
626626
end
627627

628628
# Actual unsafe_wrap implementation
629-
@inline function _unsafe_wrap(pointer::Ptr{T}, inds::NTuple{N}; own = false, kw...) where {T,N}
629+
@inline function _unsafe_wrap(pointer::Ptr{T}, inds::NTuple{N, OffsetAxisKnownLength}; own = false, kw...) where {T,N}
630630
_checkindices(N, inds, "indices")
631631
AA = Base.unsafe_wrap(Array, pointer, map(_indexlength, inds); own=own)
632632
OffsetArray{T, N, typeof(AA)}(AA, map(_indexoffset, inds); kw...)

test/runtests.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,11 +2678,6 @@ include("origin.jl")
26782678
@test OffsetArrays._addoffset(3:2:9, 1) == 4:2:10
26792679
end
26802680

2681-
@info "Following deprecations are expected"
2682-
@testset "deprecations" begin
2683-
A = reshape(collect(1:9), 3, 3)
2684-
@test OffsetArrays.centered(A, RoundDown) == OffsetArrays.centered(A, RoundUp)
2685-
end
26862681
@testset "unsafe_wrap" begin
26872682
p = Ptr{UInt16}(Libc.malloc(2*3*4*2))
26882683
@test unsafe_wrap(OffsetArray, p, 2, 3, 4) isa OffsetArray{UInt16, 3}
@@ -2697,5 +2692,12 @@ end
26972692
@test unsafe_wrap(OffsetArray, p, 2:3, 3:5, 4:7) isa OffsetArray{UInt8, 3}
26982693
@test unsafe_wrap(OffsetArray, p, (2:3, 3:5, 4:7)) isa OffsetArray{UInt8, 3}
26992694
@test unsafe_wrap(OffsetVector, p, 1:(2*3*4) .- 1) isa OffsetVector{UInt8}
2700-
@test unsafe_wrap(OffsetMatrix, p, 1:(2*3) .+ 6, 4:7; own = true) isa OffsetMatrix{UInt8}
2695+
@test unsafe_wrap(OffsetMatrix, p, 1:(2*3) .+ 6, 4:7) isa OffsetMatrix{UInt8}
2696+
@test unsafe_wrap(OffsetMatrix, p, -5:5, Base.OneTo(3); own = true) isa OffsetMatrix{UInt8}
2697+
end
2698+
2699+
@info "Following deprecations are expected"
2700+
@testset "deprecations" begin
2701+
A = reshape(collect(1:9), 3, 3)
2702+
@test OffsetArrays.centered(A, RoundDown) == OffsetArrays.centered(A, RoundUp)
27012703
end

0 commit comments

Comments
 (0)