logo       

Re: ublas::matrix sharing storage with ublas::vector: msg#00317

lib.boost.user

Subject: Re: ublas::matrix sharing storage with ublas::vector

Kresimir Fresl wrote:

[snip]

> There is a storage class `array_adaptor<>' (in storage.hpp, currently
> undocumented), which adapts some other array to interface
> which ublas classes expect:
> ==============================================
> #include <cstddef>
> #include <iostream>
>
> #define BOOST_UBLAS_SIMPLE_ARRAY_ADAPTOR
>
> #include <boost/numeric/ublas/vector.hpp>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> typedef boost::numeric::ublas::array_adaptor<double> storage_t;
> typedef boost::numeric::ublas::vector<double, storage_t> vct_t;
> typedef boost::numeric::ublas::row_major rm_t;
> typedef boost::numeric::ublas::matrix<double, rm_t, storage_t> matr_t;
>
> int main() {
>
> std::size_t n = 5;
> std::size_t nxn = n * n;
>
> double *a = new double[nxn];
> storage_t st (nxn, a);
>
> vct_t v (nxn, st);
> for (std::size_t i = 0; i < nxn; ++i)
> v (i) = i + 0.1;
> std::cout << v << std::endl;
>
> matr_t m (n, n, st);
> std::cout << m << std::endl;
>
> for (std::size_t i = 0; i < n; ++i)
> for (std::size_t j = 0; j < n; ++j)
> m (i, j) = 10 * i + j + 0.1;
>
> std::cout << v << std::endl;
> std::cout << m << std::endl;
>
> delete[] a;
> }
> ==============================================
> [Note that BOOST_UBLAS_SIMPLE_ARRAY_ADAPTOR must
> be defined. Otherwise array_adaptor<> uses boost::shared_array<>
> which doesn't have operator+, which is in turn needed in some
> functions -- Joerg, are you listening?]

Err, what's up? Oh, a new test case (and a new bug ;-( I'll look into it.

Thanks

Joerg



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/EbFolB/TM
---------------------------------------------------------------------~->

Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx>


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise