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

Appearance settings

support for noconvert #73

Copy link
Copy link
@nbecker

Description

@nbecker
Issue body actions

It seems noconvert is not supported? I tried adding noconvert to my (now classic) summer.cc:

#include <numpy/arrayobject.h>
#include "pybind11/numpy.h"     // complex
#include "pybind11/pybind11.h"
#include "pybind11/operators.h"
#include "numpy/arrayobject.h"
//#include "ndarray/pybind11.h"
#include "xtensor/xtensor.hpp"
#include "xtensor/xcontainer.hpp"
#include "xtensor-python/pyarray.hpp"

#include <complex>

namespace py = pybind11;

PYBIND11_PLUGIN (summer) {
  if (_import_array() < 0) {
    PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
    return nullptr;
  }

  py::module m("summer", "pybind11 example plugin");

  // m.def("sum", [](xt::pyarray<double> const& x) {
  //     xt::xtensor<double, 1> tmp(x);
  //     double sum = 0;
  //     for (auto e : tmp)
  //       sum += e;
  //     return sum;
  //   });

  m.def("sum", [](xt::pyarray<std::complex<double>> const& x) {
      std::complex<double> sum = 0;
      for (auto e : x)
        sum += e;
      return sum;
    },
    py::arg("inp").noconvert()
    );

  m.def("sum", [](xt::pyarray<double> const& x) {
      double sum = 0;
      for (auto e : x)
        sum += e;
      return sum;
    },
    py::arg("inp").noconvert()
    );


  return m.ptr();
}

It seems to have no effect. If I reverse the order of the defs (double is 1st), then when passing a complex array I get the numpy warning of discarding imag part. If I use the order above, the time for processing float array is much more than for complex array, suggesting there is conversion.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.