| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 062c8c2 commit 66b81ae
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -224,6 +224,8 @@ namespace xt | |||
| 224 | 224 | storage_type& storage_impl() noexcept; | |
| 225 | 225 | const storage_type& storage_impl() const noexcept; | |
| 226 | 226 | ||
| 227 | + layout_type default_dynamic_layout(); | ||
| 228 | + | ||
| 227 | 229 | friend class xcontainer<pyarray<T, L>>; | |
| 228 | 230 | friend class pycontainer<pyarray<T, L>>; | |
| 229 | 231 | }; | |
@@ -254,48 +256,48 @@ namespace xt | |||
| 254 | 256 | inline pyarray<T, L>::pyarray(const value_type& t) | |
| 255 | 257 | : base_type() | |
| 256 | 258 | { | |
| 257 | - base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 259 | + base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); | ||
| 258 | 260 | nested_copy(m_storage.begin(), t); | |
| 259 | 261 | } | |
| 260 | 262 | ||
| 261 | 263 | template <class T, layout_type L> | |
| 262 | 264 | inline pyarray<T, L>::pyarray(nested_initializer_list_t<T, 1> t) | |
| 263 | 265 | : base_type() | |
| 264 | 266 | { | |
| 265 | - base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 266 | - nested_copy(m_storage.begin(), t); | ||
| 267 | + base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); | ||
| 268 | + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); | ||
| 267 | 269 | } | |
| 268 | 270 | ||
| 269 | 271 | template <class T, layout_type L> | |
| 270 | 272 | inline pyarray<T, L>::pyarray(nested_initializer_list_t<T, 2> t) | |
| 271 | 273 | : base_type() | |
| 272 | 274 | { | |
| 273 | - base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 274 | - nested_copy(m_storage.begin(), t); | ||
| 275 | + base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); | ||
| 276 | + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); | ||
| 275 | 277 | } | |
| 276 | 278 | ||
| 277 | 279 | template <class T, layout_type L> | |
| 278 | 280 | inline pyarray<T, L>::pyarray(nested_initializer_list_t<T, 3> t) | |
| 279 | 281 | : base_type() | |
| 280 | 282 | { | |
| 281 | - base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 282 | - nested_copy(m_storage.begin(), t); | ||
| 283 | + base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); | ||
| 284 | + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); | ||
| 283 | 285 | } | |
| 284 | 286 | ||
| 285 | 287 | template <class T, layout_type L> | |
| 286 | 288 | inline pyarray<T, L>::pyarray(nested_initializer_list_t<T, 4> t) | |
| 287 | 289 | : base_type() | |
| 288 | 290 | { | |
| 289 | - base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 290 | - nested_copy(m_storage.begin(), t); | ||
| 291 | + base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); | ||
| 292 | + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); | ||
| 291 | 293 | } | |
| 292 | 294 | ||
| 293 | 295 | template <class T, layout_type L> | |
| 294 | 296 | inline pyarray<T, L>::pyarray(nested_initializer_list_t<T, 5> t) | |
| 295 | 297 | : base_type() | |
| 296 | 298 | { | |
| 297 | - base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 298 | - nested_copy(m_storage.begin(), t); | ||
| 299 | + base_type::resize(xt::shape<shape_type>(t), default_dynamic_layout()); | ||
| 300 | + L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin<layout_type::row_major>(), t); | ||
| 299 | 301 | } | |
| 300 | 302 | ||
| 301 | 303 | template <class T, layout_type L> | |
@@ -443,7 +445,9 @@ namespace xt | |||
| 443 | 445 | // TODO: prevent intermediary shape allocation | |
| 444 | 446 | shape_type shape = xtl::forward_sequence<shape_type, decltype(e.derived_cast().shape())>(e.derived_cast().shape()); | |
| 445 | 447 | strides_type strides = xtl::make_sequence<strides_type>(shape.size(), size_type(0)); | |
| 446 | - compute_strides(shape, L, strides); | ||
| 448 | + layout_type layout = default_dynamic_layout(); | ||
| 449 | + | ||
| 450 | + compute_strides(shape, layout, strides); | ||
| 447 | 451 | init_array(shape, strides); | |
| 448 | 452 | semantic_base::assign(e); | |
| 449 | 453 | } | |
@@ -559,6 +563,12 @@ namespace xt | |||
| 559 | 563 | { | |
| 560 | 564 | return m_storage; | |
| 561 | 565 | } | |
| 566 | + | ||
| 567 | + template <class T, layout_type L> | ||
| 568 | + layout_type pyarray<T, L>::default_dynamic_layout() | ||
| 569 | + { | ||
| 570 | + return L == layout_type::dynamic ? layout_type::row_major : L; | ||
| 571 | + } | ||
| 562 | 572 | } | |
| 563 | 573 | ||
| 564 | 574 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,17 +37,44 @@ namespace xt | |||
| 37 | 37 | ||
| 38 | 38 | TEST(pyarray, initializer_constructor) | |
| 39 | 39 | { | |
| 40 | - pyarray<int> t | ||
| 40 | + pyarray<int> r | ||
| 41 | 41 | {{{ 0, 1, 2}, | |
| 42 | 42 | { 3, 4, 5}, | |
| 43 | 43 | { 6, 7, 8}}, | |
| 44 | 44 | {{ 9, 10, 11}, | |
| 45 | 45 | {12, 13, 14}, | |
| 46 | 46 | {15, 16, 17}}}; | |
| 47 | 47 | ||
| 48 | - EXPECT_EQ(t.dimension(), 3); | ||
| 49 | - EXPECT_EQ(t(0, 0, 1), 1); | ||
| 50 | - EXPECT_EQ(t.shape()[0], 2); | ||
| 48 | + EXPECT_EQ(r.layout(), xt::layout_type::row_major); | ||
| 49 | + EXPECT_EQ(r.dimension(), 3); | ||
| 50 | + EXPECT_EQ(r(0, 0, 1), 1); | ||
| 51 | + EXPECT_EQ(r.shape()[0], 2); | ||
| 52 | + | ||
| 53 | + pyarray<int, xt::layout_type::column_major> c | ||
| 54 | + {{{ 0, 1, 2}, | ||
| 55 | + { 3, 4, 5}, | ||
| 56 | + { 6, 7, 8}}, | ||
| 57 | + {{ 9, 10, 11}, | ||
| 58 | + {12, 13, 14}, | ||
| 59 | + {15, 16, 17}}}; | ||
| 60 | + | ||
| 61 | + EXPECT_EQ(c.layout(), xt::layout_type::column_major); | ||
| 62 | + EXPECT_EQ(c.dimension(), 3); | ||
| 63 | + EXPECT_EQ(c(0, 0, 1), 1); | ||
| 64 | + EXPECT_EQ(c.shape()[0], 2); | ||
| 65 | + | ||
| 66 | + pyarray<int, xt::layout_type::dynamic> d | ||
| 67 | + {{{ 0, 1, 2}, | ||
| 68 | + { 3, 4, 5}, | ||
| 69 | + { 6, 7, 8}}, | ||
| 70 | + {{ 9, 10, 11}, | ||
| 71 | + {12, 13, 14}, | ||
| 72 | + {15, 16, 17}}}; | ||
| 73 | + | ||
| 74 | + EXPECT_EQ(d.layout(), xt::layout_type::row_major); | ||
| 75 | + EXPECT_EQ(d.dimension(), 3); | ||
| 76 | + EXPECT_EQ(d(0, 0, 1), 1); | ||
| 77 | + EXPECT_EQ(d.shape()[0], 2); | ||
| 51 | 78 | } | |
| 52 | 79 | ||
| 53 | 80 | TEST(pyarray, shaped_constructor) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments