 |
NumCpp
1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
31 #ifdef INCLUDE_PYBIND_PYTHON_INTERFACE
37 #include "pybind11/pybind11.h"
38 #include "pybind11/numpy.h"
45 namespace pybindInterface
62 template<
typename dtype>
65 dtype* dataPtr = numpyArray.mutable_data();
66 switch (numpyArray.ndim())
79 uint32 numRows =
static_cast<uint32>(numpyArray.shape(0));
80 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:4296
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:46
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition: Functions/Shape.hpp:45
std::uint32_t uint32
Definition: Types.hpp:41
ReturnPolicy
Enum for the pybind array return policy.
Definition: PybindInterface.hpp:48
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2549
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 cols
Definition: Core/Shape.hpp:46
static const std::map< ReturnPolicy, std::string > returnPolicyStringMap
Definition: PybindInterface.hpp:50
Definition: Coordinate.hpp:45
pointer data() noexcept
Definition: NdArrayCore.hpp:2527
NdArray< dtype > pybind2nc(pybind11::array_t< dtype, pybind11::array::c_style > &numpyArray)
Definition: PybindInterface.hpp:63
uint32 rows
Definition: Core/Shape.hpp:45
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
pybind11::array_t< dtype > nc2pybind(NdArray< dtype > &inArray, ReturnPolicy returnPolicy=ReturnPolicy::COPY)
Definition: PybindInterface.hpp:99