Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Binding array of arrays #24

Open
Open
Labels
@jpomoell

Description

@jpomoell

I'm attempting to bind axt::pyarray<xt::pyarray<double>> to a Numpy array of arrays, but I am getting compilation errors instantiating thepyarray. The error is a bit long to include here, the relevant bit is

pybind11/include/pybind11/numpy.h:260:81: error: no member named 'dtype' in 'pybind11::detail::npy_format_descriptor<xt::pyarray<double, 16>, void>'
return detail::npy_format_descriptor<typename std::remove_cv::type>::dtype();

coming from the call topybind11::dtype::of<T> in the return ofpyarray::raw_array_t. Unfortunately, I don't know enough about the inner workings ofpybind11 to determine if the problem lies there, or whether this is axtensor-python issue.

The problem I am trying to solve is to provide Python bindings to a code that usesxtensorxarray. Usingxt::xarray<xt::xarray<double>> in a C++-only situation works as expected. Actually, my case is limited in that I always have three inner arrays, so in C++ I would prefer to usestd::array<xt::xarray<double>, 3> (or perhapsxt::xtensor<xt::xarray<double>, 3>) but I do not know how to transparently (without copies) expose those as an ndarray of three ndarrays to Python.

Example code that produces the compilation error:

#include <numeric>#include "pybind11/pybind11.h"#include "xtensor/xarray.hpp"#include "xtensor/xmath.hpp"#include "xtensor-python/pyarray.hpp"double sum_of_dim(xt::pyarray<xt::pyarray<double>> & m, const int dim){    auto d = m(dim);     return std::accumulate(d.begin(), d.end(), 0.0);}PYBIND11_PLUGIN(example1_m){    pybind11::module m("example1_m", "Array of array test");    m.def("sum_of_dim", sum_of_dim, "Array of array function test");    return m.ptr();}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp