Boost logo

Ublas :

From: Jesse Manning (manning.jesse_at_[hidden])
Date: 2008-02-03 10:28:07


The problem is that the lapack::gesv function you are using is expecting a
matrix for the second parameter and you are passing in a vector.

To fix this problem try adding this line:

#include <boost/numeric/bindings/traits/ublas_vector2.hpp>

the ublas_vector2.hpp header file basically allows you to pass in a vector
to functions expecting a matrix by treating the vector as an nx1 matrix.

When I added that header include to your program it compiled fine for me.

Jesse

On Feb 3, 2008 8:00 AM, Arun Tom Abraham <aruntom55_at_[hidden]> wrote:

> Hi,
>
> I tried the suggestion of
>
> ublas::matrix<float, column_major> A(3,3);
> ublas::vector<float> b(3);
>
> but this has given me huge compilation errors -- >
>
> The system i am solving is
> 2x-3y+2z=21
> x+4y-z=1
> -x+2y+z=17
>
>
> ####################code #############################
>
> #include<boost/numeric/ublas/matrix.hpp>
> #include<boost/numeric/ublas/io.hpp>
> #include<boost/numeric/bindings/traits/ublas_matrix.hpp>
> #include<boost/numeric/bindings/lapack/gesv.hpp>
>
> namespace ublas = boost::numeric::ublas;
> namespace lapack= boost::numeric::bindings::lapack;
>
> int main()
> {
> ublas::matrix<float,ublas::column_major> A(3,3);
> ublas::vector<float> b(3);
>
>
> for(unsigned i=0;i < A.size1();i++)
> for(unsigned j =0;j < A.size2();j++)
> {
> std::cout << "enter element "<<i << j << std::endl;
> std::cin >> A(i,j);
> }
>
> std::cout << A << std::endl;
>
> b(0) = 21; b(1) = 1; b(2) = 17;
>
> lapack::gesv(A,b);
>
> std::cout << b << std::endl;
>
>
> return 0;
> }
>
>
> ############################################################
>
> the error seems to be with the lapack part of the code now
>
> ################ compile error messages
> #####################################
>
>
>
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:
>
> In function 'int boost::numeric::bindings::lapack::gesv(MatrA&,
> IVec&, MatrB&) [with MatrA = boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, IVec = boost::numeric::bindings::traits::detail::array<int>]':
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:139:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, MatrB&) [with MatrA =
> boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]'
> exp2.cpp:35: instantiated from here
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:104:
> error: no type named 'matrix_structure' in 'struct
>
> boost::numeric::bindings::traits::matrix_traits<boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> > >'
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:139:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, MatrB&) [with MatrA =
> boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]'
>
> exp2.cpp:35: instantiated from here
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:116:
> error: no matching function for call to
> 'matrix_storage(boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >&)'
>
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/traits/matrix_traits.hpp:
> In function 'int boost::numeric::bindings::traits::matrix_size1(M&)
> [with M = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]':
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:112:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, IVec&, MatrB&) [with
> MatrA = boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, IVec = boost::numeric::bindings::traits::detail::array<int>]'
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:139:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, MatrB&) [with MatrA =
> boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]'
> exp2.cpp:35: instantiated from here
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/traits/matrix_traits.hpp:102:
> error: 'size1' is not a member of
>
> 'boost::numeric::bindings::traits::matrix_traits<boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> > >'
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/traits/matrix_traits.hpp:
> In function 'int boost::numeric::bindings::traits::matrix_size2(M&)
> [with M = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]':
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:116:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, IVec&, MatrB&) [with
> MatrA = boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, IVec = boost::numeric::bindings::traits::detail::array<int>]'
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:139:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, MatrB&) [with MatrA =
> boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]'
> exp2.cpp:35: instantiated from here
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/traits/matrix_traits.hpp:106:
> error: 'size2' is not a member of
>
> 'boost::numeric::bindings::traits::matrix_traits<boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> > >'
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/traits/matrix_traits.hpp:
> In function 'int
> boost::numeric::bindings::traits::leading_dimension(M&) [with M =
> boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]':
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:116:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, IVec&, MatrB&) [with
> MatrA = boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, IVec = boost::numeric::bindings::traits::detail::array<int>]'
> /home/iitb-aero/boost/boost/boost/numeric/bindings/lapack/gesv.hpp:139:
> instantiated from 'int
> boost::numeric::bindings::lapack::gesv(MatrA&, MatrB&) [with MatrA =
> boost::numeric::ublas::matrix<float,
> boost::numeric::ublas::basic_column_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >, MatrB = boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> >]'
> exp2.cpp:35: instantiated from here
>
> /home/iitb-aero/boost/boost/boost/numeric/bindings/traits/matrix_traits.hpp:131:
> error: 'leading_dimension' is not a member of
>
> 'boost::numeric::bindings::traits::matrix_traits<boost::numeric::ublas::vector<float,
> boost::numeric::ublas::unbounded_array<float, std::allocator<float> >
> > >'
>
> #########################################################
> regards,
>
> Arun
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>