File: arrvec.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 (9 lines) | stat: -rw-r--r-- 327 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
#pragma once
#include <pybind11/numpy.h>

template<typename T>
pybind11::array_t<T> py_array_from_vector(std::vector<T>&& original_vec) {
  auto v = new std::vector<T>(std::move(original_vec));
  pybind11::capsule cap(v, [](void* p) { delete (std::vector<T>*) p; });
  return pybind11::array_t<T>(v->size(), v->data(), cap);
}