-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclangmipy11.cpp
45 lines (42 loc) · 1.15 KB
/
clangmipy11.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import <iostream>;
import <string>;
import <memory>;
import <mutex>;
import <map>;
import <functional>;
#define module module__
#define import import__
#include <Python.h>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#undef module
#undef import
#include "Seg.hpp"
namespace py = pybind11;
struct Array_ptr {
Array<double> *ptr;
Array_ptr() : ptr(nullptr) {}
Array_ptr(Array<double> *a) : ptr(a) {}
~Array_ptr() {}
Array<double> *operator->() {
return ptr;
}
};
PYBIND11_MODULE(clangmi, m) {
py::class_<Array_ptr>(m, "Array", py::buffer_protocol())
.def_buffer([](Array_ptr& a) -> py::buffer_info {
return py::buffer_info(
a->begin(),
sizeof(double),
py::format_descriptor<double>::format(),
1,
{ a->size() },
{ sizeof(double) }
);
});
m.def("allocate_array", [](const std::string& seg_name, const std::string& mem_name,size_t size)->Array_ptr {
Seg seg(seg_name.c_str());
Array_ptr mem(seg.allocate_array<double>(mem_name.c_str(), size));
return std::move(mem);
});
}