| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ install: | |||
| 23 | 23 | - conda update -q conda | |
| 24 | 24 | - conda info -a | |
| 25 | 25 | - conda install gtest cmake -c conda-forge | |
| 26 | - - conda install xtensor==0.14.0 pytest numpy pybind11==2.2.1 -c conda-forge | ||
| 26 | + - conda install xtensor==0.15.0 pytest numpy pybind11==2.2.1 -c conda-forge | ||
| 27 | 27 | - "set PYTHONHOME=%MINICONDA%" | |
| 28 | 28 | - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe . | |
| 29 | 29 | - nmake test_xtensor_python | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,7 +95,7 @@ install: | |||
| 95 | 95 | - conda update -q conda | |
| 96 | 96 | # Useful for debugging any issues with conda | |
| 97 | 97 | - conda info -a | |
| 98 | - - conda install xtensor==0.14.0 pytest numpy pybind11==2.2.1 -c conda-forge | ||
| 98 | + - conda install xtensor==0.15.0 pytest numpy pybind11==2.2.1 -c conda-forge | ||
| 99 | 99 | - conda install cmake gtest -c conda-forge | |
| 100 | 100 | - cmake -D BUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda . | |
| 101 | 101 | - make -j2 test_xtensor_python | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -187,7 +187,7 @@ from the `docs` subdirectory. | |||
| 187 | 187 | ||
| 188 | 188 | | `xtensor-python` | `xtensor` | `pybind11` | | |
| 189 | 189 | |------------------|-----------|------------------| | |
| 190 | - | master | ^0.14.0 | ~2.1.0 or ~2.2.1 | | ||
| 190 | + | master | ^0.15.0 | ~2.1.0 or ~2.2.1 | | ||
| 191 | 191 | | 0.16.x | ^0.14.0 | ~2.1.0 or ~2.2.1 | | |
| 192 | 192 | | 0.15.x | ^0.13.1 | ~2.1.0 or ~2.2.1 | | |
| 193 | 193 | | 0.14.x | ^0.12.0 | ~2.1.0 or ~2.2.1 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -486,47 +486,47 @@ namespace xt | |||
| 486 | 486 | inline pyarray<T>::pyarray(const value_type& t) | |
| 487 | 487 | : base_type() | |
| 488 | 488 | { | |
| 489 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 489 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 490 | 490 | nested_copy(m_data.begin(), t); | |
| 491 | 491 | } | |
| 492 | 492 | ||
| 493 | 493 | template <class T> | |
| 494 | 494 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 1> t) | |
| 495 | 495 | : base_type() | |
| 496 | 496 | { | |
| 497 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 497 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 498 | 498 | nested_copy(m_data.begin(), t); | |
| 499 | 499 | } | |
| 500 | 500 | ||
| 501 | 501 | template <class T> | |
| 502 | 502 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 2> t) | |
| 503 | 503 | : base_type() | |
| 504 | 504 | { | |
| 505 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 505 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 506 | 506 | nested_copy(m_data.begin(), t); | |
| 507 | 507 | } | |
| 508 | 508 | ||
| 509 | 509 | template <class T> | |
| 510 | 510 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 3> t) | |
| 511 | 511 | : base_type() | |
| 512 | 512 | { | |
| 513 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 513 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 514 | 514 | nested_copy(m_data.begin(), t); | |
| 515 | 515 | } | |
| 516 | 516 | ||
| 517 | 517 | template <class T> | |
| 518 | 518 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 4> t) | |
| 519 | 519 | : base_type() | |
| 520 | 520 | { | |
| 521 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 521 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 522 | 522 | nested_copy(m_data.begin(), t); | |
| 523 | 523 | } | |
| 524 | 524 | ||
| 525 | 525 | template <class T> | |
| 526 | 526 | inline pyarray<T>::pyarray(nested_initializer_list_t<T, 5> t) | |
| 527 | 527 | : base_type() | |
| 528 | 528 | { | |
| 529 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 529 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 530 | 530 | nested_copy(m_data.begin(), t); | |
| 531 | 531 | } | |
| 532 | 532 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,11 +85,14 @@ namespace xt | |||
| 85 | 85 | static constexpr bool contiguous_layout = false; | |
| 86 | 86 | ||
| 87 | 87 | template <class S = shape_type> | |
| 88 | - void reshape(const S& shape); | ||
| 88 | + void resize(const S& shape); | ||
| 89 | 89 | template <class S = shape_type> | |
| 90 | - void reshape(const S& shape, layout_type l); | ||
| 90 | + void resize(const S& shape, layout_type l); | ||
| 91 | 91 | template <class S = shape_type> | |
| 92 | - void reshape(const S& shape, const strides_type& strides); | ||
| 92 | + void resize(const S& shape, const strides_type& strides); | ||
| 93 | + | ||
| 94 | + template <class S = shape_type> | ||
| 95 | + void reshape(S&& shape, layout_type layout = base_type::static_layout); | ||
| 93 | 96 | ||
| 94 | 97 | layout_type layout() const; | |
| 95 | 98 | ||
@@ -258,46 +261,79 @@ namespace xt | |||
| 258 | 261 | } | |
| 259 | 262 | ||
| 260 | 263 | /** | |
| 261 | - * Reshapes the container. | ||
| 264 | + * resizes the container. | ||
| 262 | 265 | * @param shape the new shape | |
| 263 | 266 | */ | |
| 264 | 267 | template <class D> | |
| 265 | 268 | template <class S> | |
| 266 | - inline void pycontainer<D>::reshape(const S& shape) | ||
| 269 | + inline void pycontainer<D>::resize(const S& shape) | ||
| 267 | 270 | { | |
| 268 | 271 | if (shape.size() != this->dimension() || !std::equal(std::begin(shape), std::end(shape), std::begin(this->shape()))) | |
| 269 | 272 | { | |
| 270 | - reshape(shape, layout_type::row_major); | ||
| 273 | + resize(shape, layout_type::row_major); | ||
| 271 | 274 | } | |
| 272 | 275 | } | |
| 273 | 276 | ||
| 274 | 277 | /** | |
| 275 | - * Reshapes the container. | ||
| 278 | + * resizes the container. | ||
| 276 | 279 | * @param shape the new shape | |
| 277 | 280 | * @param l the new layout | |
| 278 | 281 | */ | |
| 279 | 282 | template <class D> | |
| 280 | 283 | template <class S> | |
| 281 | - inline void pycontainer<D>::reshape(const S& shape, layout_type l) | ||
| 284 | + inline void pycontainer<D>::resize(const S& shape, layout_type l) | ||
| 282 | 285 | { | |
| 283 | 286 | strides_type strides = xtl::make_sequence<strides_type>(shape.size(), size_type(1)); | |
| 284 | 287 | compute_strides(shape, l, strides); | |
| 285 | - reshape(shape, strides); | ||
| 288 | + resize(shape, strides); | ||
| 286 | 289 | } | |
| 287 | 290 | ||
| 288 | 291 | /** | |
| 289 | - * Reshapes the container. | ||
| 292 | + * resizes the container. | ||
| 290 | 293 | * @param shape the new shape | |
| 291 | 294 | * @param strides the new strides | |
| 292 | 295 | */ | |
| 293 | 296 | template <class D> | |
| 294 | 297 | template <class S> | |
| 295 | - inline void pycontainer<D>::reshape(const S& shape, const strides_type& strides) | ||
| 298 | + inline void pycontainer<D>::resize(const S& shape, const strides_type& strides) | ||
| 296 | 299 | { | |
| 297 | 300 | derived_type tmp(xtl::forward_sequence<shape_type>(shape), strides); | |
| 298 | 301 | *static_cast<derived_type*>(this) = std::move(tmp); | |
| 299 | 302 | } | |
| 300 | 303 | ||
| 304 | + template <class D> | ||
| 305 | + template <class S> | ||
| 306 | + inline void pycontainer<D>::reshape(S&& shape, layout_type layout) | ||
| 307 | + { | ||
| 308 | + if (compute_size(shape) != this->size()) | ||
| 309 | + { | ||
| 310 | + throw std::runtime_error("Cannot reshape with incorrect number of elements."); | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + if (layout == layout_type::dynamic || layout == layout_type::any) | ||
| 314 | + { | ||
| 315 | + layout = DEFAULT_LAYOUT; | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + NPY_ORDER npy_layout; | ||
| 319 | + if (layout == layout_type::row_major) | ||
| 320 | + { | ||
| 321 | + npy_layout = NPY_CORDER; | ||
| 322 | + } | ||
| 323 | + else if (layout == layout_type::column_major) | ||
| 324 | + { | ||
| 325 | + npy_layout = NPY_FORTRANORDER; | ||
| 326 | + } | ||
| 327 | + else | ||
| 328 | + { | ||
| 329 | + throw std::runtime_error("Cannot reshape with unknown layout_type."); | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + std::vector<npy_intp> int_shape(shape.begin(), shape.end()); | ||
| 333 | + PyArray_Dims dims({int_shape.data(), static_cast<int>(shape.size())}); | ||
| 334 | + PyArray_Newshape((PyArrayObject*) this->ptr(), &dims, npy_layout); | ||
| 335 | + } | ||
| 336 | + | ||
| 301 | 337 | /** | |
| 302 | 338 | * Return the layout_type of the container | |
| 303 | 339 | * @return layout_type of the container | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -237,7 +237,7 @@ namespace xt | |||
| 237 | 237 | inline pytensor<T, N>::pytensor(nested_initializer_list_t<T, N> t) | |
| 238 | 238 | : base_type() | |
| 239 | 239 | { | |
| 240 | - base_type::reshape(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 240 | + base_type::resize(xt::shape<shape_type>(t), layout_type::row_major); | ||
| 241 | 241 | nested_copy(m_data.begin(), t); | |
| 242 | 242 | } | |
| 243 | 243 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments