5 #include <pybind11/pybind11.h> 6 #include <pybind11/numpy.h> 13 namespace bindinghelpers
25 template<
typename DataType>
28 if( array.ndim() != 1 )
30 throw std::invalid_argument(
"efl::BasicVector from numpy ndarray: Input array must be 1D" );
33 if( not array.dtype().is( pybind11::dtype::of<DataType>() ) )
35 throw std::invalid_argument(
"efl::BasicVector from numpy ndarray: Input matrix has a different data type (dtype)." );
37 std::size_t
const numElements =
static_cast<pybind11::ssize_t
>(array.shape()[0]);
39 for( std::size_t elIdx( 0 ); elIdx < numElements; ++elIdx )
41 ret[ elIdx ] = *
static_cast<DataType
const *
>(array.data( elIdx ));
Definition: options.cpp:10
efl::BasicVector< DataType > vectorFromNdArray(pybind11::array_t< SampleType > const &array, std::size_t alignment=0)
Definition: vector_from_ndarray.hpp:26
Definition: basic_vector.hpp:28