MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / bitSetFromNP

Function bitSetFromNP

source/mrmeshnumpy/MRPythonNumpyExposing.cpp:512–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510
511template<typename T>
512MR::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
533MR_ADD_PYTHON_CUSTOM_DEF( mrmeshnumpy, NumpyBitSets, [] ( pybind11::module_& m )
534{

Callers

nothing calls this directly

Calls 2

requestMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected