File: miller_a.h

package info (click to toggle)
gemmi 0.6.5%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,836 kB
  • sloc: cpp: 54,719; python: 4,743; ansic: 3,972; sh: 384; makefile: 73; 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;
}