This example shows how to make use of the LatBuilder::IndexMap class to permute vector elements.
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include "latbuilder/IndexMap.h"
#include "latbuilder/TextStream.h"
class ReverseMapper {
public:
typedef size_t size_type;
ReverseMapper(size_type size): m_size(size) { }
size_type size() const { return m_size; }
size_type operator() (size_type i) const { return m_size - i - 1; }
private:
size_type m_size;
};
template <typename VEC>
void set_elems(VEC& vec)
{
for (unsigned i = 0; i < vec.size(); i++)
vec[i] = 10 + i;
}
int main(int argc, char* argv[])
{
using LatBuilder::TextStream::operator<<;
boost::numeric::ublas::vector<unsigned> vec(10);
std::cout << "==> setting original vector" << std::endl;
set_elems(vec);
std::cout << " orginal vector: " << vec << std::endl;
std::cout << "reversed vector: " << rvec << std::endl;
std::cout << "==> setting reversed vector" << std::endl;
set_elems(rvec);
std::cout << " orginal vector: " << vec << std::endl;
std::cout << "reversed vector: " << rvec << std::endl;
return 0;
}