Skip to content

Commit b571c37

Browse files
committed
test updated
1 parent 9a538ca commit b571c37

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

tests/test_numpy_array.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <cstdint>
1616
#include <vector>
1717

18-
using arr = py::array;
18+
using arr = py::array<>;
1919
using arr_t = py::array_t<uint16_t, 0>;
2020

2121
template<typename... Ix> arr data(const arr& a, Ix... index) {
@@ -100,8 +100,8 @@ test_initializer numpy_array([](py::module &m) {
100100
return py::array_t<float>({ 2, 2 }, { 8, 4 });
101101
});
102102

103-
sm.def("wrap", [](py::array a) {
104-
return py::array(
103+
sm.def("wrap", [](py::array<> a) {
104+
return py::array<>(
105105
a.dtype(),
106106
std::vector<size_t>(a.shape(), a.shape() + a.ndim()),
107107
std::vector<size_t>(a.strides(), a.strides() + a.ndim()),
@@ -128,7 +128,7 @@ test_initializer numpy_array([](py::module &m) {
128128
sm.def("function_taking_uint64", [](uint64_t) { });
129129

130130
sm.def("isinstance_untyped", [](py::object yes, py::object no) {
131-
return py::isinstance<py::array>(yes) && !py::isinstance<py::array>(no);
131+
return py::isinstance<py::array<>>(yes) && !py::isinstance<py::array<>>(no);
132132
});
133133

134134
sm.def("isinstance_typed", [](py::object o) {
@@ -137,15 +137,15 @@ test_initializer numpy_array([](py::module &m) {
137137

138138
sm.def("default_constructors", []() {
139139
return py::dict(
140-
"array"_a=py::array(),
140+
"array"_a=py::array<>(),
141141
"array_t<int32>"_a=py::array_t<std::int32_t>(),
142142
"array_t<double>"_a=py::array_t<double>()
143143
);
144144
});
145145

146146
sm.def("converting_constructors", [](py::object o) {
147147
return py::dict(
148-
"array"_a=py::array(o),
148+
"array"_a=py::array<>(o),
149149
"array_t<int32>"_a=py::array_t<std::int32_t>(o),
150150
"array_t<double>"_a=py::array_t<double>(o)
151151
);

tests/test_numpy_dtypes.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ std::ostream& operator<<(std::ostream& os, const EnumStruct& v) {
9393
}
9494

9595
template <typename T>
96-
py::array mkarray_via_buffer(size_t n) {
97-
return py::array(py::buffer_info(nullptr, sizeof(T),
98-
py::format_descriptor<T>::format(),
99-
1, { n }, { sizeof(T) }));
96+
py::array<> mkarray_via_buffer(size_t n) {
97+
return py::array<>(py::buffer_info(nullptr, sizeof(T),
98+
py::format_descriptor<T>::format(),
99+
1, { n }, { sizeof(T) }));
100100
}
101101

102102
template <typename S>
@@ -228,7 +228,7 @@ py::array_t<int32_t, 0> test_array_ctors(int i) {
228228
py::buffer_info buf_ndim2(vptr, 4, "i", 2, shape, strides);
229229
py::buffer_info buf_ndim2_null(nullptr, 4, "i", 2, shape, strides);
230230

231-
auto fill = [](py::array arr) {
231+
auto fill = [](py::array<> arr) {
232232
auto req = arr.request();
233233
for (int i = 0; i < 6; i++) ((int32_t *) req.ptr)[i] = i + 1;
234234
return arr;
@@ -237,34 +237,34 @@ py::array_t<int32_t, 0> test_array_ctors(int i) {
237237
switch (i) {
238238
// shape: (3, 2)
239239
case 10: return arr_t(shape, strides, ptr);
240-
case 11: return py::array(shape, strides, ptr);
241-
case 12: return py::array(dtype, shape, strides, vptr);
240+
case 11: return py::array<>(shape, strides, ptr);
241+
case 12: return py::array<>(dtype, shape, strides, vptr);
242242
case 13: return arr_t(shape, ptr);
243-
case 14: return py::array(shape, ptr);
244-
case 15: return py::array(dtype, shape, vptr);
243+
case 14: return py::array<>(shape, ptr);
244+
case 15: return py::array<>(dtype, shape, vptr);
245245
case 16: return arr_t(buf_ndim2);
246-
case 17: return py::array(buf_ndim2);
246+
case 17: return py::array<>(buf_ndim2);
247247
// shape: (3, 2) - post-fill
248248
case 20: return fill(arr_t(shape, strides));
249-
case 21: return py::array(shape, strides, ptr); // can't have nullptr due to templated ctor
250-
case 22: return fill(py::array(dtype, shape, strides));
249+
case 21: return py::array<>(shape, strides, ptr); // can't have nullptr due to templated ctor
250+
case 22: return fill(py::array<>(dtype, shape, strides));
251251
case 23: return fill(arr_t(shape));
252-
case 24: return py::array(shape, ptr); // can't have nullptr due to templated ctor
253-
case 25: return fill(py::array(dtype, shape));
252+
case 24: return py::array<>(shape, ptr); // can't have nullptr due to templated ctor
253+
case 25: return fill(py::array<>(dtype, shape));
254254
case 26: return fill(arr_t(buf_ndim2_null));
255-
case 27: return fill(py::array(buf_ndim2_null));
255+
case 27: return fill(py::array<>(buf_ndim2_null));
256256
// shape: (6, )
257257
case 30: return arr_t(6, ptr);
258-
case 31: return py::array(6, ptr);
259-
case 32: return py::array(dtype, 6, vptr);
258+
case 31: return py::array<>(6, ptr);
259+
case 32: return py::array<>(dtype, 6, vptr);
260260
case 33: return arr_t(buf_ndim1);
261-
case 34: return py::array(buf_ndim1);
261+
case 34: return py::array<>(buf_ndim1);
262262
// shape: (6, )
263263
case 40: return fill(arr_t(6));
264-
case 41: return py::array(6, ptr); // can't have nullptr due to templated ctor
265-
case 42: return fill(py::array(dtype, 6));
264+
case 41: return py::array<>(6, ptr); // can't have nullptr due to templated ctor
265+
case 42: return fill(py::array<>(dtype, 6));
266266
case 43: return fill(arr_t(buf_ndim1_null));
267-
case 44: return fill(py::array(buf_ndim1_null));
267+
case 44: return fill(py::array<>(buf_ndim1_null));
268268
}
269269
return arr_t();
270270
}

tests/test_numpy_vectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_initializer numpy_vectorize([](py::module &m) {
3535
m.def("vectorized_func3", py::vectorize(my_func3));
3636

3737
/// Numpy function which only accepts specific data types
38-
m.def("selective_func", [](py::array_t<int, py::array::c_style>) { return "Int branch taken."; });
39-
m.def("selective_func", [](py::array_t<float, py::array::c_style>) { return "Float branch taken."; });
40-
m.def("selective_func", [](py::array_t<std::complex<float>, py::array::c_style>) { return "Complex float branch taken."; });
38+
m.def("selective_func", [](py::array_t<int, py::array<>::c_style>) { return "Int branch taken."; });
39+
m.def("selective_func", [](py::array_t<float, py::array<>::c_style>) { return "Float branch taken."; });
40+
m.def("selective_func", [](py::array_t<std::complex<float>, py::array<>::c_style>) { return "Complex float branch taken."; });
4141
});

0 commit comments

Comments
 (0)