Skip to content
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

_unsafe_wrap: Allow ind NTuple to have mixed AbstractUnitRanges #296

Merged
merged 5 commits into from
May 29, 2022

Conversation

mkitti
Copy link
Contributor

@mkitti mkitti commented May 27, 2022

master:

julia> using OffsetArrays

julia> unsafe_wrap(OffsetArray{Int}, Ptr{Int}(Libc.malloc(7*11*8)), -3:3, -5:5);

julia> unsafe_wrap(OffsetArray{Int}, Ptr{Int}(Libc.malloc(7*11*8)), -3:3, Base.OneTo(5));
ERROR: MethodError: no method matching _unsafe_wrap(::Ptr{Int64}, ::Tuple{UnitRange{Int64}, Base.OneTo{Int64}})
Closest candidates are:
  _unsafe_wrap(::Ptr{T}, ::Tuple{Vararg{T, N}} where T; own, kw...) where {T, N} at ~/.julia/dev/OffsetArrays/src/OffsetArrays.jl:629

This pull request

julia> using OffsetArrays

julia> unsafe_wrap(OffsetArray{Int}, Ptr{Int}(Libc.malloc(7*11*8)), -3:3, -5:5);

julia> unsafe_wrap(OffsetArray{Int}, Ptr{Int}(Libc.malloc(7*11*8)), -3:3, Base.OneTo(5));

This normalizes unsafe_wrap to take similar arguments as the constructors.

@codecov
Copy link

codecov bot commented May 27, 2022

Codecov Report

Merging #296 (c82d196) into master (c42fe3d) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #296   +/-   ##
=======================================
  Coverage   96.35%   96.35%           
=======================================
  Files           5        5           
  Lines         439      439           
=======================================
  Hits          423      423           
  Misses         16       16           
Impacted Files Coverage Δ
src/OffsetArrays.jl 98.27% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c42fe3d...c82d196. Read the comment docs.

@@ -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}
Copy link
Member

Choose a reason for hiding this comment

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

I've not followed this closely, but is this test not valid? Or is it simply unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I only allocated one pointer, there can only be one own = true, otherwise Julia will try to free the pointer twice.

@jishnub
Copy link
Member

jishnub commented May 27, 2022

LGTM overall

@jishnub
Copy link
Member

jishnub commented May 28, 2022

Could you also bump the patch version?

@mkitti
Copy link
Contributor Author

mkitti commented May 28, 2022

Thanks for the suggestion. Version has been bumped to 1.12.1

@jishnub jishnub merged commit a094f04 into JuliaArrays:master May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants