Skip to content

Make reshape_view accept -1 as a wildcard dimension#2746

Merged
JohanMabille merged 6 commits intoxtensor-stack:masterfrom
spectre-ns:reshape
Nov 16, 2023
Merged

Make reshape_view accept -1 as a wildcard dimension#2746
JohanMabille merged 6 commits intoxtensor-stack:masterfrom
spectre-ns:reshape

Conversation

@spectre-ns
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread include/xtensor/xstrided_view.hpp
Comment thread include/xtensor/xstrided_view.hpp
Comment thread include/xtensor/xstrided_view.hpp Outdated
Comment thread include/xtensor/xstrided_view.hpp Outdated
Comment thread include/xtensor/xstrided_view.hpp Outdated
@spectre-ns
Copy link
Copy Markdown
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.

Comment thread include/xtensor/xstrided_view.hpp Outdated
Comment thread include/xtensor/xstrided_view.hpp Outdated
Comment thread include/xtensor/xstrided_view.hpp
@tdegeus
Copy link
Copy Markdown
Member

tdegeus commented Nov 15, 2023

Thanks! Great work. Some minor comments

spectre-ns and others added 3 commits November 15, 2023 08:29
Co-authored-by: Tom de Geus <tdegeus@users.noreply.github.com>
@spectre-ns
Copy link
Copy Markdown
Contributor Author

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

@spectre-ns spectre-ns requested a review from tdegeus November 16, 2023 11:38
Comment thread include/xtensor/xstrided_view.hpp
Comment thread include/xtensor/xstrided_view.hpp Outdated
Comment thread include/xtensor/xstrided_view.hpp Outdated
Comment thread include/xtensor/xstrided_view.hpp
@JohanMabille
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Thanks again!

@JohanMabille JohanMabille merged commit 69eaac5 into xtensor-stack:master Nov 16, 2023
@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