| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6d62f0f commit c72ec9b
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ install: | |||
| 24 | 24 | - conda info -a | |
| 25 | 25 | - conda install pytest -c conda-forge | |
| 26 | 26 | - cd test | |
| 27 | - - conda install xtensor==0.5.0 pytest numpy pybind11==2.0.1 -c conda-forge | ||
| 27 | + - conda install xtensor==0.6.0 pytest numpy pybind11==2.0.1 -c conda-forge | ||
| 28 | 28 | - xcopy /S %APPVEYOR_BUILD_FOLDER%\include %MINICONDA%\include | |
| 29 | 29 | ||
| 30 | 30 | build_script: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,7 +59,7 @@ install: | |||
| 59 | 59 | # Useful for debugging any issues with conda | |
| 60 | 60 | - conda info -a | |
| 61 | 61 | - cd test | |
| 62 | - - conda install xtensor==0.5.0 pytest numpy pybind11==2.0.1 -c conda-forge | ||
| 62 | + - conda install xtensor==0.6.0 pytest numpy pybind11==2.0.1 -c conda-forge | ||
| 63 | 63 | - cp -r $TRAVIS_BUILD_DIR/include/* $HOME/miniconda/include/ | |
| 64 | 64 | ||
| 65 | 65 | script: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,8 @@ conda install -c conda-forge xtensor-python | |||
| 29 | 29 | ||
| 30 | 30 | | `xtensor-python` | `xtensor` | `pybind11` | | |
| 31 | 31 | |-------------------|------------|-------------| | |
| 32 | - | master | 0.5.0 | ^2.0.0 | | ||
| 32 | + | master | 0.6.0 | ^2.0.0 | | ||
| 33 | + | 0.5.0 | 0.5.0 | ^2.0.0 | | ||
| 33 | 34 | | 0.4.0 | 0.5.0 | ^2.0.0 | | |
| 34 | 35 | | 0.3.0 | ^0.4.1 | ^2.0.0 | | |
| 35 | 36 | | 0.2.0 | ^0.2.1 | ^1.8.1 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,7 @@ namespace xt | |||
| 108 | 108 | using semantic_base = xcontainer_semantic<self_type>; | |
| 109 | 109 | using base_type = pycontainer<self_type>; | |
| 110 | 110 | using container_type = typename base_type::container_type; | |
| 111 | + using value_type = typename base_type::value_type; | ||
| 111 | 112 | using pointer = typename base_type::pointer; | |
| 112 | 113 | using size_type = typename base_type::size_type; | |
| 113 | 114 | using shape_type = typename base_type::shape_type; | |
@@ -117,6 +118,12 @@ namespace xt | |||
| 117 | 118 | using inner_strides_type = typename base_type::inner_strides_type; | |
| 118 | 119 | ||
| 119 | 120 | pyarray() = default; | |
| 121 | + pyarray(const value_type& t); | ||
| 122 | + pyarray(nested_initializer_list_t<T, 1> t); | ||
| 123 | + pyarray(nested_initializer_list_t<T, 2> t); | ||
| 124 | + pyarray(nested_initializer_list_t<T, 3> t); | ||
| 125 | + pyarray(nested_initializer_list_t<T, 4> t); | ||
| 126 | + pyarray(nested_initializer_list_t<T, 5> t); | ||
| 120 | 127 | ||
| 121 | 128 | pyarray(pybind11::handle h, pybind11::object::borrowed_t); | |
| 122 | 129 | pyarray(pybind11::handle h, pybind11::object::stolen_t); | |
@@ -179,6 +186,48 @@ namespace xt | |||
| 179 | 186 | * pyarray implementation * | |
| 180 | 187 | **************************/ | |
| 181 | 188 | ||
| 189 | + template <class T> | ||
| 190 | + inline pyarray<T>::pyarray(const value_type& t) | ||
| 191 | + { | ||
| 192 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 193 | + nested_copy(m_data.begin(), t); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + template <class T> | ||
| 197 | + inline pyarray<T>::pyarray(nested_initializer_list_t<T, 1> t) | ||
| 198 | + { | ||
| 199 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 200 | + nested_copy(m_data.begin(), t); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + template <class T> | ||
| 204 | + inline pyarray<T>::pyarray(nested_initializer_list_t<T, 2> t) | ||
| 205 | + { | ||
| 206 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 207 | + nested_copy(m_data.begin(), t); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + template <class T> | ||
| 211 | + inline pyarray<T>::pyarray(nested_initializer_list_t<T, 3> t) | ||
| 212 | + { | ||
| 213 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 214 | + nested_copy(m_data.begin(), t); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + template <class T> | ||
| 218 | + inline pyarray<T>::pyarray(nested_initializer_list_t<T, 4> t) | ||
| 219 | + { | ||
| 220 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 221 | + nested_copy(m_data.begin(), t); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + template <class T> | ||
| 225 | + inline pyarray<T>::pyarray(nested_initializer_list_t<T, 5> t) | ||
| 226 | + { | ||
| 227 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 228 | + nested_copy(m_data.begin(), t); | ||
| 229 | + } | ||
| 230 | + | ||
| 182 | 231 | template <class T> | |
| 183 | 232 | inline pyarray<T>::pyarray(pybind11::handle h, pybind11::object::borrowed_t) | |
| 184 | 233 | : base_type(h, pybind11::object::borrowed) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ | |||
| 12 | 12 | #include <cstddef> | |
| 13 | 13 | #include <array> | |
| 14 | 14 | #include <algorithm> | |
| 15 | + #include "xtensor/xutils.hpp" | ||
| 15 | 16 | #include "xtensor/xsemantic.hpp" | |
| 16 | 17 | #include "xtensor/xiterator.hpp" | |
| 17 | 18 | ||
@@ -83,6 +84,7 @@ namespace xt | |||
| 83 | 84 | using semantic_base = xcontainer_semantic<self_type>; | |
| 84 | 85 | using base_type = pycontainer<self_type>; | |
| 85 | 86 | using container_type = typename base_type::container_type; | |
| 87 | + using value_type = typename base_type::value_type; | ||
| 86 | 88 | using pointer = typename base_type::pointer; | |
| 87 | 89 | using size_type = typename base_type::size_type; | |
| 88 | 90 | using shape_type = typename base_type::shape_type; | |
@@ -92,7 +94,7 @@ namespace xt | |||
| 92 | 94 | using inner_strides_type = typename base_type::inner_strides_type; | |
| 93 | 95 | ||
| 94 | 96 | pytensor() = default; | |
| 95 | - | ||
| 97 | + pytensor(nested_initializer_list_t<T, N> t); | ||
| 96 | 98 | pytensor(pybind11::handle h, pybind11::object::borrowed_t); | |
| 97 | 99 | pytensor(pybind11::handle h, pybind11::object::stolen_t); | |
| 98 | 100 | pytensor(const pybind11::object &o); | |
@@ -137,6 +139,13 @@ namespace xt | |||
| 137 | 139 | * pytensor implementation * | |
| 138 | 140 | ***************************/ | |
| 139 | 141 | ||
| 142 | + template <class T, std::size_t N> | ||
| 143 | + inline pytensor<T, N>::pytensor(nested_initializer_list_t<T, N> t) | ||
| 144 | + { | ||
| 145 | + base_type::reshape(xt::shape<shape_type>(t), layout::row_major); | ||
| 146 | + nested_copy(m_data.begin(), t); | ||
| 147 | + } | ||
| 148 | + | ||
| 140 | 149 | template <class T, std::size_t N> | |
| 141 | 150 | inline pytensor<T, N>::pytensor(pybind11::handle h, pybind11::object::borrowed_t) | |
| 142 | 151 | : base_type(h, pybind11::object::borrowed) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,19 +11,19 @@ using complex_t = std::complex<double>; | |||
| 11 | 11 | ||
| 12 | 12 | // Examples | |
| 13 | 13 | ||
| 14 | - double example1(xt::pyarray<double> &m) | ||
| 14 | + double example1(xt::pyarray<double>& m) | ||
| 15 | 15 | { | |
| 16 | 16 | return m(0); | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | - xt::pyarray<double> example2(xt::pyarray<double> &m) | ||
| 19 | + xt::pyarray<double> example2(xt::pyarray<double>& m) | ||
| 20 | 20 | { | |
| 21 | 21 | return m + 2; | |
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | // Readme Examples | |
| 25 | 25 | ||
| 26 | - double readme_example1(xt::pyarray<double> &m) | ||
| 26 | + double readme_example1(xt::pyarray<double>& m) | ||
| 27 | 27 | { | |
| 28 | 28 | auto sines = xt::sin(m); | |
| 29 | 29 | return std::accumulate(sines.begin(), sines.end(), 0.0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,32 +16,27 @@ | |||
| 16 | 16 | class ExampleTest(TestCase): | |
| 17 | 17 | ||
| 18 | 18 | def test_example1(self): | |
| 19 | - print("test1") | ||
| 20 | 19 | self.assertEqual(4, xt.example1([4, 5, 6])) | |
| 21 | 20 | ||
| 22 | 21 | def test_example2(self): | |
| 23 | - print("test2") | ||
| 24 | 22 | x = np.array([[0., 1.], [2., 3.]]) | |
| 25 | 23 | res = np.array([[2., 3.], [4., 5.]]) | |
| 26 | 24 | y = xt.example2(x) | |
| 27 | 25 | np.testing.assert_allclose(y, res, 1e-12) | |
| 28 | 26 | ||
| 29 | 27 | def test_vectorize(self): | |
| 30 | - print("test3") | ||
| 31 | 28 | x1 = np.array([[0, 1], [2, 3]]) | |
| 32 | 29 | x2 = np.array([0, 1]) | |
| 33 | 30 | res = np.array([[0, 2], [2, 4]]) | |
| 34 | 31 | y = xt.vectorize_example1(x1, x2) | |
| 35 | 32 | np.testing.assert_array_equal(y, res) | |
| 36 | 33 | ||
| 37 | 34 | def test_readme_example1(self): | |
| 38 | - print("test4") | ||
| 39 | 35 | v = np.arange(15).reshape(3, 5) | |
| 40 | 36 | y = xt.readme_example1(v) | |
| 41 | 37 | np.testing.assert_allclose(y, 1.2853996391883833, 1e-12) | |
| 42 | 38 | ||
| 43 | 39 | def test_readme_example2(self): | |
| 44 | - print("test5") | ||
| 45 | 40 | x = np.arange(15).reshape(3, 5) | |
| 46 | 41 | y = [1, 2, 3, 4, 5] | |
| 47 | 42 | z = xt.readme_example2(x, y) | |
@@ -51,7 +46,6 @@ def test_readme_example2(self): | |||
| 51 | 46 | [-1.084323, -0.583843, 0.45342 , 1.073811, 0.706945]], 1e-5) | |
| 52 | 47 | ||
| 53 | 48 | def test_rect_to_polar(self): | |
| 54 | - print("test6") | ||
| 55 | 49 | x = np.ones(10, dtype=complex) | |
| 56 | 50 | z = xt.rect_to_polar(x[::2]); | |
| 57 | 51 | np.testing.assert_allclose(z, (np.ones(5, dtype=float), np.zeros(5, dtype=float)), 1e-5) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments