Ah yes, I have to remember to actually import flex in python for the get_data() accessor to work.

foo.get_indices() is a different issue. I should be able to copy-and-paste whatever I need from somewhere else a scitbx::af::shared< std::size_t > is returned.

Cheers
-- David


On Wed, 2 Mar 2022 at 14:27, David Waterman <dgwaterman@gmail.com> wrote:
Hi folks,

I'm trying to create a boost python class that works with either vec3 or mat3 arrays (and I only need those two types). I made a templated class and then exported it twice with different names, for the vec3 and mat3 versions. For example, for mat3:

    class_<ReconstituteDerivatives< mat3<double> > >("ReconstituteDerivativesMat3", no_init)
      .def("get_data", &ReconstituteDerivatives< mat3<double> >::get_data)
      .def("get_indices", &ReconstituteDerivatives< std::size_t >::get_indices);

I can create one of these objects from Python

>>> foo
<dials_refinement_helpers_ext.ReconstituteDerivativesMat3 object at 0x7f3ffa421ac0>

but the accessors are not exported properly:

>>> foo.get_data()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: No to_python (by-value) converter found for C++ type: scitbx::af::shared<scitbx::mat3<double> >

I expected a scitbx_array_family_flex_ext.mat3_double here

>>> foo.get_indices()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    ReconstituteDerivativesMat3.get_indices(ReconstituteDerivativesMat3)
did not match C++ signature:
    get_indices(dials::refinement::ReconstituteDerivatives<unsigned long> {lvalue})

and I expected a scitbx_array_family_flex_ext.size_t here.

Is it likely there is something simple I am missing, like a #include? I do include flex_wrapper.h. Or perhaps I am just doing something wrong with templated classes and boost python. Looking at other code isn't helping to reveal the mysteries to me yet.

Cheers
-- David