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

Added function to create std::variant for multiple array views. #220

Merged
merged 26 commits into from
Oct 8, 2024

Conversation

odlomax
Copy link
Contributor

@odlomax odlomax commented Aug 22, 2024

During PR #218, I found myself writing two nested switch statements in order to create an ArrayView from an Array. I've found myself writing this same pattern multiple times throughout Atlas, and indeed other external applications which use atlas.

This PR adds provides an alternative to the nested switch statement. The method util::make_array_view_variant<Values<types...>, Ranks<ints...>>(Array& array) creates an std::variant of ArrayView types, and then assigns the view that matches array (so long as the value-type and rank can be found within the Values and Ranks arguments respectively. The ArrayView can then be accessed rather succinctly using std::visit.

@wdeconinck
Copy link
Member

Hi @odlomax I think this is a great idea.
I was wondering if this should not become part of the "array" namespace. If you want we could discuss offline.
It should also cater for device views though.
array::make_host_view_variant and array::make_device_view_variant
All possibly supported Values and Ranks could be immediately part of the variant type, removing even more boiler-plate?

@odlomax
Copy link
Contributor Author

odlomax commented Aug 23, 2024

Hi @odlomax I think this is a great idea. I was wondering if this should not become part of the "array" namespace. If you want we could discuss offline. It should also cater for device views though. array::make_host_view_variant and array::make_device_view_variant All possibly supported Values and Ranks could be immediately part of the variant type, removing even more boiler-plate?

Hi @wdeconinck,

Thanks for the feedback! I'm on leave at the moment, but this is oddly recreational between baby's naps. I'll arrange a catch up when I'm back after next week. 🙂

@odlomax
Copy link
Contributor Author

odlomax commented Sep 13, 2024

Hi @wdeconinck. I believe I've incorporated all of your suggestions. It's ready for a look when you have the time. Cheers!

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 92.96875% with 9 lines in your changes missing coverage. Please review.

Project coverage is 80.02%. Comparing base (afd3b5f) to head (73d990f).
Report is 14 commits behind head on develop.

Files with missing lines Patch % Lines
src/tests/array/test_array_view_variant.cc 92.70% 7 Missing ⚠️
src/atlas/array/ArrayViewVariant.cc 93.75% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #220      +/-   ##
===========================================
+ Coverage    79.95%   80.02%   +0.06%     
===========================================
  Files          792      794       +2     
  Lines        62309    62491     +182     
===========================================
+ Hits         49822    50011     +189     
+ Misses       12487    12480       -7     

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

@odlomax
Copy link
Contributor Author

odlomax commented Sep 16, 2024

@wdeconinck Apologies for the last minute push.

There were relatively important EXPECT statements that needed to be added to lines 139 and 164 of the test. I also removed some extraneous whitespace at the end of an otherwise untouched file.

@odlomax
Copy link
Contributor Author

odlomax commented Sep 17, 2024

Okay, I won't touch this until it's reviewed. I promise!

@odlomax
Copy link
Contributor Author

odlomax commented Sep 25, 2024

Hi @wdeconinck,

When attempting to using this in anger (see PR #226), I found that it was worth refactoring the make_view_variant methods to produce either const or non-const versions of the variant depending on the constness of the array. Shall I merge the refactor into this PR, or leave it in #226?

@odlomax
Copy link
Contributor Author

odlomax commented Oct 2, 2024

Hi @wdeconinck @sbrdar,

I've refactored the introspection helpers as we discussed on Slack. I've also added an additional helper to distinguish between value_type and non_const_value_type. Seemed like a sensible idea.

Cheers!

@odlomax
Copy link
Contributor Author

odlomax commented Oct 2, 2024

@wdeconinck the latest push has your suggested signature for the introspection helpers. Thanks for the suggestion, it's a lot tidier.

@odlomax
Copy link
Contributor Author

odlomax commented Oct 3, 2024

@odlomax
Copy link
Contributor Author

odlomax commented Oct 4, 2024

MacOS tests! Nooo!

@wdeconinck
Copy link
Member

MacOS tests! Nooo!

https://github.com/ecmwf/atlas/actions/runs/11157941275/job/31068813417?pr=220 should not be the problem of this PR, but about the CI infrastructure. I passed on this problem.

Copy link
Member

@wdeconinck wdeconinck left a comment

Choose a reason for hiding this comment

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

This looks great now! Thanks!

@wdeconinck wdeconinck merged commit b944fba into ecmwf:develop Oct 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants