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

reshape with array_view #86

Open
mmorale3 opened this issue Feb 11, 2025 · 0 comments
Open

reshape with array_view #86

mmorale3 opened this issue Feb 11, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@mmorale3
Copy link
Collaborator

Prerequisites

Description

Not sure if this is a bug or expected behavior.
Consider the following unit tests (following style from tests/c++/nda_functions.cpp

TEST(reshape, reshape_view) { //NOLINT

nda::array<long, 1> a{1, 2, 3, 4, 5, 6}; // 1d array
auto v = reshape(a(nda::range::all), std::array{2, 3}); // v is an array_view<long,2> of size 2 x 3
v(0, nda::range::all) *= 10; // a is now {10, 20, 30, 4, 5, 6}

EXPECT_EQ_ARRAY(a, (nda::array<long, 1>{10, 20, 30, 4, 5, 6}));
}
//================================================

TEST(reshape, reshape_view_strided) { //NOLINT

nda::array<long, 1> a{1, 2, 3, 4, 5, 6}; // 1d array
auto v = reshape(a(nda::range(6)), std::array{2, 3}); // v is an array_view<long,2> of size 2 x 3
v(0, nda::range::all) *= 10; // a is now {10, 20, 30, 4, 5, 6}

EXPECT_EQ_ARRAY(a, (nda::array<long, 1>{10, 20, 30, 4, 5, 6}));
}
//================================================

The first one works as expected. The second one fails with the following message:

nda/c++/nda/./././layout/idx_map.hpp: In instantiation of 'class nda::idx_map<2, 0, 0, nda::layout_prop_e::strided_1d>':
nda/c++/nda/././linalg/../blas/../layout_transforms.hpp:121:32: required from 'auto nda::reshape(A&&, const std::array<Int, Rank>&) [with A = nda::basic_array_view<long int, 1, nda::basic_layout<0, 0, nda::layout_prop_e::strided_1d>, 'A', nda::default_accessor, nda::borrowed<> >; Int = int; auto R = 2]'
nda/test/c++/nda_functions.cpp:104:19: required from here
nda/c++/nda/./././layout/idx_map.hpp:105:38: error: static assertion failed: Error in nda::idx_map: StrideOrder can only be zero for 1D arrays
105 | static_assert((StrideOrder != 0) or (Rank == 1), "Error in nda::idx_map: StrideOrder can only be zero for 1D arrays");
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
nda/c++/nda/./././layout/idx_map.hpp:105:38: note: '((0 != 0) || (2 == 1))' evaluates to false
...
nda/c++/nda/././layout/./../stdutil/array.hpp: In instantiation of 'nda::stdutil::make_initialized_array<4, int>(int)::<lambda(std::index_sequence<I ...>)> [with long unsigned int ...Is = {0, 1, 2, 3}; std::index_sequence<I ...> = std::integer_sequence<long unsigned int, 0, 1, 2, 3>]':

Steps to Reproduce

Add unit tests described above to nda_functions.cpp.

Expected behavior: [What you expect to happen]

To be able to reshape an array_view (with strided_1d layout) in cases where the storage is contiguous (compact strides).

Actual behavior:

Compilation error.

Possibly coming from layout_transformations.hpp,

line ~125
using layout_t = typename std::decay_t::layout_policy_t::template mapping;

Versions

1.3.x (and all versions before).

@mmorale3 mmorale3 added the bug Something isn't working label Feb 11, 2025
@mmorale3 mmorale3 changed the title Bug report reshape with array_view Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant