30#if defined(NUMCPP_INCLUDE_BOOST_PYTHON_INTERFACE) && !defined(NUMCPP_NO_USE_BOOST)
35#include "boost/python.hpp"
36#include "boost/python/numpy.hpp"
45 namespace boostPythonInterface
54 template<
typename dtype>
55 inline NdArray<dtype> boost2Nc(
const boost::python::numpy::ndarray& inArray)
57 BoostNdarrayHelper<dtype> helper(inArray);
58 if (helper.numDimensions() > 2)
64 if (helper.numDimensions() == 1)
67 arrayShape.cols =
static_cast<uint32>(helper.shape().front());
69 NdArray<dtype> returnArray(arrayShape);
70 for (
uint32 i = 0; i < arrayShape.size(); ++i)
72 returnArray[i] = helper(i);
78 arrayShape.rows =
static_cast<uint32>(helper.shape().front());
79 arrayShape.cols =
static_cast<uint32>(helper.shape()[1]);
81 NdArray<dtype> returnArray(arrayShape);
82 for (
uint32 row = 0; row < arrayShape.rows; ++row)
84 for (
uint32 col = 0; col < arrayShape.cols; ++col)
86 returnArray(row, col) = helper(row, col);
100 template<
typename dtype>
101 inline boost::python::numpy::ndarray nc2Boost(
const NdArray<dtype>& inArray)
103 const Shape inShape = inArray.shape();
104 boost::python::tuple
shape = boost::python::make_tuple(inShape.rows, inShape.cols);
105 BoostNdarrayHelper<dtype> newNdArrayHelper(
shape);
107 for (
uint32 row = 0; row < inShape.rows; ++row)
109 for (
uint32 col = 0; col < inShape.cols; ++col)
111 newNdArrayHelper(row, col) = inArray(row, col);
114 return newNdArrayHelper.getArray();
125 inline std::vector<T> list2vector(
const boost::python::list& inList)
127 return std::vector<T>(boost::python::stl_input_iterator<T>(inList), boost::python::stl_input_iterator<T>());
138 inline boost::python::list vector2list(std::vector<T>& inVector)
140 boost::python::list outList;
141 for (
auto& value : inVector)
143 outList.append(value);
156 template<
class Key,
class Value>
157 inline boost::python::dict map2dict(
const std::map<Key, Value>& inMap)
159 boost::python::dict dictionary;
160 for (
auto& keyValue : inMap)
162 dictionary[keyValue.first] = keyValue.second;
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:40
Definition: Cartesian.hpp:40
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition: Functions/Shape.hpp:42
std::uint32_t uint32
Definition: Types.hpp:40