Discussion:
[Pyublas] ublas/PyUblas functions
John Edmiston
2009-09-04 18:28:20 UTC
Permalink
Hello,

Very green user here (brought up from python so I'm pretty weak when it comes to C++, and I'm not any sort of programmer by education), I appreciate the easy installation setup for PyUblas and the documentation, unlike for Boost/Python, ugh.

I'm just trying to do some simple things with PyUblas/Boost I was just wondering what the best way to do things like matrix-vector multiplication with numpy_vector and numpy_matrix would be - I had been using your numpy_vector's as_ublas() function to convert them to boost::numeric::ublas::vector/matrix individually, then using boost::numeric::ublas::prod(amatrix,avector) - and then in order to output the result back to python I used the boost::numeric::ublas::vector which resulted from the matrix-vector product as the constructor argument for a new numpy_vector object in order to send back to python.
e.g. something like:
boost::numeric::ublas::vector<double> v = a_numpy_vector.as_ublas();
boost::numeric::ublas::matrix<double> R = a_numpy_matrix.as_ublas();
boost::numeric::ublas::vector<double> Rv = boost::numeric::ublas::prod(R,v);
pyublas::numpy_vector<double> return_val(Rv);

Is this what you would recommend for this sort of operation or would it be at all more efficient at all to implement the matrix vector multiplication myself. Im not concerned with 'optimimum' performance at all really, I just thought maybe there was an even simpler way to do matrix-vector product without needing the as_ublas() function to and then converting back to numpy_vector.

Thanks
John

_________________________________________________________________
Windows Live: Keep your friends up to date with what you do online.
http://windowslive.com/Campaign/SocialNetworking?ocid=PID23285::T:WLMTAGL:ON:WL:en-US:SI_SB_online:082009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.tiker.net/pipermail/pyublas/attachments/20090904/68980a74/attachment.htm>
Andreas Klöckner
2009-09-08 15:35:10 UTC
Permalink
Hi John,
Post by John Edmiston
Very green user here (brought up from python so I'm pretty weak when it
comes to C++, and I'm not any sort of programmer by education), I
appreciate the easy installation setup for PyUblas and the documentation,
unlike for Boost/Python, ugh.
I agree that Boost's installation is more painful than it needs to be. Did you
see this Wiki page I maintain?

http://wiki.tiker.net/BoostInstallationHowto
Post by John Edmiston
I'm just trying to do some simple things with PyUblas/Boost I was just
wondering what the best way to do things like matrix-vector multiplication
with numpy_vector and numpy_matrix would be - I had been using your
numpy_vector's as_ublas() function to convert them to
boost::numeric::ublas::vector/matrix individually, then using
boost::numeric::ublas::prod(amatrix,avector) - and then in order to output
the result back to python I used the boost::numeric::ublas::vector which
resulted from the matrix-vector product as the constructor argument for a
new numpy_vector object in order to send back to python. e.g. something
boost::numeric::ublas::vector<double> v = a_numpy_vector.as_ublas();
boost::numeric::ublas::matrix<double> R = a_numpy_matrix.as_ublas();
boost::numeric::ublas::vector<double> Rv =
boost::numeric::ublas::prod(R,v); pyublas::numpy_vector<double>
return_val(Rv);
prod() should work directly on numpy_matrix and numpy_vector, however
unfortunately it will only be efficient if you compile with the
BOOST_UBLAS_USE_ITERATING define. Therefore, if you can stand the copy, the
way you are doing it is perfectly ok. If you'd like to save some work, you can
also have ublas::vector and ublas::matrix directly as function arguments (and
return values, I believe). PyUblas will do the copying and conversion for you.

See also:
http://documen.tician.de/pyublas/faq.html#gaah-why-is-this-garbage-so-slow

Best,
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.tiker.net/pipermail/pyublas/attachments/20090908/04d081f6/attachment.pgp>
Loading...