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

Make reshape_view accept -1 as a wildcard dimension #2746

Merged
merged 6 commits into from
Nov 16, 2023

Conversation

spectre-ns
Copy link
Contributor

@spectre-ns spectre-ns commented Nov 11, 2023

Checklist

  • [ x] The title and commit message(s) are descriptive.
  • [ x] Small commits made to fix your PR have been squashed to avoid history pollution.
  • [ x] Tests have been added for new features or bug fixes.
  • [ x] API of new functions and classes are documented.

Description

Fix #2417
@JohanMabille @tdegeus this is failing the type check at test_xstrided_view.cpp(709). I was unable to cast the underlying std::array to unsigned using std::make_unsigned as I expected. Any help would be appreciated. I think apart from that it should be identical to the previous implementation as it only implements the check when given signed integers and preserves static lengths using std::array<T,N>

@spectre-ns
Copy link
Contributor Author

spectre-ns commented Nov 11, 2023

I got everything working without modifying the unit tests. I question the need to compare if the view and expression have the same shape type. The machinery required to do the cast to std::size_t is pretty complicated for what it is. I'd prefer to drop it.

@tdegeus
Copy link
Member

tdegeus commented Nov 13, 2023

I'm probably missing something, but is there not a way to re-use existing machinery?

@spectre-ns
Copy link
Contributor Author

I'm probably missing something, but is there not a way to re-use existing machinery?

I could have reused xcontainer's implementation but the mechanics seemed looked up in a member function. I suppose I could refactor to have a shared implementation, but it doesn't seem right to have the view depend on xcontainer.

xstrided_container<D>::reshape_impl(S&& shape, std::false_type /* is unsigned */, layout_type layout)

Let me know what you think.

include/xtensor/xstrided_view.hpp Show resolved Hide resolved
include/xtensor/xstrided_view.hpp Show resolved Hide resolved
include/xtensor/xstrided_view.hpp Outdated Show resolved Hide resolved
include/xtensor/xstrided_view.hpp Outdated Show resolved Hide resolved
include/xtensor/xstrided_view.hpp Outdated Show resolved Hide resolved
@spectre-ns
Copy link
Contributor Author

spectre-ns commented Nov 15, 2023

@JohanMabille @tdegeus I think this one should be implemented as requested. I'd like some suggestions on implementation clean up. I'm still learning my metatemplate syntax and idioms.

@tdegeus
Copy link
Member

tdegeus commented Nov 15, 2023

Thanks! Great work. Some minor comments

@spectre-ns
Copy link
Contributor Author

@JohanMabille I think the PR should be ready to merge! :)

@JohanMabille
Copy link
Member

JohanMabille commented Nov 16, 2023

@spectre-ns thanks a lot for your work on this and your patience! I added some minor comments.

@spectre-ns
Copy link
Contributor Author

@spectre-ns thanks a lot for your work on this and your patience! I added some minor comments.

@JohanMabille I have addressed your comments

@JohanMabille
Copy link
Member

Thanks again!

@JohanMabille JohanMabille merged commit 69eaac5 into xtensor-stack:master Nov 16, 2023
12 checks passed
@spectre-ns spectre-ns deleted the reshape branch November 16, 2023 19:15
@JohanMabille JohanMabille changed the title [WIP] Make reshape_view accept -1 as a wildcard dimension Make reshape_view accept -1 as a wildcard dimension Jan 25, 2024
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.

reshape view doesn't infer shape from -1
3 participants