File: miller_a.h

package info (click to toggle)
gemmi 0.5.7%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,344 kB
  • sloc: cpp: 48,972; python: 4,352; ansic: 3,428; sh: 302; makefile: 69; f90: 42; javascript: 12
file content (16 lines) | stat: -rw-r--r-- 571 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include <pybind11/numpy.h>

template<typename Ret, typename Obj, typename Func>
pybind11::array_t<Ret>
miller_function(const Obj& obj, Func func, pybind11::array_t<int> hkl) {
  auto h = hkl.unchecked<2>();
  if (h.shape(1) != 3)
    throw std::domain_error("error: the size of the second dimension != 3");
  auto result = pybind11::array_t<Ret>(h.shape(0));
  pybind11::buffer_info rbuf = result.request();
  Ret* rptr = (Ret*) rbuf.ptr;
  for (pybind11::ssize_t i = 0; i < h.shape(0); ++i)
    rptr[i] = (obj.*func)({{h(i, 0), h(i, 1), h(i, 2)}});
  return result;
}