 |
NumCpp
1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
31 #ifdef INCLUDE_BOOST_PYTHON_INTERFACE
38 #include "boost/python.hpp"
39 #include "boost/python/numpy.hpp"
46 namespace boostPythonInterface
55 template<
typename dtype>
73 returnArray[i] = helper(i);
84 for (
uint32 row = 0; row < arrayShape.
rows; ++row)
86 for (
uint32 col = 0; col < arrayShape.
cols; ++col)
88 returnArray(row, col) = helper(row, col);
103 template<
typename dtype>
107 boost::python::tuple
shape = boost::python::make_tuple(inShape.
rows, inShape.
cols);
110 for (
uint32 row = 0; row < inShape.
rows; ++row)
112 for (
uint32 col = 0; col < inShape.
cols; ++col)
114 newNdArrayHelper(row, col) = inArray(row, col);
128 inline std::vector<T>
list2vector(
const boost::python::list& inList)
130 return std::vector<T>(boost::python::stl_input_iterator<T>(inList), boost::python::stl_input_iterator<T>());
140 template <
typename T>
143 boost::python::list outList;
144 for (
auto& value : inVector)
146 outList.append(value);
159 template <
class Key,
class Value>
160 inline boost::python::dict
map2dict(
const std::map<Key, Value>& inMap)
162 boost::python::dict dictionary;
163 for (
auto& keyValue : inMap)
165 dictionary[keyValue.first] = keyValue.second;
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition: Functions/Shape.hpp:45
std::vector< T > list2vector(const boost::python::list &inList)
Definition: BoostInterface.hpp:128
NdArray< dtype > boost2Nc(const boost::python::numpy::ndarray &inArray)
Definition: BoostInterface.hpp:56
const std::vector< Py_intptr_t > & shape() noexcept
Definition: BoostNumpyNdarrayHelper.hpp:148
std::uint32_t uint32
Definition: Types.hpp:41
const boost::python::numpy::ndarray & getArray() noexcept
Definition: BoostNumpyNdarrayHelper.hpp:118
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 cols
Definition: Core/Shape.hpp:46
boost::python::list vector2list(std::vector< T > &inVector)
Definition: BoostInterface.hpp:141
Helper class for ndarray.
Definition: BoostNumpyNdarrayHelper.hpp:53
boost::python::dict map2dict(const std::map< Key, Value > &inMap)
Definition: BoostInterface.hpp:160
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:38
Definition: Coordinate.hpp:45
uint32 rows
Definition: Core/Shape.hpp:45
constexpr uint32 size() const noexcept
Definition: Core/Shape.hpp:103
uint8 numDimensions() noexcept
Definition: BoostNumpyNdarrayHelper.hpp:138
boost::python::numpy::ndarray nc2Boost(const NdArray< dtype > &inArray)
Definition: BoostInterface.hpp:104