5 #include <pybind11/pybind11.h> 6 #include <pybind11/numpy.h> 13 namespace bindinghelpers
23 template<
typename DataType>
26 if( array.ndim() != 2 )
28 throw std::invalid_argument(
"efl::BasicMatrix from numpy ndarray: Input array must be 2D" );
31 if( not array.dtype().is( pybind11::dtype::of<DataType>() ) )
33 throw std::invalid_argument(
"efl::BasicMatrix from numpy ndarray: Input matrix has a different data type (dtype)." );
35 std::size_t
const numRows =
static_cast<pybind11::ssize_t
>(array.shape()[0]);
36 std::size_t
const numCols =
static_cast<pybind11::ssize_t
>(array.shape()[1]);
38 for( std::size_t rowIdx( 0 ); rowIdx < numRows; ++rowIdx )
40 for( std::size_t colIdx( 0 ); colIdx < numCols; ++colIdx )
42 ret( rowIdx, colIdx ) = *
static_cast<DataType
const *
>(array.data( rowIdx, colIdx ));
efl::BasicMatrix< DataType > matrixFromNdArray(pybind11::array_t< SampleType > const &array, std::size_t alignment=0)
Definition: matrix_from_ndarray.hpp:24
Definition: options.cpp:10