[Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

Bill Baxter wbaxter@gmail....
Fri Sep 21 15:35:49 CDT 2007


On 9/21/07, Alexander Schmolck <a.schmolck@gmx.net> wrote:
>
> David Cournapeau <david@ar.media.kyoto-u.ac.jp> writes:
>
> > Alexander Schmolck wrote:
> >> "Charles R Harris" <charlesr.harris@gmail.com> writes:
> >>
> >>
> >>> The automatic handling of pointers for the default allocation type is
> also
> >>> convenient and makes it reasonable to have functions return matrices
> and
> >>> vectors.
> >>>
> >>
> >> Hmm, I wonder whether I missed something when I read the manual. I
> didn't see
> >> anything in the docs that suggests that ublas matrices do COW,
> reference
> >> semantics or anything else to make C++'s horrible pass-by-value
> semantics
> >> bearable performancewise, so I return and pass in shared_ptr's to
> matrices,
> >> which is syntactically ugly but avoids the need to write a (reference
> >> semantics) wrapper class for matrix. Am I missing some easier way to
> >> efficiently return and pass large matrices?
> >>
> > If ublas is using expression template, shouldn't it alleviate somewhat
> > this problem ?
>
> I don't think so, but then I'm hardly a C++ whizz. As far as I can tell
> the
> point of expression tempaltes is just to provide syntactic sugar so that
> one
> can write fairly complex in-place computations as a normal mathematical
> expression.
>
> But say I want to pass a big matrix of datapoints to a classifier -- how
> would
> expression templates help here? Ublas does have various view objects, but
> they're of limited usefulness, because they don't provide the same
> functionality as the matrix class itself.


What's wrong with using references?

void my_classifier(BigMatrix& datapoints) {
   ...
}


--bb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070922/62e9a2cc/attachment.html 


More information about the Numpy-discussion mailing list