View

View is a powerful concept in exmat. It can be understood as a transformed representation of the data of a matrix. In order words, view is just a representation but didn't have any data inside, therefore memory coping is only performed at the time you assigning the view to another matrix.

You can even assign value to a view. Unless there is explicit statement in the documentation, otherwise all the views support assignment.

Example on using view: Example: View

Vector view

The reverse() function will reverse the order of elements in the vector
    Vec4 u("1 2 3 4");
    cout << exmat::reverse(u);  // Output: 4 3 2 1

    // Assigning values to the reversed vector
    exmat::reverse(u) = 5, 6, 7, 8;
    cout << u;                  // Output: 8 7 6 5

The subVec() function return a sub-vector:

    // Create a compile-time sized sub-vector start at index 0, with size equals 3
    Vec4 u("1 2 3 4");
    cout << exmat::subVec(u, Int2Type<0>, Int2Type<3>); // Output: 1 2 3

    // Create a run-time sized sub-vector start at index 1, with size equals 2
    cout << exmat::subVec(u, 1, 2);                     // Output: 2 3
Note:
Compile-time sized sub-vector is not supported in compiler without partial specialization.

Matrix view

The col() / row() function returns a column / row of a matrix
    exmat::Mat2x2f m("1 2
                      3 4");
    cout << exmat::col(m, Int2Type<0>); // Output: 1
                                        //         3
    cout << exmat::row(m, Int2Type<1>); // Output: 3 4

The subMat() function return the sub-matrix of a matrix. The first 2 parameter is the index for the top left corner of the sub-matrix, and the last 2 parameter is the size of the sub-matrix.

    exmat::Mat3x3f m("1 2 3
                      4 5 6
                      7 8 9");
    // Create a compile-time sized sub-matrix start at index (0,1), with size 2x2
    cout << exmat::subMat(m, Int2Type<0>, Int2Type<1>, Int2Type<2>, Int2Type<2>);
    // Output: 2 3
    //         5 6
    // Create a run-time sized sub-matrix start at index (1,0), with size 2x3
    cout << exmat::subMat(m, 1, 0, 2, 3);
    // Output: 4 5 6
    //         7 8 9

The trans() function return the transpose of a matrix/vector(turns a row vector into a column vector and vise versa).

    exmat::Mat2x2f m("1 2
                      3 4");
    cout << exmat::trans(m);    // Output: 1 3
                                //         2 4

The cofactors() function return the cofactors of a squared matrix.

    exmat::Mat3x3f m("0 1 3
                      2 2 5
                      3 1 2");
    cout << exmat::cofactors(m);    // Output: -1 11 -4
                                    //          1 -9  3
                                    //         -1  6 -2

The adjoint() function return the adjoint of a squared matrix.

    exmat::Mat2x2f m("0 1 3
                      2 2 5
                      3 1 2");
    cout << exmat::adjoint(m);  // Output: 1  1 -1
                                //        11 -9  6
                                //        -4  3 -2

Example on using adjoint to find the inverse: Example: Inverse

Go to the next section : Error handling


Generated on Sat May 6 23:12:04 2006 for Exmat by  doxygen 1.4.6-NO