|
Boost Users : |
Subject: Re: [Boost-users] Multiplying a matrix and vector ===> vector
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-10-27 21:24:59
> >> Alternatively, I can avoid the tmp variable altogether and get a
> >> working program to copy the result of matrix-vector multiplication onto
> >> a new vector y but then I would
> >> need two multiplications. E.g.
> >>
> >> std::copy(prod(m,x).begin(), prod(m,x).end(), y.begin());
> >>
> >
> > This doesn't answer your question, but I just wanted to point out that
> > the above line is undefined behaviour, since the begin and end iterators
> > refer to two different ranges (two different temporary variables). This
> > problem can be avoided by using boost::copy (from Boost.Range) instead,
> > which allows you to mention the range just once:
> >
> > boost::copy(prod(m, x), y.begin());
>
> Unfortunately I'm unable to get the below suggestion to work. Could you
> please mention if this was what you were referring to:
> http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/adaptors/introduction.html?
>
> If so, the closest file I have in my Boost Version 1.0 is
> boost/range/iterator_range.hpp but
> that
> doesn't have the below copy function. I'll probably need to get the 1.49.0
> version then.
Boost.Range's copy function is documented here:
http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/algorithms/mutating/copy.html
I believe it was first added in version 1.43. However, it's not difficult to write
your own version. The following will work for any range type that has begin() and
end() member functions:
template
void copy(const Range& input, OutputIterator output)
{
std::copy(input.begin(), input.end(), output);
}
Regards,
Nate
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