 |
NumCpp
2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
|
Go to the documentation of this file.
30 #ifdef INCLUDE_PYBIND_PYTHON_INTERFACE
36 #include "pybind11/pybind11.h"
37 #include "pybind11/numpy.h"
44 namespace pybindInterface
61 template<
typename dtype>
64 dtype* dataPtr = numpyArray.mutable_data();
65 switch (numpyArray.ndim())
78 uint32 numRows =
static_cast<uint32>(numpyArray.shape(0));
79 uint32 numCols =
static_cast<uint32>(numpyArray.shape(1));
98 template<
typename dtype>
102 std::vector<pybind11::ssize_t>
shape{ inShape.
rows, inShape.
cols };
103 std::vector<pybind11::ssize_t> strides{ inShape.
cols *
sizeof(dtype),
sizeof(dtype) };
105 switch (returnPolicy)
109 return pybind11::array_t<dtype>(
shape, strides, inArray.
data());
113 typename pybind11::capsule reference(inArray.
data(), [](
void* ptr) {});
114 return pybind11::array_t<dtype>(
shape, strides, inArray.
data(), reference);
118 typename pybind11::capsule garbageCollect(inArray.
dataRelease(),
121 dtype* dataPtr = reinterpret_cast<dtype*>(ptr);
125 return pybind11::array_t<dtype>(
shape, strides, inArray.
data(), garbageCollect);
129 std::stringstream sstream;
130 sstream <<
"ReturnPolicy " <<
returnPolicyStringMap.at(returnPolicy) <<
" has not been implemented yet" << std::endl;
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4311
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:45
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition: Functions/Shape.hpp:44
std::uint32_t uint32
Definition: Types.hpp:40
ReturnPolicy
Enum for the pybind array return policy.
Definition: PybindInterface.hpp:47
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2556
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
uint32 cols
Definition: Core/Shape.hpp:45
static const std::map< ReturnPolicy, std::string > returnPolicyStringMap
Definition: PybindInterface.hpp:49
Definition: Coordinate.hpp:44
pointer data() noexcept
Definition: NdArrayCore.hpp:2534
NdArray< dtype > pybind2nc(pybind11::array_t< dtype, pybind11::array::c_style > &numpyArray)
Definition: PybindInterface.hpp:62
uint32 rows
Definition: Core/Shape.hpp:44
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
pybind11::array_t< dtype > nc2pybind(NdArray< dtype > &inArray, ReturnPolicy returnPolicy=ReturnPolicy::COPY)
Definition: PybindInterface.hpp:99