1py::class_<Shape>
PyShape(m,
"Shape", py::dynamic_attr());
3PyShape.def(py::init<std::vector<std::size_t>>()).def(py::init<std::size_t>());
5py::class_<DataSet>
PyDataSet(m,
"DataSet", py::dynamic_attr());
11 [](DataSet& self,
const std::string& key, py::tuple pyTuple,
const std::string& dtype,
const std::string& doc) {
12 std::vector<std::size_t> shape;
13 shape.reserve(pyTuple.size());
14 for (
size_t i = 0; i < pyTuple.size(); ++i) {
15 int value = pyTuple[i].cast<
int>();
16 shape.push_back(
value);
19 self._def_int(key, Shape{shape}, doc);
20 }
else if (dtype ==
"real") {
21 self._def_real(key, Shape{shape}, doc);
22 }
else if (dtype ==
"complex") {
23 self._def_complex(key, Shape{shape}, doc);
28 py::arg(
"key"), py::arg(
"shape"), py::arg(
"dtype") =
"int", py::arg(
"doc") =
"");
30PyDataSet.def(
"_undef", &DataSet::_undef, py::arg(
"key") =
"0");
32PyDataSet.def(
"numpy", [](DataSet& self,
const std::string& key) {
33 auto inode = self.node(key);
34 kids_dtype n_type = inode->type();
37 std::size_t n_size =
static_cast<Tensor<kids_int>*
>(inode)->size();
38 void* n_data =
static_cast<Tensor<kids_int>*
>(inode)->data();
39 return py::array({n_size},
42 py::capsule(n_data, [](
void* _void_n_data) { ; })
46 case kids_real_type: {
47 std::size_t n_size =
static_cast<Tensor<kids_real>*
>(inode)->size();
48 void* n_data =
static_cast<Tensor<kids_real>*
>(inode)->data();
49 return py::array({n_size},
52 py::capsule(n_data, [](
void* _void_n_data) { ; })
56 case kids_complex_type: {
57 std::size_t n_size =
static_cast<Tensor<kids_complex>*
>(inode)->size();
58 void* n_data =
static_cast<Tensor<kids_complex>*
>(inode)->data();
59 return py::array({n_size},
60 {
sizeof(kids_complex)},
61 (kids_complex*) n_data,
62 py::capsule(n_data, [](
void* _void_n_data) { ; })
67 throw std::runtime_error(
"can not converted to numpy!");
73 "help", [](DataSet& self,
const std::string& name) {
return self.help(name); }, py::arg(
"name") =
"");
75PyDataSet.def(
"__repr__", [](DataSet& self) {
return self.repr(); });
py::class_< Shape > PyShape(m, "Shape", py::dynamic_attr())
PyShape def(py::init< std::vector< std::size_t > >()).def(py py::class_< DataSet > PyDataSet(m, "DataSet", py::dynamic_attr())
Param::LoadOption::fromString value("fromFile", Param::LoadOption::fromFile) .export_values()