 |
NumCpp
2.4.0
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
53 template<
typename dtype>
54 using pbArray = pybind11::array_t<dtype, pybind11::array::c_style>;
65 template<
typename dtype>
68 const auto dataPtr = numpyArray.mutable_data();
69 switch (numpyArray.ndim())
82 const uint32 numRows =
static_cast<uint32>(numpyArray.shape(0));
83 const uint32 numCols =
static_cast<uint32>(numpyArray.shape(1));
102 template<
typename dtype>
105 const auto dataPtr = numpyArray.
data();
106 switch (numpyArray.ndim())
119 const uint32 numRows =
static_cast<uint32>(numpyArray.shape(0));
120 const uint32 numCols =
static_cast<uint32>(numpyArray.shape(1));
138 template<
typename dtype>
142 const std::vector<pybind11::ssize_t>
shape{
static_cast<pybind11::ssize_t
>(inShape.
rows),
143 static_cast<pybind11::ssize_t
>(inShape.
cols) };
144 const std::vector<pybind11::ssize_t> strides{
static_cast<pybind11::ssize_t
>(inShape.
cols *
sizeof(dtype)),
145 static_cast<pybind11::ssize_t
>(
sizeof(dtype)) };
157 template<
typename dtype>
161 const std::vector<pybind11::ssize_t>
shape{
static_cast<pybind11::ssize_t
>(inShape.
rows),
162 static_cast<pybind11::ssize_t
>(inShape.
cols) };
163 const std::vector<pybind11::ssize_t> strides{
static_cast<pybind11::ssize_t
>(inShape.
cols *
sizeof(dtype)),
164 static_cast<pybind11::ssize_t
>(
sizeof(dtype)) };
166 switch (returnPolicy)
174 typename pybind11::capsule reference(inArray.
data(), [](
void* ) {});
179 typename pybind11::capsule garbageCollect(inArray.
dataRelease(),
182 dtype* dataPtr = reinterpret_cast<dtype*>(ptr);
190 std::stringstream sstream;
191 sstream <<
"ReturnPolicy " <<
returnPolicyStringMap.at(returnPolicy) <<
" has not been implemented yet" << std::endl;
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
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:2574
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:2552
uint32 rows
Definition: Core/Shape.hpp:44
pbArrayGeneric nc2pybind(const NdArray< dtype > &inArray)
Definition: PybindInterface.hpp:139
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
NdArray< dtype > pybind2nc_copy(const pbArray< dtype > &numpyArray)
Definition: PybindInterface.hpp:103
pybind11::array_t< dtype, pybind11::array::c_style > pbArray
Definition: PybindInterface.hpp:54
pybind11::array pbArrayGeneric
Definition: PybindInterface.hpp:55
NdArray< dtype > pybind2nc(pbArray< dtype > &numpyArray)
Definition: PybindInterface.hpp:66