/* * Expression Template Matrix Library * * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * Demonstrate the use of view */ #include <iostream> #include "../include/exmat.h" using namespace std; using namespace exmat; // Define some vector and matrix types // A row vector of static size 3, with float as the element type typedef Vec<DenseRowVecCon<float, 3> > RVec3f; // A row column of static size 3, with float as the element type typedef Vec<DenseColVecCon<float, 3> > CVec3f; // A dense matrix of static size 3x2, with float as the element type typedef Mat<DenseMatCon<float, 3, 2> > Mat3x2f; // A dense matrix of static size 3x2, with float as the element type typedef Mat<DenseMatCon<float, 2, 3> > Mat2x3f; // A dense matrix of static size 3x3, with float as the element type typedef Mat<DenseMatCon<float, 3, 3> > Mat3x3f; int main() { // Reverse of a vector CVec3f v1("0 1 2"); cout << "v1 =\n" << v1; cout << "reverse of v1 =\n" << reverse(v1) << endl; // Views can be nested together cout << "reverse reverse of v1 =\n" << reverse(reverse(v1)) << endl; // Views can be used as l-value reverse(v1) = CVec3f("3 2 1"); cout << "new value of v1 =\n" << v1 << endl; // Note: View cannot be assigned with comma initialization // due to View lack of iterators //reverse(v1) = 3, 2, 1; // Transpose of matrix/vector // Vector transpose (row vector <-> column vector) RVec3f v2 = trans(v1); // Transform the column vector into row vector // dot product of a column vector as vT*v cout << "v1T * v1 = " << trans(v1) * v1 << endl << endl; // Matrix transpose Mat2x3f m1("0 1 2\n\ 3 4 5\n\ "); cout << "m1 =\n" << m1; cout << "m1T =\n" << trans(m1) << endl; // ATA product cout << "m1T * m1 =\n" << trans(m1) * m1 << endl; // Row/Column vector from a matrix // Extract a row vector from a matrix cout << "The first row of m1 = " << row(m1, 0); cout << "The second row of m1 = " << row(m1, 1); // Extract a column vector from a matrix cout << "The first column of m1 =\n" << col(m1, 0) << endl; // Co-factor and adjoint of a matrix Mat3x3f m2("0 1 2\n\ 3 4 5\n\ 6 7 8\n\ "); cout << "Co-factors of m2 =\n" << cofactors(m2) << endl; cout << "Adjoint of m2 =\n" << adjoint(m2) << endl; // A more complex example reverse(v1) = trans(row(trans(m1) * m1, 0)); cout << v1; return 0; }