Logo MTL4

reorder(v)

Returns reorder matrix from corresponding vector.

See: mtl::matrix::permutation

P= reorder(v);

For example:

#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
    using namespace mtl;

    double           array[][3]= {{1., 2., 3.}, {4., 5., 6.}, {7., 8., 9.}};
    dense2D<double>  A(array), B2, B3;

    // Creating a reordering matrix from a vector (or an array respectively)
    int indices[]= {2, 1};
    matrix::traits::reorder<>::type R= matrix::reorder(indices);
    std::cout << "\nR =\n" << R;    

    // Reorder rows
    B2= R * A;
    std::cout << "\nR * A =\n" << B2;
    
    // Reorder columns
    B3= B2 * trans(R);
    std::cout << "\nB2 * trans(R) =\n" << B3;
    
    dense_vector<double> v(array[2]), w(R * v);
    std::cout << "\nR * v =\n" << w << "\n";
    
    return 0;
}

For a more detailed explanation see Permutations and Reordering.

Return to Overview                                Table of Content                               


reorder(v) -- MTL 4 -- Peter Gottschling and Andrew Lumsdaine -- Gen. with rev. 7542 on 7 Apr 2011 by doxygen 1.5.9 -- © 2010 by SimuNova UG.