GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — xtensor-python/benchmark/main.cpp at master · xtensor-stack/xtensor-python

Expand file tree

/

main.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
57 lines (48 loc) · 1.61 KB
/

main.cpp

Copy path

File metadata and controls

57 lines (48 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
57
#include "pybind11/pybind11.h"
#include "pybind11/numpy.h"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h"
#include "xtensor/containers/xtensor.hpp"
#include "xtensor/containers/xarray.hpp"
#include "xtensor-python/pyarray.hpp"
#include "xtensor-python/pytensor.hpp"
#include "xtensor-python/pyvectorize.hpp"
using complex_t = std::complex<double>;
namespace py = pybind11;
PYBIND11_MODULE(benchmark_xtensor_python, m)
{
if(_import_array() < 0)
{
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
}
m.doc() = "Benchmark module for xtensor python bindings";
m.def("sum_array", [](xt::pyarray<double> const& x) {
double sum = 0;
for(auto e : x)
sum += e;
return sum;
});
m.def("sum_tensor", [](xt::pytensor<double, 1> const& x) {
double sum = 0;
for(auto e : x)
sum += e;
return sum;
});
m.def("pybind_sum_array", [](py::array_t<double> const& x) {
double sum = 0;
size_t size = x.size();
const double* data = x.data(0);
for(size_t i = 0; i < size; ++i)
sum += data[i];
return sum;
});
m.def("rect_to_polar", [](xt::pyarray<complex_t> const& a) {
return py::vectorize([](complex_t x) { return std::abs(x); })(a);
});
m.def("pybind_rect_to_polar", [](py::array a) {
if (py::isinstance<py::array_t<complex_t>>(a))
return py::vectorize([](complex_t x) { return std::abs(x); })(a);
else
throw py::type_error("rect_to_polar unhandled type");
});
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.