Add explicit test for recarray format descriptors

This commit is contained in:
Ivan Smirnov 2016-06-19 16:54:07 +01:00
parent 7f913aecab
commit bdc9902041
3 changed files with 15 additions and 1 deletions

View File

@ -57,7 +57,13 @@ py::array_t<NestedStruct> create_nested(size_t n) {
ptr[i].b.x = (i + 1) % 2; ptr[i].b.y = (uint32_t) (i + 1); ptr[i].b.z = (float) (i + 1) * 1.5f;
}
return arr;
}
void print_format_descriptors() {
std::cout << py::format_descriptor<Struct>::value() << std::endl;
std::cout << py::format_descriptor<PackedStruct>::value() << std::endl;
std::cout << py::format_descriptor<NestedStruct>::value() << std::endl;
}
void init_ex20(py::module &m) {
@ -68,4 +74,5 @@ void init_ex20(py::module &m) {
m.def("create_rec_simple", &create_recarray<Struct>);
m.def("create_rec_packed", &create_recarray<PackedStruct>);
m.def("create_rec_nested", &create_nested);
m.def("print_format_descriptors", &print_format_descriptors);
}

View File

@ -2,12 +2,16 @@
from __future__ import print_function
import numpy as np
from example import create_rec_simple, create_rec_packed, create_rec_nested
from example import (
create_rec_simple, create_rec_packed, create_rec_nested, print_format_descriptors
)
def check_eq(arr, data, dtype):
np.testing.assert_equal(arr, np.array(data, dtype=dtype))
print_format_descriptors()
simple_dtype = np.dtype({'names': ['x', 'y', 'z'],
'formats': ['?', 'u4', 'f4'],
'offsets': [0, 4, 8]})

View File

@ -0,0 +1,3 @@
T{?:x:xxxI:y:f:z:}
T{?:x:=I:y:f:z:}
T{T{?:x:xxxI:y:f:z:}:a:T{?:x:=I:y:f:z:}:b:}