core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
ndarray_interop.hpp File Reference
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <array>
#include <cstring>
#include <Kokkos_Core.hpp>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
#include "peclet/core/common/view.hpp"

Go to the source code of this file.

Namespaces

namespace  peclet
 
namespace  peclet::core
 
namespace  peclet::core::python
 

Functions

template<class MemorySpace >
std::pair< int, intpeclet::core::python::dlpack_device ()
 Map a Kokkos memory space to a DLPack {device_type, device_id} pair.
 
template<class T >
void peclet::core::python::require_dtype (const nb::ndarray<> &a, const char *who)
 Throw if a's element type is not T.
 
template<class V >
auto peclet::core::python::view_to_ndarray (const V &view)
 Export a Kokkos View to a Python array without copying.
 
template<class T >
nb::ndarray< nb::numpy, Tpeclet::core::python::vector_to_ndarray (std::vector< T > &&v, std::initializer_list< std::size_t > shape, std::initializer_list< std::int64_t > strides)
 Export a host std::vector<T> as a NumPy array of the given logical shape and element-unit strides, without the extra copy the old to_xyz made: the vector is moved into a capsule that backs the array.
 
template<class T >
peclet::core::View< Tpeclet::core::python::ndarray_to_view (const nb::ndarray<> &a, const std::string &label)
 Import a (contiguous) Python array into a freshly-allocated flat device peclet::core::View<T>.
 
template<class T >
std::vector< Tpeclet::core::python::ndarray_to_vector (const nb::ndarray<> &a)
 Import a (contiguous) Python array into a host std::vector<T>.
 

Variables

template<class MemorySpace >
constexpr bool peclet::core::python::is_host_space_v
 True when MemorySpace is reachable from the host (NumPy export path); false for a device-resident space (CUDA/HIP — DLPack/CuPy export path).