| 18 | } ) |
| 19 | |
| 20 | std::vector<MR::Vector3f> fromNumpyArrayInfo( const pybind11::buffer_info& bufInfo ) |
| 21 | { |
| 22 | std::vector<MR::Vector3f> vec; |
| 23 | auto stride0 = bufInfo.strides[0] / bufInfo.itemsize; |
| 24 | auto stride1 = bufInfo.strides[1] / bufInfo.itemsize; |
| 25 | vec.resize( bufInfo.shape[0] ); |
| 26 | auto fillData = [&] ( const auto* data ) |
| 27 | { |
| 28 | for ( auto i = 0; i < bufInfo.shape[0]; i++ ) |
| 29 | { |
| 30 | auto ind = stride0 * i; |
| 31 | vec[i] = MR::Vector3f( |
| 32 | float( data[ind] ), |
| 33 | float( data[ind + stride1] ), |
| 34 | float( data[ind + stride1 * 2] ) ); |
| 35 | } |
| 36 | }; |
| 37 | if ( bufInfo.format == pybind11::format_descriptor<double>::format() ) |
| 38 | { |
| 39 | double* data = reinterpret_cast< double* >( bufInfo.ptr ); |
| 40 | fillData( data ); |
| 41 | } |
| 42 | else if ( bufInfo.format == pybind11::format_descriptor<float>::format() ) |
| 43 | { |
| 44 | float* data = reinterpret_cast< float* >( bufInfo.ptr ); |
| 45 | fillData( data ); |
| 46 | } |
| 47 | else |
| 48 | throw std::runtime_error( "dtype of input python vector should be float32 or float64" ); |
| 49 | return vec; |
| 50 | } |
| 51 | |
| 52 | std::vector<MR::Vector3f> fromNumpyArray( const pybind11::buffer& coords ) |
| 53 | { |
no test coverage detected