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

Implicitly specify axes using colons in the constructor #139

Merged
merged 3 commits into from
Sep 8, 2020

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Sep 7, 2020

In case certain axes of an array are not offset, they may be implicitly specified using Colons in the constructor. The colons would be replaced by the corresponding axes of the parent array.

julia> OffsetArray(zeros(2,3), :, 4:6)
2×3 OffsetArray(::Array{Float64,2}, 1:2, 4:6) with eltype Float64 with indices 1:2×4:6:
 0.0  0.0  0.0
 0.0  0.0  0.0

This is useful in cases where the size along a non-offset dimension is not known a-priori.

Copy link
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

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

Nicely done! Probably there are some utils in Base that can be reused here, but I think this one is written pretty clearly and self-explained.

The failed test in the nightly build is unrelated so I believe this is good to get merged; the fix for the nightly build can be done in other PR.

@jishnub jishnub changed the title Implicitly specify non-offset axes using colons in the constructor Implicitly specify axes using colons in the constructor Sep 8, 2020
@jishnub
Copy link
Member Author

jishnub commented Sep 8, 2020

This works with offset axes as well, and is not limited to non-offset ones.

julia> OffsetArray(zeros(3:4), :)
2-element OffsetArray(::Array{Float64,1}, 3:4) with eltype Float64 with indices 3:4:
 0.0
 0.0

julia> OffsetArray(zeros(3:4, 5:6), :, 4:5)
2×2 OffsetArray(::Array{Float64,2}, 3:4, 4:5) with eltype Float64 with indices 3:4×4:5:
 0.0  0.0
 0.0  0.0

I wonder if I should add tests for these?

@johnnychen94
Copy link
Member

johnnychen94 commented Sep 8, 2020

yes, we may want to make sure the axes is not changed with : as a regression test.

@johnnychen94
Copy link
Member

reopen this PR to retrigger the nightly test based on #140

@johnnychen94 johnnychen94 reopened this Sep 8, 2020
@codecov
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #139 into master will increase coverage by 4.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #139      +/-   ##
==========================================
+ Coverage   86.29%   90.45%   +4.16%     
==========================================
  Files           2        2              
  Lines         197      220      +23     
==========================================
+ Hits          170      199      +29     
+ Misses         27       21       -6     
Impacted Files Coverage Δ
src/OffsetArrays.jl 90.34% <100.00%> (+3.80%) ⬆️
src/axes.jl 90.90% <0.00%> (+5.54%) ⬆️

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 ff0d630...0e5e083. Read the comment docs.

@johnnychen94
Copy link
Member

johnnychen94 commented Sep 8, 2020

@jishnub If it's okay with you to wait for a few more days, I'd like to make a new release by this weekend with a patch for #136, too.

@johnnychen94 johnnychen94 merged commit ea4008f into JuliaArrays:master Sep 8, 2020
@jishnub
Copy link
Member Author

jishnub commented Sep 9, 2020

I don't have issues with the delay, but I'm just wondering if this should go in a minor release whereas the bugfix for #136 should go in a patch release? Perhaps I'm not clear about the release sequence

@jishnub jishnub deleted the implicit_constructor branch September 21, 2020 05:51
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