pyublas + lapack problem?
by John Edmiston

Hello,
Thanks very much for your response on my last question. I have come
across another issue which I have been unable to solve based on my
normal essentially clueless method of piecing together things from
online postings.
I want to be able to implement some things from the boost bindings, eg.
lapack functions. But when I have #include <pyublas/numpy.hpp> I
get segmentation faults before entering main().
For example:
lapack_test.cc:
#define PYUBLAS_HAVE_BOOST_BINDINGS
#include <iostream>
#include <pyublas/numpy.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/bindings/lapack/geev.hpp>
#include <complex>
namespace ublas = boost::numeric::ublas;
namespace lapack = boost::numeric::bindings::lapack;
int main() {
int n=3;
ublas::matrix < double, ublas::column_major> A (n,n);
for(unsigned int i=0; i<n; i++){
for(unsigned int j=0; j<n; j++){
A(i,j)=i*j+1;
}
}
ublas::matrix<std::complex<double>, ublas::column_major> Vl(n,n),Vr(n,n);
ublas::vector<std::complex<double> > w(n);
lapack::geev(A, w, &Vl, &Vr, lapack::optimal_workspace());
std::cout<<"Vl "<<Vl<<std::endl;
std::cout<<"Vr "<<Vr<<std::endl;
return 0;
}
I attempt to compile this with
g++ lapack_test.cc -I/usr/apps/python2.6/include/python2.6/ -L/usr/apps/python2.6/lib/ -lpython2.6 -L/g/g23/edmiston/BOOST_INSTALL_LIB/ -lboost_python-gcc41-mt-1_39 -I/usr/apps/python2.6/lib/python2.6/site-packages/numpy/core/include/ -I/g/g23/edmiston/PYUBLAS/lib/python2.6/site-packages/PyUblas-0.93.1-py2.6-linux-x86_64.egg/include -I/g/g23/edmiston/BOOST_NUMERIC_BINDINGS/include/boost-numeric-bindings -L/usr/lib64 -llapack
which compiles, but the executable seg faults. If I leave out the
#include <pyublas/numpy.hpp> it works. It seems to be a problem
with having both that particular include file and the linking to
liblapack.so (just from trying out different combinations to the g++
command ).
I obviously have a very low level understanding of compiling and
linking but have tried my quota of things blindly. Have you come across this problem before? Or is there a
different way suggested to get lapack functions to operate with
pyublas? What is the meaning of life?
Thanks,
John
_________________________________________________________________
Insert movie times and more without leaving Hotmail®.
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tut...
9 years, 11 months

ublas/PyUblas functions
by John Edmiston

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...
9 years, 11 months