Boost logo

Ublas :

Subject: Re: [ublas] initialize ublas matrix with a std::vector or array
From: Bruno Abreu Calfa (bacalfa_at_[hidden])
Date: 2011-11-12 23:16:59


Michael,

There is no matrix constructor defined that takes a std::vector as the
third argument. It has to be a ublas storage array type. Look for "Storage
and special containers" in
http://www.boost.org/doc/libs/1_47_0/libs/numeric/ublas/doc/index.htm.

The following listing will work:

#include <iostream>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>

namespace ublas = boost::numeric::ublas;

void Foo(ublas::unbounded_array<double>& v)
{
    ublas::matrix<double> t(2, 2, v);

    std::cout << t << std::endl;
}

int main()
{
    ublas::unbounded_array<double> v(4);
    v[0] = 1.0; v[1] = 2.0; v[2] = 3.0; v[3] = 4.0;

    Foo(v);

    return 0;
}

On Sat, Nov 12, 2011 at 10:37 PM, Michael Morrison
<mwmorrison93_at_[hidden]>wrote:

> Hello All,
>
> I have a method that takes a std::vector as one of its parameters. Is
> there a way I can initialize a matrix by assigning the std::vector to the
> matrix? Here's what I tried to do below. Does anyone know how i can achieve
> assigning the vector (or even a pointer of doubles) to the matrix? Thanks
> in advance. Mike
>
> void Foo(std::vector v)
> {
> matrix<double> t(2, 2, v);
> // work with matrix...
> }
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: bacalfa_at_[hidden]
>