| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d2e19bb commit a7f9f73
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,15 +28,14 @@ conda install -c conda-forge xtensor-python | |||
| 28 | 28 | ||
| 29 | 29 | xtensor-python offers two container types wrapping numpy arrays inplace to provide an xtensor semantics | |
| 30 | 30 | ||
| 31 | - - ``pytensor`` | ||
| 32 | - - ``pyarray``. | ||
| 31 | + - `pytensor` | ||
| 32 | + - `pyarray`. | ||
| 33 | 33 | ||
| 34 | 34 | Both containers enable the numpy-style APIs of xtensor (see [the numpy to xtensor cheat sheet](http://xtensor.readthedocs.io/en/latest/numpy.html)). | |
| 35 | 35 | ||
| 36 | - - On the one hand, ``pyarray`` has a dynamic number of dimensions. Just like numpy arrays, it can be reshaped with a shape of a different length (and the new shape is reflected on the python side). | ||
| 36 | + - On the one hand, `pyarray` has a dynamic number of dimensions. Just like numpy arrays, it can be reshaped with a shape of a different length (and the new shape is reflected on the python side). | ||
| 37 | 37 | ||
| 38 | - - On the other hand ``pytensor`` has a compile time number of dimensions, specified with a template parameter. Shapes of ``pytensor`` instances are stack allocated, making ``pytensor`` a significantly | ||
| 39 | - faster expression than ``pyarray``. | ||
| 38 | + - On the other hand `pytensor` has a compile time number of dimensions, specified with a template parameter. Shapes of `pytensor` instances are stack allocated, making `pytensor` a significantly faster expression than `pyarray`. | ||
| 40 | 39 | ||
| 41 | 40 | ### Example 1: Use an algorithm of the C++ standard library on a numpy array inplace. | |
| 42 | 41 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -397,7 +397,7 @@ namespace xt | |||
| 397 | 397 | ||
| 398 | 398 | this->m_ptr = tmp.release().ptr(); | |
| 399 | 399 | init_from_python(); | |
| 400 | - std::copy(rhs.data().begin(), rhs.data().end(), this->data().begin()); | ||
| 400 | + std::copy(rhs.data().cbegin(), rhs.data().cend(), this->data().begin()); | ||
| 401 | 401 | } | |
| 402 | 402 | ||
| 403 | 403 | /** | |
@@ -425,6 +425,7 @@ namespace xt | |||
| 425 | 425 | inline pyarray<T>::pyarray(const xexpression<E>& e) | |
| 426 | 426 | : base_type() | |
| 427 | 427 | { | |
| 428 | + // TODO: prevent intermediary shape allocation | ||
| 428 | 429 | shape_type shape = forward_sequence<shape_type>(e.derived_cast().shape()); | |
| 429 | 430 | strides_type strides = make_sequence<strides_type>(shape.size(), size_type(0)); | |
| 430 | 431 | compute_strides(shape, layout_type::row_major, strides); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -306,7 +306,7 @@ namespace xt | |||
| 306 | 306 | : base_type() | |
| 307 | 307 | { | |
| 308 | 308 | init_tensor(rhs.shape(), rhs.strides()); | |
| 309 | - std::copy(rhs.data().begin(), rhs.data().end(), this->data().begin()); | ||
| 309 | + std::copy(rhs.data().cbegin(), rhs.data().cend(), this->data().begin()); | ||
| 310 | 310 | } | |
| 311 | 311 | ||
| 312 | 312 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,8 @@ | |||
| 9 | 9 | #ifndef PY_VECTORIZE_HPP | |
| 10 | 10 | #define PY_VECTORIZE_HPP | |
| 11 | 11 | ||
| 12 | + #include <type_traits> | ||
| 13 | + | ||
| 12 | 14 | #include "pyarray.hpp" | |
| 13 | 15 | #include "xtensor/xvectorize.hpp" | |
| 14 | 16 | ||
@@ -20,13 +22,13 @@ namespace xt | |||
| 20 | 22 | { | |
| 21 | 23 | xvectorizer<Func, R> m_vectorizer; | |
| 22 | 24 | ||
| 23 | - template <class F> | ||
| 25 | + template <class F, class = std::enable_if_t<!std::is_same<std::decay_t<F>, pyvectorizer>::value>> | ||
| 24 | 26 | pyvectorizer(F&& func) | |
| 25 | 27 | : m_vectorizer(std::forward<F>(func)) | |
| 26 | 28 | { | |
| 27 | 29 | } | |
| 28 | 30 | ||
| 29 | - inline pyarray<R> operator()(const pyarray<Args>&... args) | ||
| 31 | + inline pyarray<R> operator()(const pyarray<Args>&... args) const | ||
| 30 | 32 | { | |
| 31 | 33 | pyarray<R> res = m_vectorizer(args...); | |
| 32 | 34 | return res; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments