Boost logo

Boost Users :

From: Ed Johnson (ed_at_[hidden])
Date: 2006-05-31 17:56:06


Alexander Bell wrote:
> Ed Johnson <ed_at_[hidden]> writes:
>
>> Does anyone know how to recreate this example using the iterators?
>
> try:
>
> using namespace boost::numeric::ublas;
> typedef matrix<double> MatType;
> MatType m(3,3);
>
> for(MatType::iterator1 i1 = m.begin1(); i1!=m.end1(); ++i1)
> for(MatType::iterator2 i2 = i1.begin2(); i2!=i1.end2(); ++i2)
> *i2= ... // obviously you cannot assign the iterators here
>
>
> untested - but the main idea is, that iterator1 accesses each row and iterator2
> loops over the columns of the rows - this should work for all models of Matrix
> (including sparse matrices)
>
> Good luck,
>
> Alexander.

Thanks, Alexander.
I tried the code and got these compilation errors.

c:\workspace\hivm\trunk\src\test\PreProcessorTest.cpp(315): error C2039:
'begin2' : is not a member of 'boost::numeric::ublas::matrix<T>::iterator1'
        with
        [
            T=double
        ]

c:\workspace\hivm\trunk\src\test\PreProcessorTest.cpp(315): error C2039:
'end2' : is not a member of 'boost::numeric::ublas::matrix<T>::iterator1'
        with
        [
            T=double
        ]

I tried the following, but it doesn't work either. The goal of the code
is to load the entire matrix with 2's.

code:

using namespace boost::numeric::ublas;
typedef matrix<double> MatType;
MatType m(3,3);

for(MatType::iterator1 i1 = m.begin1(); i1!=m.end1(); ++i1)
  for(MatType::iterator2 i2 = m.begin2(); i2!=m.end2(); ++i2)
          *i2 = 2;

std::cout << m << std::endl;

output:
((2,2,2),(-6.27744e+066,-6.27744e+066,-6.27744e+066),(-6.27744e+066,-6.27744e+066,-6.27744e+066))

Also, pointing an iterator2 to an iterator1 results in a conversion error.

c:\workspace\hivm\trunk\src\test\PreProcessorTest.cpp(315): error C2440:
'initializing' : cannot convert from
'boost::numeric::ublas::matrix<T>::iterator1' to
'boost::numeric::ublas::matrix<T>::iterator2'
        with
        [
            T=double
        ]
        and
        [
            T=double
        ]

Any ideas?

Thanks,

Ed


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net