Example: Dimension

/*
 * Expression Template Matrix Library
 *
 * Copyright (C) 2004 - 2004 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 dimension information
 */

#include <iostream>
#include "../include/exmat.h"

using namespace std;
using namespace exmat;

// Define some vector and matrix types

// A row vector of dynamic size, with float as the element type
typedef Vec<DenseRowVecCon<float, 0> > RVecf;
// A column vector of dynamic size, with float as the element type
typedef Vec<DenseColVecCon<float, 0> > CVecf;
// 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 matrix of dynamic size, with float as the element type
typedef Mat<DenseMatCon<float, 0, 0> > Matf;

int main()
{
    // Get the dimension of vector and matrix

    // Size of vector (number of elements)
    RVec3f v1;
    cout << "Size of RVec3f: " << v1.size() << endl << endl;
    CVec3f v2;
    cout << "Size of CVec3f: " << v2.size() << endl << endl;

    // Dimension of vector
    cout << "RVec3f have rows: " << v1.rows() << endl;
    cout << "RVec3f have columns: " << v1.cols() << endl << endl;

    cout << "CVec3f have rows: " << v2.rows() << endl;
    cout << "CVec3f have columns: " << v2.cols() << endl << endl;

    // Dimension of matrix
    Mat3x2f m1;
    Mat2x3f m2;
    cout << "Mat3x2f have rows: " << m1.rows() << endl;
    cout << "Mat3x2f have columns: " << m1.cols() << endl << endl;

    cout << "Mat2x3f have rows: " << m2.rows() << endl;
    cout << "Mat2x3f have columns: " << m2.cols() << endl << endl;


    // Get/Set the dimension of dynamic matrix
    Matf m3;
    // Resize the matrix with 10 rows and 5 columns
    // Note that the resizing operation will not preserve the content
    m3.resize(10, 5);
    cout << "Dynamic rows: " << m3.rows() << endl;
    cout << "Dynamic columns: " << m3.cols() << endl << endl;

    // Resize the matrix again
    m3.resizeRow(3);
    m3.resizeCol(3);
    cout << "Dynamic rows: " << m3.rows() << endl;
    cout << "Dynamic columns: " << m3.cols() << endl << endl;


    // Dimension of expression

    // Vector expression
    cout << "Size of RVec3f + RVec3f: " << (v1 + v1).size() << endl << endl;

    // Matrix expression
    cout << "Rows of Mat3x2f * Mat2x3f: " << (m1 * m2).rows() << endl;
    cout << "Cols of Mat3x2f * Mat2x3f: " << (m1 * m2).cols() << endl << endl;

    return 0;
}

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