MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::MsqMatrix< R, C > Class Template Reference

Fixed-size matrix class. More...

#include <MsqMatrix.hpp>

+ Inheritance diagram for MBMesquite::MsqMatrix< R, C >:

Public Types

enum  { ROWS = R, COLS = C }
typedef MsqMatrix< R, Cmy_type

Public Member Functions

 MsqMatrix ()
 MsqMatrix (double v)
 MsqMatrix (const double *v)
 MsqMatrix (const double v[R][C])
 MsqMatrix (const MsqMatrix< R, 1 > *c)
 MsqMatrix (const MsqMatrix< 1, C > *r)
 MsqMatrix (const char *s)
 MsqMatrix (const std::string &s)
 MsqMatrix (const MsqMatrix< R+1, C+1 > &p_m, unsigned p_r, unsigned p_c)
MsqMatrix< R, C > & operator= (double v)
MsqMatrix< R, C > & operator= (const double *v)
MsqMatrix< R, C > & operator= (const char *s)
MsqMatrix< R, C > & operator= (const std::string &s)
double & operator() (unsigned r, unsigned c)
double operator() (unsigned r, unsigned c) const
double * data ()
const double * data () const
void zero ()
void identity ()
void set (double v)
void set (const double *v)
void set (const double v[R][C])
void set (const char *s)
void set (const std::string &s)
void diag (double v)
void diag (const double *v)
void make_minor (const MsqMatrix< R+1, C+1 > &m, unsigned r, unsigned c)
 Extract minor of a matrix and assign to *this.
MsqMatrix< R, C > & assign_add_transpose (const MsqMatrix< C, R > &other)
MsqMatrix< R, C > & assign_product (double s, const MsqMatrix< R, C > &m)
MsqMatrix< R, C > & assign_add_product (double s, const MsqMatrix< R, C > &m)
MsqMatrix< R, C > & assign_multiply_elements (const MsqMatrix< R, C > &m)
MsqMatrix< R, C > & operator+= (const MsqMatrix< R, C > &other)
MsqMatrix< R, C > & operator-= (const MsqMatrix< R, C > &other)
MsqMatrix< R, C > & operator+= (double scalar)
MsqMatrix< R, C > & operator-= (double scalar)
MsqMatrix< R, C > & operator*= (double scalar)
MsqMatrix< R, C > & operator/= (double scalar)
MsqMatrix< 1, Crow (unsigned r) const
MsqMatrix< R, 1 > column (unsigned c) const
MsqMatrix< 1, R > column_transpose (unsigned c) const
void set_row (unsigned r, const MsqMatrix< 1, C > &v)
void add_row (unsigned r, const MsqMatrix< 1, C > &v)
void set_row_transpose (unsigned r, const MsqMatrix< C, 1 > &v)
void set_rows (const MsqMatrix< 1, C > *v)
void set_column (unsigned c, const MsqMatrix< R, 1 > &v)
void add_column (unsigned c, const MsqMatrix< R, 1 > &v)
void set_column_transpose (unsigned c, const MsqMatrix< 1, R > &v)
void set_columns (const MsqMatrix< R, 1 > *v)

Protected Attributes

double m [R *C]

Detailed Description

template<unsigned R, unsigned C>
class MBMesquite::MsqMatrix< R, C >

Fixed-size matrix class.

This class implements a fixed-size 2-dimensional matrix. The actual size is specified with template parameters.

Definition at line 51 of file MsqMatrix.hpp.


Member Typedef Documentation

template<unsigned R, unsigned C>
typedef MsqMatrix< R, C > MBMesquite::MsqMatrix< R, C >::my_type

Definition at line 57 of file MsqMatrix.hpp.


Member Enumeration Documentation

template<unsigned R, unsigned C>
anonymous enum
Enumerator:
ROWS 
COLS 

Definition at line 59 of file MsqMatrix.hpp.

    {
        ROWS = R,
        COLS = C
    };

Constructor & Destructor Documentation

template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( ) [inline]

Constructor for uninitialized matrix

Definition at line 66 of file MsqMatrix.hpp.

{}
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( double  v) [inline]

Initialize diagonal values, zero others

Definition at line 68 of file MsqMatrix.hpp.

    {
        diag( v );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const double *  v) [inline]

Initialize to an array of values

Definition at line 73 of file MsqMatrix.hpp.

    {
        set( v );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const double  v[R][C]) [inline]

Initialize from 2D array

Definition at line 78 of file MsqMatrix.hpp.

    {
        set( v );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const MsqMatrix< R, 1 > *  c) [inline]

Initialize with column vectors

Definition at line 83 of file MsqMatrix.hpp.

    {
        set_columns( c );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const MsqMatrix< 1, C > *  r) [inline]

Initialize with row vectors

Definition at line 88 of file MsqMatrix.hpp.

    {
        set_rows( r );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const char *  s) [inline]

Parse initial values from string

Definition at line 93 of file MsqMatrix.hpp.

    {
        set( s );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const std::string &  s) [inline]

Parse initial values from string

Definition at line 98 of file MsqMatrix.hpp.

    {
        set( s );
    }
template<unsigned R, unsigned C>
MBMesquite::MsqMatrix< R, C >::MsqMatrix ( const MsqMatrix< R+1, C+1 > &  p_m,
unsigned  p_r,
unsigned  p_c 
) [inline]

Initialize to the minor of a larger matrix This matrix is the passed matrix with the specified row and column removed.

Definition at line 106 of file MsqMatrix.hpp.

    {
        make_minor( p_m, p_r, p_c );
    }

Member Function Documentation

template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::add_column ( unsigned  c,
const MsqMatrix< R, 1 > &  v 
) [inline]

Definition at line 712 of file MsqMatrix.hpp.

References moab::R.

Referenced by MBMesquite::do_numerical_hessian(), and MBMesquite::pluseq_outer_product_I().

{
    for( unsigned i = 0; i < R; ++i )
        operator()( i, c ) += v( i, 0 );
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::add_row ( unsigned  r,
const MsqMatrix< 1, C > &  v 
) [inline]

Definition at line 687 of file MsqMatrix.hpp.

References C.

Referenced by MBMesquite::do_numerical_hessian(), and MBMesquite::pluseq_I_outer_product().

{
    for( unsigned i = 0; i < C; ++i )
        operator()( r, i ) += v( 0, i );
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::assign_add_product ( double  s,
const MsqMatrix< R, C > &  m 
) [inline]

*this += s*m

Definition at line 785 of file MsqMatrix.hpp.

References C, MBMesquite::MsqMatrix< R, C >::data(), and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] += s * other.data()[i];
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::assign_add_transpose ( const MsqMatrix< C, R > &  other) [inline]

*this += transpose(other)

Definition at line 760 of file MsqMatrix.hpp.

References C, and moab::R.

{
    for( unsigned r = 0; r < R; ++r )
        for( unsigned c = 0; c < C; ++c )
            operator()( r, c ) += other( c, r );
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::assign_multiply_elements ( const MsqMatrix< R, C > &  m) [inline]

multiply each element by the cooresponding element in m

Definition at line 769 of file MsqMatrix.hpp.

References C, MBMesquite::MsqMatrix< R, C >::data(), and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] *= other.data()[i];
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::assign_product ( double  s,
const MsqMatrix< R, C > &  m 
) [inline]

*this = s*m

Definition at line 777 of file MsqMatrix.hpp.

References C, MBMesquite::MsqMatrix< R, C >::data(), and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] = s * other.data()[i];
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< 1, R > MBMesquite::MsqMatrix< R, C >::column_transpose ( unsigned  c) const [inline]

Definition at line 740 of file MsqMatrix.hpp.

References moab::R.

{
    MsqMatrix< 1, R > result;
    for( unsigned i = 0; i < R; ++i )
        result( 0, i ) = operator()( i, c );
    return result;
}
template<unsigned R, unsigned C>
const double* MBMesquite::MsqMatrix< R, C >::data ( ) const [inline]

Definition at line 144 of file MsqMatrix.hpp.

    {
        return m;
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::diag ( double  v) [inline]

Set diagonal value to passed values, others to zero.

Definition at line 481 of file MsqMatrix.hpp.

References C, and moab::R.

Referenced by MBMesquite::MsqMatrix< 3, 3 >::identity(), and MBMesquite::MsqMatrix< 3, 3 >::MsqMatrix().

{
    // for (unsigned r = 0; r < R; ++r)
    //  for (unsigned c = 0; c < C; ++c)
    //    operator()(r,c) = (r == c) ? v : 0.0;

    switch( R )
    {
        default:
            for( unsigned r = 4; r < R; ++r )
                switch( C )
                {
                    default:
                        for( unsigned k = 4; k < C; ++k )
                            operator()( r, k ) = r == k ? v : 0.0;
                    case 4:
                        operator()( r, 3 ) = 0.0;
                    case 3:
                        operator()( r, 2 ) = 0.0;
                    case 2:
                        operator()( r, 1 ) = 0.0;
                    case 1:
                        operator()( r, 0 ) = 0.0;
                }
        case 4:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 3, k ) = 0.0;
                case 4:
                    operator()( 3, 3 ) = v;
                case 3:
                    operator()( 3, 2 ) = 0.0;
                case 2:
                    operator()( 3, 1 ) = 0.0;
                case 1:
                    operator()( 3, 0 ) = 0.0;
            }
        case 3:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 2, k ) = 0.0;
                case 4:
                    operator()( 2, 3 ) = 0.0;
                case 3:
                    operator()( 2, 2 ) = v;
                case 2:
                    operator()( 2, 1 ) = 0.0;
                case 1:
                    operator()( 2, 0 ) = 0.0;
            }
        case 2:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 1, k ) = 0.0;
                case 4:
                    operator()( 1, 3 ) = 0.0;
                case 3:
                    operator()( 1, 2 ) = 0.0;
                case 2:
                    operator()( 1, 1 ) = v;
                case 1:
                    operator()( 1, 0 ) = 0.0;
            }
        case 1:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 0, k ) = 0.0;
                case 4:
                    operator()( 0, 3 ) = 0.0;
                case 3:
                    operator()( 0, 2 ) = 0.0;
                case 2:
                    operator()( 0, 1 ) = 0.0;
                case 1:
                    operator()( 0, 0 ) = v;
            }
    }
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::diag ( const double *  v) [inline]

Set diagonal values to passed values, others to zero.

Definition at line 569 of file MsqMatrix.hpp.

References C, and moab::R.

{
    // for (unsigned r = 0; r < R; ++r)
    //  for (unsigned c = 0; c < C; ++c)
    //    operator()(r,c) = (r == c) ? v[r] : 0.0;

    switch( R )
    {
        default:
            for( unsigned r = 4; r < R; ++r )
                switch( C )
                {
                    default:
                        for( unsigned k = 4; k < C; ++k )
                            operator()( r, k ) = r == k ? v[r] : 0.0;
                    case 4:
                        operator()( r, 3 ) = 0.0;
                    case 3:
                        operator()( r, 2 ) = 0.0;
                    case 2:
                        operator()( r, 1 ) = 0.0;
                    case 1:
                        operator()( r, 0 ) = 0.0;
                }
        case 4:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 3, k ) = 0.0;
                case 4:
                    operator()( 3, 3 ) = v[3];
                case 3:
                    operator()( 3, 2 ) = 0.0;
                case 2:
                    operator()( 3, 1 ) = 0.0;
                case 1:
                    operator()( 3, 0 ) = 0.0;
            }
        case 3:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 2, k ) = 0.0;
                case 4:
                    operator()( 2, 3 ) = 0.0;
                case 3:
                    operator()( 2, 2 ) = v[2];
                case 2:
                    operator()( 2, 1 ) = 0.0;
                case 1:
                    operator()( 2, 0 ) = 0.0;
            }
        case 2:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 1, k ) = 0.0;
                case 4:
                    operator()( 1, 3 ) = 0.0;
                case 3:
                    operator()( 1, 2 ) = 0.0;
                case 2:
                    operator()( 1, 1 ) = v[1];
                case 1:
                    operator()( 1, 0 ) = 0.0;
            }
        case 1:
            switch( C )
            {
                default:
                    for( unsigned k = 4; k < C; ++k )
                        operator()( 0, k ) = 0.0;
                case 4:
                    operator()( 0, 3 ) = 0.0;
                case 3:
                    operator()( 0, 2 ) = 0.0;
                case 2:
                    operator()( 0, 1 ) = 0.0;
                case 1:
                    operator()( 0, 0 ) = v[0];
            }
    }
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::identity ( ) [inline]

Definition at line 153 of file MsqMatrix.hpp.

    {
        diag( 1.0 );
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::make_minor ( const MsqMatrix< R+1, C+1 > &  M,
unsigned  r,
unsigned  c 
) [inline]

Extract minor of a matrix and assign to *this.

Set this matrix to the minor of a larger matrix

Given a matrix m, a row r and an column c, set *this to the matrix that is m with row r and column c deleted.

Definition at line 662 of file MsqMatrix.hpp.

References C, and moab::R.

Referenced by MBMesquite::MsqMatrix< 3, 3 >::MsqMatrix(), and MBMesquite::MsqMatrixA< R, C >::MsqMatrixA().

{
    for( unsigned i = 0; i < r; ++i )
    {
        for( unsigned j = 0; j < c; ++j )
            operator()( i, j ) = M( i, j );
        for( unsigned j = c; j < C; ++j )
            operator()( i, j ) = M( i, j + 1 );
    }
    for( unsigned i = r; i < R; ++i )
    {
        for( unsigned j = 0; j < c; ++j )
            operator()( i, j ) = M( i + 1, j );
        for( unsigned j = c; j < C; ++j )
            operator()( i, j ) = M( i + 1, j + 1 );
    }
}
template<unsigned R, unsigned C>
double& MBMesquite::MsqMatrix< R, C >::operator() ( unsigned  r,
unsigned  c 
) [inline]

Definition at line 132 of file MsqMatrix.hpp.

    {
        return m[r * C + c];
    }
template<unsigned R, unsigned C>
double MBMesquite::MsqMatrix< R, C >::operator() ( unsigned  r,
unsigned  c 
) const [inline]

Definition at line 136 of file MsqMatrix.hpp.

    {
        return m[r * C + c];
    }
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::operator*= ( double  scalar) [inline]

Definition at line 825 of file MsqMatrix.hpp.

References C, and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] *= s;
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::operator+= ( const MsqMatrix< R, C > &  other) [inline]

Definition at line 793 of file MsqMatrix.hpp.

References C, MBMesquite::MsqMatrix< R, C >::data(), and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] += other.data()[i];
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::operator+= ( double  scalar) [inline]

Definition at line 809 of file MsqMatrix.hpp.

References C, and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] += s;
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::operator-= ( const MsqMatrix< R, C > &  other) [inline]

Definition at line 801 of file MsqMatrix.hpp.

References C, MBMesquite::MsqMatrix< R, C >::data(), and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] -= other.data()[i];
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::operator-= ( double  scalar) [inline]

Definition at line 817 of file MsqMatrix.hpp.

References C, and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] -= s;
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C > & MBMesquite::MsqMatrix< R, C >::operator/= ( double  scalar) [inline]

Definition at line 833 of file MsqMatrix.hpp.

References C, and moab::R.

{
    for( unsigned i = 0; i < R * C; ++i )
        m[i] /= s;
    return *this;
}
template<unsigned R, unsigned C>
MsqMatrix< R, C >& MBMesquite::MsqMatrix< R, C >::operator= ( double  v) [inline]

Definition at line 111 of file MsqMatrix.hpp.

    {
        set( v );
        return *this;
    }
template<unsigned R, unsigned C>
MsqMatrix< R, C >& MBMesquite::MsqMatrix< R, C >::operator= ( const double *  v) [inline]

Definition at line 116 of file MsqMatrix.hpp.

    {
        set( v );
        return *this;
    }
template<unsigned R, unsigned C>
MsqMatrix< R, C >& MBMesquite::MsqMatrix< R, C >::operator= ( const char *  s) [inline]

Definition at line 121 of file MsqMatrix.hpp.

    {
        set( s );
        return *this;
    }
template<unsigned R, unsigned C>
MsqMatrix< R, C >& MBMesquite::MsqMatrix< R, C >::operator= ( const std::string &  s) [inline]

Definition at line 126 of file MsqMatrix.hpp.

    {
        set( s );
        return *this;
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set ( double  v) [inline]

Definition at line 157 of file MsqMatrix.hpp.

Referenced by MBMesquite::MsqMatrixA< R, C >::MsqMatrixA().

    {
        for( unsigned i = 0; i < R * C; ++i )
            m[i] = v;
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set ( const double *  v) [inline]

Definition at line 162 of file MsqMatrix.hpp.

    {
        for( unsigned i = 0; i < R * C; ++i )
            m[i] = v[i];
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set ( const double  v[R][C]) [inline]

Definition at line 473 of file MsqMatrix.hpp.

References C, and moab::R.

{
    for( unsigned r = 0; r < R; ++r )
        for( unsigned c = 0; c < C; ++c )
            operator()( r, c ) = v[r][c];
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set ( const char *  s) [inline]

Definition at line 168 of file MsqMatrix.hpp.

    {
        std::istringstream i( s );
        i >> *this;
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set ( const std::string &  s) [inline]

Definition at line 173 of file MsqMatrix.hpp.

    {
        set( s.c_str() );
    }
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set_column_transpose ( unsigned  c,
const MsqMatrix< 1, R > &  v 
) [inline]

Definition at line 718 of file MsqMatrix.hpp.

References moab::R.

{
    for( unsigned i = 0; i < R; ++i )
        operator()( i, c ) = v( 0, i );
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set_columns ( const MsqMatrix< R, 1 > *  v) [inline]

Definition at line 724 of file MsqMatrix.hpp.

References C.

Referenced by MBMesquite::MsqMatrix< 3, 3 >::MsqMatrix().

{
    for( unsigned c = 0; c < C; ++c )
        set_column( c, v[c] );
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set_row ( unsigned  r,
const MsqMatrix< 1, C > &  v 
) [inline]

Definition at line 681 of file MsqMatrix.hpp.

References C.

Referenced by MBMesquite::TMPQualityMetric::evaluate_surface_common(), IdealShapeXY::get_surface_target(), TriTauMetric::matrix(), LVQDTargetTest::target(), and MsqMatrixTest::test_get_set_row().

{
    for( unsigned i = 0; i < C; ++i )
        operator()( r, i ) = v( 0, i );
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set_row_transpose ( unsigned  r,
const MsqMatrix< C, 1 > &  v 
) [inline]

Definition at line 693 of file MsqMatrix.hpp.

References C.

{
    for( unsigned i = 0; i < C; ++i )
        operator()( r, i ) = v( i, 0 );
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::set_rows ( const MsqMatrix< 1, C > *  v) [inline]

Definition at line 699 of file MsqMatrix.hpp.

References moab::R.

Referenced by MBMesquite::MsqMatrix< 3, 3 >::MsqMatrix().

{
    for( unsigned r = 0; r < R; ++r )
        set_row( r, v[r] );
}
template<unsigned R, unsigned C>
void MBMesquite::MsqMatrix< R, C >::zero ( ) [inline]

Member Data Documentation

List of all members.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines