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

fixed select_region and colleagues. #13

Merged
merged 4 commits into from
Dec 21, 2023
Merged

Conversation

RainerHeintzmann
Copy link
Member

fixed a bug in select_region, select_region! and added the dst_center argument to select_region_view.

@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (980f967) 91.28% compared to head (4fbe45e) 91.74%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
+ Coverage   91.28%   91.74%   +0.45%     
==========================================
  Files          10       11       +1     
  Lines         218      218              
==========================================
+ Hits          199      200       +1     
+ Misses         19       18       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -311,9 +318,9 @@ julia> dst=select_region(a,new_size=(10,10), dst_center=(1,1)) # pad a with zero
0.0 0.0 0.0 0.0 0.0 0.0 2.0 2.0 2.0 2.0
```
"""
function select_region!(src, dst; new_size=size(dst),
function select_region!(src, dst; new_size=ntuple((d)->typemax(Int)÷2,Val(length(size(src)))),
Copy link
Member

Choose a reason for hiding this comment

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

why typemax?
You can also use nothing to handle that.
Also instead of using length(size(src)) better do src::AbstractArray{T, N} and use the parametric type N.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to avoid branches in the code. First had a "nothing" version but this would anyway then branch to the same expression.
typemax is needed as the index-calculation which is used explicitely considers a finite copy-size. If the user specifies center=-100, dst_center=-100 it should still work. For copy operations such as in select_region!() the code still insists on the centers, if the new_size is specifies, but it should allow for maximal src and dst overlap, in case the user does not specify new_size.

Copy link
Member Author

Choose a reason for hiding this comment

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

... the use of length was fixed now.

function select_region!(src, dst; new_size=size(dst),
center=size(src).÷2 .+1, dst_center=size(dst).÷ 2 .+1, operator! =assign_to!)
new_size = Tuple(expand_size(new_size, size(dst)))
function select_region!(src::AbstractArray{T, N}, dst; new_size=ntuple((d)->typemax(Int)÷2,Val(N)),
Copy link
Member

Choose a reason for hiding this comment

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

still think that typemax is hacky.
even -1 would be better

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you prefer this version? I hope it is correct for even and odd sizes alike.

@@ -252,7 +255,10 @@ end


"""
select_region!(src, dst=nothing; new_size=size(src), center=size(src).÷2 .+1, dst_center=nothing, pad_value=zero(eltype(mat), operator!=assign_to!))
select_region!(srcsrc::AbstractArray{T, N}, dst=nothing;
Copy link
Member

Choose a reason for hiding this comment

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

why srcsrc?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was a typo in the documentation. Fixed now. Also added test cases.

@roflmaostc
Copy link
Member

@roflmaostc
Copy link
Member

Did you run the tests locally? I rerun them here.
select_region is quite a stable and often used functions. So we should definitely avoid any issues with that.
Please check with code_warntype that everything infers well and that there are no spurious allocations.

@roflmaostc
Copy link
Member

So ready to merge?

@RainerHeintzmann
Copy link
Member Author

Yes. I can merge, if you agree.

@RainerHeintzmann RainerHeintzmann merged commit 041d090 into main Dec 21, 2023
6 checks passed
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