| 510 | |
| 511 | template<typename T> |
| 512 | MR::TaggedBitSet<T> bitSetFromNP( const pybind11::buffer& bools ) |
| 513 | { |
| 514 | pybind11::buffer_info boolsInfo = bools.request(); |
| 515 | if ( boolsInfo.ndim != 1 ) |
| 516 | throw std::runtime_error( "shape of input python vector 'bools' should be (n)" ); |
| 517 | |
| 518 | if ( boolsInfo.shape[0] == 0 ) |
| 519 | return {}; |
| 520 | |
| 521 | if ( boolsInfo.format != pybind11::format_descriptor<bool>::format() ) |
| 522 | throw std::runtime_error( "format of python vector 'bools' should be bool" ); |
| 523 | |
| 524 | MR::TaggedBitSet<T> resultBitSet( boolsInfo.shape[0] ); |
| 525 | |
| 526 | bool* data = reinterpret_cast< bool* >( boolsInfo.ptr ); |
| 527 | for ( int i = 0; i < boolsInfo.shape[0]; ++i ) |
| 528 | resultBitSet.set( MR::Id<T>( i ), data[i] ); |
| 529 | |
| 530 | return resultBitSet; |
| 531 | } |
| 532 | |
| 533 | MR_ADD_PYTHON_CUSTOM_DEF( mrmeshnumpy, NumpyBitSets, [] ( pybind11::module_& m ) |
| 534 | { |