My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
Matrix< T > Class Template Reference

#include <ftmpl_matrix.h>

Public Member Functions

 Matrix ()
 
 Matrix (int nr, int nc)
 
 Matrix (const Matrix< T > &M)
 
 ~Matrix ()
 
Matrix< T > & operator= (const Matrix< T > &M)
 
int rows () const
 
int columns () const
 
SubMatrix< Toperator[] (int i)
 
const SubMatrix< Toperator[] (int i) const
 
Toperator() (int row, int col)
 
T operator() (int row, int col) const
 
SubMatrix< Toperator() (int rmin, int rmax, int cmin, int cmax)
 
const SubMatrix< Toperator() (int rmin, int rmax, int cmin, int cmax) const
 
void swapRow (int i, int j)
 
void swapColumn (int i, int j)
 
void print (OSTREAM &s) const
 

Private Types

typedef TT_ptr
 

Private Member Functions

void printrow (OSTREAM &s, int i) const
 

Private Attributes

int NR
 
int NC
 
T ** elems
 

Friends

class SubMatrix< T >
 
OSTREAMoperator (OSTREAM &s, const Matrix< T > &M)
 

Detailed Description

template<class T>
class Matrix< T >

Definition at line 28 of file ftmpl_matrix.h.

Member Typedef Documentation

◆ T_ptr

template<class T >
typedef T* Matrix< T >::T_ptr
private

Definition at line 36 of file ftmpl_matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

template<class T >
Matrix< T >::Matrix ( )
inline

Definition at line 38 of file ftmpl_matrix.h.

38: NR(0), NC(0), elems(0) {}
int NR
Definition: ftmpl_matrix.h:31
T ** elems
Definition: ftmpl_matrix.h:32
int NC
Definition: ftmpl_matrix.h:31

◆ Matrix() [2/3]

template<class T >
Matrix< T >::Matrix ( int  nr,
int  nc 
)

Definition at line 6 of file ftmpl_matrix.cc.

6 : NR(nr), NC(nc)
7{
8 ASSERT( (nr > 0 && nc > 0) || (nr == 0 && nc == 0), "illegal index" );
9 if ( nr == 0 )
10 elems = 0;
11 else {
12 int i;
13 elems = new T_ptr[nr];
14 for ( i = 0; i < nr; i++ )
15 elems[i] = new T[nc];
16 }
17}
int i
Definition: cfEzgcd.cc:132
#define ASSERT(expression, message)
Definition: cf_assert.h:99
T * T_ptr
Definition: ftmpl_matrix.h:36
STATIC_VAR jList * T
Definition: janet.cc:30

◆ Matrix() [3/3]

template<class T >
Matrix< T >::Matrix ( const Matrix< T > &  M)

Definition at line 20 of file ftmpl_matrix.cc.

20 : NR(M.NR), NC(M.NC)
21{
22 if ( NR == 0 )
23 elems = 0;
24 else {
25 int i, j;
26 elems = new T_ptr[NR];
27 for ( i = 0; i < NR; i++ ) {
28 elems[i] = new T[NC];
29 for ( j = 0; j < NC; j++ )
30 elems[i][j] = M.elems[i][j];
31 }
32 }
33}
int j
Definition: facHensel.cc:110
#define M
Definition: sirandom.c:25

◆ ~Matrix()

template<class T >
Matrix< T >::~Matrix

Definition at line 36 of file ftmpl_matrix.cc.

37{
38 if ( elems != 0 ) {
39 int i;
40 for ( i = 0; i < NR; i++ )
41 delete [] elems[i];
42 delete [] elems;
43 }
44}

Member Function Documentation

◆ columns()

template<class T >
int Matrix< T >::columns ( ) const
inline

Definition at line 44 of file ftmpl_matrix.h.

44{ return NC; }

◆ operator()() [1/4]

template<class T >
SubMatrix< T > Matrix< T >::operator() ( int  rmin,
int  rmax,
int  cmin,
int  cmax 
)

Definition at line 96 of file ftmpl_matrix.cc.

97{
98 ASSERT( rmin > 0 && rmax <= NR && rmin <= rmax && cmin > 0 && cmax <= NC && cmin <= cmax , "illegal index" );
99 return SubMatrix<T>( rmin, rmax, cmin, cmax, *this );
100}
friend class SubMatrix< T >
Definition: ftmpl_matrix.h:57

◆ operator()() [2/4]

template<class T >
const SubMatrix< T > Matrix< T >::operator() ( int  rmin,
int  rmax,
int  cmin,
int  cmax 
) const

Definition at line 103 of file ftmpl_matrix.cc.

104{
105 ASSERT( rmin > 0 && rmax <= NR && rmin <= rmax && cmin > 0 && cmax <= NC && cmin <= cmax , "illegal index" );
106 return SubMatrix<T>( rmin, rmax, cmin, cmax, *this );
107}

◆ operator()() [3/4]

template<class T >
T & Matrix< T >::operator() ( int  row,
int  col 
)

Definition at line 82 of file ftmpl_matrix.cc.

83{
84 ASSERT( row > 0 && col > 0 && row <= NR && col <= NC, "illegal index" );
85 return elems[row-1][col-1];
86}

◆ operator()() [4/4]

template<class T >
T Matrix< T >::operator() ( int  row,
int  col 
) const

Definition at line 89 of file ftmpl_matrix.cc.

90{
91 ASSERT( row > 0 && col > 0 && row <= NR && col <= NC, "illegal index" );
92 return elems[row-1][col-1];
93}

◆ operator=()

template<class T >
Matrix< T > & Matrix< T >::operator= ( const Matrix< T > &  M)

Definition at line 47 of file ftmpl_matrix.cc.

48{
49 if ( this != &M ) {
50 int i, j;
51 if ( NR != M.NR || NC != M.NC ) {
52 for ( i = 0; i < NR; i++ )
53 delete [] elems[i];
54 delete [] elems;
55 NR = M.NR; NC = M.NC;
56 elems = new T_ptr[NR];
57 for ( i = 0; i < NR; i++ )
58 elems[i] = new T[NC];
59 }
60 for ( i = 0; i < NR; i++ )
61 for ( j = 0; j < NC; j++ )
62 elems[i][j] = M.elems[i][j];
63 }
64 return *this;
65}

◆ operator[]() [1/2]

template<class T >
SubMatrix< T > Matrix< T >::operator[] ( int  i)

Definition at line 68 of file ftmpl_matrix.cc.

69{
70 ASSERT( i > 0 && i <= NR, "illegal index" );
71 return SubMatrix<T>( i, i, 1, NC, *this );
72}

◆ operator[]() [2/2]

template<class T >
const SubMatrix< T > Matrix< T >::operator[] ( int  i) const

Definition at line 75 of file ftmpl_matrix.cc.

76{
77 ASSERT( i > 0 && i <= NR, "illegal index" );
78 return SubMatrix<T>( i, i, 1, NC, *this );
79}

◆ print()

template<class T >
void Matrix< T >::print ( OSTREAM s) const

Definition at line 147 of file ftmpl_matrix.cc.

148{
149 if ( NR == 0 )
150 s << "( )";
151 else if ( NR == 1 ) {
152 s << "( ";
153 printrow( s, 0 );
154 s << " )";
155 }
156 else {
157 int i;
158 s << "(\n";
159 printrow( s, 0 );
160 for ( i = 1; i < NR; i++ ) {
161 s << ",\n";
162 printrow( s, i );
163 }
164 s << "\n)";
165 }
166}
void printrow(OSTREAM &s, int i) const
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ printrow()

template<class T >
void Matrix< T >::printrow ( OSTREAM s,
int  i 
) const
private

Definition at line 138 of file ftmpl_matrix.cc.

139{
140 s << "( " << elems[i][0];
141 for ( int j = 1; j < NC; j++ )
142 s << ", " << elems[i][j];
143 s << " )";
144}

◆ rows()

template<class T >
int Matrix< T >::rows ( ) const
inline

Definition at line 43 of file ftmpl_matrix.h.

43{ return NR; }

◆ swapColumn()

template<class T >
void Matrix< T >::swapColumn ( int  i,
int  j 
)

Definition at line 122 of file ftmpl_matrix.cc.

123{
124 ASSERT( i > 0 && i <= NC && j > 0 && j <= NC, "illegal index" );
125 if ( i != j ) {
126 int k;
127 i--; j--;
128 for ( k = 0; k < NR; k++ ) {
129 T h = elems[k][i];
130 elems[k][i] = elems[k][j];
131 elems[k][j] = h;
132 }
133 }
134}
int k
Definition: cfEzgcd.cc:99
STATIC_VAR Poly * h
Definition: janet.cc:971

◆ swapRow()

template<class T >
void Matrix< T >::swapRow ( int  i,
int  j 
)

Definition at line 110 of file ftmpl_matrix.cc.

111{
112 ASSERT( i > 0 && i <= NR && j > 0 && j <= NR, "illegal index" );
113 if ( i != j ) {
114 i--; j--;
115 T * h = elems[i];
116 elems[i] = elems[j];
117 elems[j] = h;
118 }
119}

Friends And Related Function Documentation

◆ operator

template<class T >
OSTREAM & operator ( OSTREAM s,
const Matrix< T > &  M 
)
friend

◆ SubMatrix< T >

template<class T >
friend class SubMatrix< T >
friend

Definition at line 55 of file ftmpl_matrix.h.

Field Documentation

◆ elems

template<class T >
T** Matrix< T >::elems
private

Definition at line 32 of file ftmpl_matrix.h.

◆ NC

template<class T >
int Matrix< T >::NC
private

Definition at line 31 of file ftmpl_matrix.h.

◆ NR

template<class T >
int Matrix< T >::NR
private

Definition at line 31 of file ftmpl_matrix.h.


The documentation for this class was generated from the following files: