Boost logo

Ublas :

From: Vardan Akopian (vakopian_at_[hidden])
Date: 2005-09-13 09:05:43


Hi Ott,

You should be using shallow_array_adaptor as in
http://lists.boost.org/MailArchives/ublas/2005/07/0530.php

Note that shallow_array_adaptor has been removed from boost-1.33, and
a new adaptor carray_adaptor has been introduced. So if you update to
boost-1.33 you may need change your code accordingly.

Regards
-Vardan

On 9/13/05, Ott Toomet <otoomet_at_[hidden]> wrote:
> Dear list,
>
> I would like to write some functions in c++ which will be called from
> R. The matrix data will be passed and returned as double* array. The
> problem is to force a matrix to share the same memory as double*
> array. Examples in a similar thread
>
> http://lists.boost.org/MailArchives/boost-users/msg02507.php
>
> seem not to work for me, the array contents will be copied to matrix
> at it's initialisation but later changes are not reflected there any
> more. E.g.
>
>
> #define BOOST_UBLAS_SIMPLE_ARRAY_ADAPTOR
>
> #include <boost/numeric/ublas/vector.hpp>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> using namespace boost::numeric::ublas;
>
> int main() {
> double a[] = {-11, -12, -13, -14};
> array_adaptor<double> st (4, a);
> vector<double, array_adaptor<double> > v(4, st);
> unsigned i;
> //
> a[1] = 100;
> std::cout << "before initialisation: v " << v << std::endl;
> for(i = 0; i < 4; ++i)
> v(i) = i + 0.1;
> std::cout << "after " << v << std::endl;
> std::cout << a[1] << std::endl;
> }
>
> results in
>
> siim_at_hugo:~/tyyq/newmat$ ./aakatse
> before initialisation: v [4](-11,-12,-13,-14)
> after [4](0.1,1.1,2.1,3.1)
> 100
>
> Note that a[1] (still equal to 100) is not overwritten by v(1).
>
> Do I miss something?
>
>
> The compilation was performed by
>
> g++ -c aakatse.c++ -O2 -Wall -Wno-unknown-pragmas -I/usr/include
> g++ aakatse.o -O2 -Wall -Wno-unknown-pragmas -L/usr/lib -lm -o aakatse
>
> I have
>
> boost-1.32.0-1.rhel4
> g++ (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.1)
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>