Example #1
0
py::list print_recarray(py::array_t<S, 0> arr) {
    const auto req = arr.request();
    const auto ptr = static_cast<S*>(req.ptr);
    auto l = py::list();
    for (size_t i = 0; i < req.size; i++) {
        std::stringstream ss;
        ss << ptr[i];
        l.append(py::str(ss.str()));
    }
    return l;
}
Example #2
0
// Passing in an array of doubles
void twice(py::array_t<double> xs) {
    py::buffer_info info = xs.request();
    auto ptr = static_cast<double *>(info.ptr);

    printf("ndim = %d\n", info.ndim);
    printf("itemsize = %d\n", info.itemsize);
    printf("shape:\n");
    for(int i = 0; i < info.shape.size(); i++)
        printf("%d\n", info.shape[i]);
    printf("strides:\n");
    for(int i = 0; i < info.strides.size(); i++)
        printf("%d\n", info.strides[i]);



    int n = 1;
    for (auto r: info.shape) {
        n *= r;
    }

    for (int i = 0; i <n; i++) {
        *ptr++ *= 2;
    }
}