28 check.pybind11 = py::dtype::of<T>();
35 get_dtype_check<std::int8_t>(
"int8"),
36 get_dtype_check<std::uint8_t>(
"uint8"),
37 get_dtype_check<std::int16_t>(
"int16"),
38 get_dtype_check<std::uint16_t>(
"uint16"),
39 get_dtype_check<std::int32_t>(
"int32"),
40 get_dtype_check<std::uint32_t>(
"uint32"),
41 get_dtype_check<std::int64_t>(
"int64"),
42 get_dtype_check<std::uint64_t>(
"uint64")
57 check.
name = py::type_id<T>();
58 check.size_cpp =
sizeof(T);
59 check.dtype = py::dtype::of<T>();
60 check.size_numpy = check.dtype.attr(
"itemsize").template cast<int>();
66 get_dtype_size_check<short>(),
67 get_dtype_size_check<unsigned short>(),
68 get_dtype_size_check<int>(),
69 get_dtype_size_check<unsigned int>(),
70 get_dtype_size_check<long>(),
71 get_dtype_size_check<unsigned long>(),
72 get_dtype_size_check<long long>(),
73 get_dtype_size_check<unsigned long long>(),
82 template<
typename... Ix>
arr data(
const arr& a, Ix... index) {
93 ptr[
i] = (uint8_t) (ptr[
i] * 2);
111 #define def_index_fn(name, type) \ 112 sm.def(#name, [](type a) { return name(a); }); \ 113 sm.def(#name, [](type a, int i) { return name(a, i); }); \ 114 sm.def(#name, [](type a, int i, int j) { return name(a, i, j); }); \ 115 sm.def(#name, [](type a, int i, int j, int k) { return name(a, i, j, k); }); 118 if (r.ndim() != 2)
throw std::domain_error(
"error: ndim != 2");
120 l.append(*r.data(0, 0));
121 l.append(*r2.mutable_data(0, 0));
122 l.append(r.data(0, 1) == r2.mutable_data(0, 1));
124 l.append(r.itemsize());
125 l.append(r.shape(0));
126 l.append(r.shape(1));
128 l.append(r.nbytes());
136 try { py::module::import(
"numpy"); }
137 catch (...) {
return; }
144 return py::str(
"<DtypeCheck numpy={} pybind11={}>").format(
154 return py::str(
"<DtypeSizeCheck name='{}' size_cpp={} size_numpy={} dtype={}>").format(
155 self.name,
self.size_cpp,
self.size_numpy,
self.dtype);
160 sm.
def(
"ndim", [](
const arr& a) {
return a.
ndim(); });
166 sm.
def(
"size", [](
const arr& a) {
return a.
size(); });
168 sm.
def(
"nbytes", [](
const arr& a) {
return a.
nbytes(); });
207 int data[2] = { 1, 2 };
208 ArrayClass() {
py::print(
"ArrayClass()"); }
209 ~ArrayClass() {
py::print(
"~ArrayClass()"); }
215 ArrayClass &a = obj.
cast<ArrayClass&>();
221 sm.
def(
"function_taking_uint64", [](uint64_t) { });
225 return py::isinstance<py::array>(yes) && !py::isinstance<py::array>(no);
232 sm.
def(
"default_constructors", []() {
253 sm.
def(
"overloaded", [](
py::array_t<std::complex<double>>) {
return "double complex"; });
254 sm.
def(
"overloaded", [](
py::array_t<std::complex<float>>) {
return "float complex"; });
256 sm.
def(
"overloaded2", [](
py::array_t<std::complex<double>>) {
return "double complex"; });
258 sm.
def(
"overloaded2", [](
py::array_t<std::complex<float>>) {
return "float complex"; });
277 sm.
def(
"issue685", [](std::string) {
return "string"; });
285 for (
ssize_t j = 0; j < r.shape(1); j++)
289 sm.
def(
"proxy_init3", [](
double start) {
295 r(
i, j, k) = start++;
298 sm.
def(
"proxy_init3F", [](
double start) {
304 r(
i, j, k) = start++;
311 sumsq += r[
i] * r(
i);
325 if (r.ndim() != 2)
throw std::domain_error(
"error: ndim != 2");
327 for (
ssize_t j = 0; j < r.shape(1); j++)
330 sm.
def(
"proxy_init3_dyn", [](
double start) {
333 if (r.
ndim() != 3)
throw std::domain_error(
"error: ndim != 3");
337 r(
i, j, k) = start++;
353 sm.
def(
"array_fail_test_negative_size", []() {
int c = 0;
return py::array(-1, &c); });
366 if (dim_sz * dim_sz != a.
size())
367 throw std::domain_error(
"array_reshape2: input array total size is not a squared integer");
368 a.
resize({dim_sz, dim_sz});
373 a.
resize({N, N, N}, refcheck);
378 sm.
def(
"create_and_resize", [](
size_t N) {
385 #if PY_MAJOR_VERSION >= 3 void * mutable_data(Ix... index)
test_initializer numpy_array("numpy_array", test_submodule_numpy_array)
ssize_t index_at(Ix... index) const
DtypeSizeCheck get_dtype_size_check()
const ssize_t * strides() const
Strides of the array.
glibc defines I as a macro which breaks things, e.g., boost template names
arr_t & mutate_at_t(arr_t &a, Ix... idx)
arr_t & mutate_data_t(arr_t &a, Ix... index)
ssize_t offset_at_t(const arr_t &a, Ix... idx)
ssize_t itemsize() const
Byte size of a single element.
ssize_t offset_at(const arr &a, Ix... idx)
pybind11::dtype dtype() const
Array descriptor (dtype)
arr data(const arr &a, Ix... index)
ssize_t offset_at(Ix... index) const
Wrapper for Python extension modules.
bool Dims mutable_unchecked() &
obj_attr_accessor attr(handle key) const
ssize_t nbytes() const
Total number of bytes.
const void * data(Ix... index) const
void resize(ShapeContainer new_shape, bool refcheck=true)
py::handle auxiliaries(T &&r, T2 &&r2)
return isinstance(obj, type)
ssize_t ndim() const
Number of dimensions.
ssize_t index_at(const arr &a, Ix... idx)
#define def_index_fn(name, type)
std::vector< DtypeCheck > get_concrete_dtype_checks()
arr & mutate_data(arr &a, Ix... index)
ssize_t index_at_t(const arr_t &a, Ix... idx)
ssize_t at_t(const arr_t &a, Ix... idx)
detail::unchecked_reference< T, Dims > unchecked() const &
std::vector< DtypeSizeCheck > get_platform_dtype_size_checks()
arg & noconvert(bool flag=true)
Indicate that the type should not be converted in the type caster.
bool writeable() const
If set, the array is writeable (otherwise the buffer is read-only)
class_ & def_readonly(const char *name, const D C::*pm, const Extra &...extra)
const ssize_t * shape() const
Dimensions of the array.
void print(Args &&...args)
#define TEST_SUBMODULE(name, variable)
ssize_t size() const
Total number of elements.
bool typename Extra class_ & def(const char *name_, Func &&f, const Extra &... extra)
DtypeCheck get_dtype_check(const char *name)
arr data_t(const arr_t &a, Ix... index)
bool owndata() const
If set, the array owns the data (will be freed when the array is deleted)