Logo MTL4

A[range1][range2]

returns a submatrix of matrix A with rows in range1 and cols in range2.

For example, if range1 is a number, the returntype is a row-vector.

using mtl::iall;
dense_vector<cdouble, vector::parameters<tag::row_major> > v_r(A[0][iall]);

If the range2 is a number, the returntype is a col-vector.

using mtl::iall;
dense_vector<cdouble>   v_r= dense_vector<cdouble>(A[iall][0]);

If range1 and range2 are numbers, the returntype is a scalar.

cdouble C= A[0][0];

If range1 and range2 are regions, the resulttype is a matrix.

irange row(2, 4), col(1, 7);
dense2D<cdouble> B= A[row][col];

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

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

    typedef std::complex<double>      cdouble;
    const unsigned                    xd= 2, yd= 5, n= xd * yd;
    dense2D<cdouble>                  A(n, n);
    matrix::laplacian_setup(A, xd, yd); 

    // Fill imaginary part of the matrix
    A*= cdouble(1, -1);
    std::cout << "A is\n" << with_format(A, 7, 1) << "\n";

    std::cout << "sub_matrix(A, 2, 4, 1, 7) is\n" 
              << with_format(sub_matrix(A, 2, 4, 1, 7), 7, 1) << "\n";

    //col-vector from matrix
    dense_vector<cdouble>   v_c(A[iall][0]);

    std::cout << "col-vector v_c is\n" << v_c << "\n";

    //row-vector from matrix
    dense_vector<cdouble, vector::parameters<tag::row_major> > v_r(A[0][iall]);

    std::cout << "row-vector v_r is\n" << v_r << "\n";

    //row-vector in matrix
    RowInMatrix<dense2D<cdouble> >::type v_r2(A[0][iall]);

    std::cout << "row-vector v_r2 is\n" << v_r2 << "\n";

    //submatrix from matrix per begin and end of row and column
    dense2D<cdouble> B= sub_matrix(A, 2, 4, 1, 7);
    B[1][2]= 88;

    std::cout << "B is\n" << B << "\n";

    //submatrix from matrix per irange
    using mtl::irange;
    irange row(2, 4), col(1, 7);
    dense2D<cdouble> B1= A[row][col];

    std::cout << "B1 is\n" << B1 << "\n";

    //scalar from matrix
    cdouble C= A[1][1];

    std::cout << "C is\n" << C << "\n";

    return 0;
}

Return to Overview                                Table of Content                               


A[range1][range2] -- MTL 4 -- Peter Gottschling and Andrew Lumsdaine -- Gen. with rev. 7542 on 7 Apr 2011 by doxygen 1.5.9 -- © 2010 by SimuNova UG.