[C++-sig] Re: Re: Re: map key
David Abrahams
dave at boost-consulting.com
Thu Jan 23 19:59:19 CET 2003
"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> writes:
> --- Mike Rovner <mike at bindkey.com> wrote:
> P.S.: I attach two relevant sections from an article I am currently
> working on (for a non-CS audience). Comments are very welcome.
It's a nice article!
<snip>
>
> Considerations of the type discussed in the previous section directly
> lead to the following situation::
>
> >>> a = flex.int((1,2,3))
> >>> b = flex.double((2,3,4))
> >>> a * b
> TypeError: unsupported operand type(s) for *:
> 'scitbx_boost.array_family.flex_scitbx_ext.int' and
> 'scitbx_boost.array_family.flex_scitbx_ext.double'
>
> In passing we note that there is a simple solution which will produce
> the desired result::
>
> a.as_double() * b
>
> However, for the purpose of this discussion let's pretend that this
> solution does not exist. Of course the first question is: what is
> the reason for the apparently stupid limitation?
>
> As mentioned before, the Python ``flex`` types are implemented as
> instantiations of C++ class templates. This ensures that all array
> operations are very fast. However, from the discussion in the previous
> section it follows that exposing the full class with its many member
> functions to Python **for each element type** (``int``, ``double``,
> ``miller::index<>``, etc.) creates very sizable object files. If only
> *homogeneous* operators (``int * int``, ``double * double``, etc.) are
> used the combined size of the object files scales linearly with the
> number of element types involved. However, if the library is expanded
> to support *heterogeneous* operators (``int * double``, ``double *
> int``, etc.) the combined object files grow proportional to the square
> of the number of array element types involved! With current technology
> this is simply prohibitive.
You might consider the impact of using something like weave for a case
like this. It generates and compiles different instantiations of the
same code on demand.
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list