| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 511b937 commit 6c0ef26
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ install: | |||
| 22 | 22 | - conda update -q conda | |
| 23 | 23 | - conda info -a | |
| 24 | 24 | - conda install gtest cmake -c conda-forge | |
| 25 | - - conda install pytest numpy pybind11==2.2.4 xtensor==0.20.8 -c conda-forge | ||
| 25 | + - conda install pytest numpy pybind11==2.4.2 xtensor==0.20.8 -c conda-forge | ||
| 26 | 26 | - "set PYTHONHOME=%MINICONDA%" | |
| 27 | 27 | - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe . | |
| 28 | 28 | - nmake test_xtensor_python | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,6 +124,35 @@ namespace xt | |||
| 124 | 124 | ||
| 125 | 125 | PyArrayObject* python_array() const; | |
| 126 | 126 | size_type get_buffer_size() const; | |
| 127 | + | ||
| 128 | + private: | ||
| 129 | + | ||
| 130 | + #if PYBIND11_VERSION_MAJOR == 2 && PYBIND11_VERSION_MINOR >= 3 | ||
| 131 | + // Prevent ambiguous overload resolution for operators defined for | ||
| 132 | + // both xt::xcontainer and pybind11::object. | ||
| 133 | + using pybind11::object::operator~; | ||
| 134 | + using pybind11::object::operator+; | ||
| 135 | + using pybind11::object::operator-; | ||
| 136 | + using pybind11::object::operator*; | ||
| 137 | + using pybind11::object::operator/; | ||
| 138 | + using pybind11::object::operator|; | ||
| 139 | + using pybind11::object::operator&; | ||
| 140 | + using pybind11::object::operator^; | ||
| 141 | + using pybind11::object::operator<<; | ||
| 142 | + using pybind11::object::operator>>; | ||
| 143 | + | ||
| 144 | + // Prevent ambiguous overload resolution for operators defined for | ||
| 145 | + // both xt::xcontainer_semantic and pybind11::object. | ||
| 146 | + using pybind11::object::operator+=; | ||
| 147 | + using pybind11::object::operator-=; | ||
| 148 | + using pybind11::object::operator*=; | ||
| 149 | + using pybind11::object::operator/=; | ||
| 150 | + using pybind11::object::operator|=; | ||
| 151 | + using pybind11::object::operator&=; | ||
| 152 | + using pybind11::object::operator^=; | ||
| 153 | + using pybind11::object::operator<<=; | ||
| 154 | + using pybind11::object::operator>>=; | ||
| 155 | + #endif | ||
| 127 | 156 | }; | |
| 128 | 157 | ||
| 129 | 158 | namespace detail | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -240,4 +240,26 @@ namespace xt | |||
| 240 | 240 | auto v = xt::view(arr, xt::all()); | |
| 241 | 241 | EXPECT_EQ(v(0), 0.); | |
| 242 | 242 | } | |
| 243 | + | ||
| 244 | + TEST(pytensor, unary) | ||
| 245 | + { | ||
| 246 | + pytensor<int, 1> a = { 1, 2, 3 }; | ||
| 247 | + pytensor<int, 1> res = -a; | ||
| 248 | + pytensor<int, 1> ref = { -1, -2, -3 }; | ||
| 249 | + EXPECT_EQ(ref(0), res(0)); | ||
| 250 | + EXPECT_EQ(ref(1), res(1)); | ||
| 251 | + EXPECT_EQ(ref(1), res(1)); | ||
| 252 | + } | ||
| 253 | + | ||
| 254 | + TEST(pytensor, inplace_pybind11_overload) | ||
| 255 | + { | ||
| 256 | + // pybind11 overrrides a number of operators in pybind11::object. | ||
| 257 | + // This is testing that the right overload is picked up. | ||
| 258 | + pytensor<double, 1> a = { 1.0, 2.0, 3.0 }; | ||
| 259 | + a /= 2; | ||
| 260 | + pytensor<double, 1> ref = { 0.5, 1.0, 1.5 }; | ||
| 261 | + EXPECT_EQ(ref(0), a(0)); | ||
| 262 | + EXPECT_EQ(ref(1), a(1)); | ||
| 263 | + EXPECT_EQ(ref(1), a(1)); | ||
| 264 | + } | ||
| 243 | 265 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments