14 #include <gtest/gtest.h>
17 using namespace kome::core;
22 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
23 #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
30 : m_row( row ), m_col( col ),
31 m_array( ( row == 0 || col == 0 ) ?
NULL : new double[ row * col ] ) {
39 : m_row( mat.m_row ), m_col( mat.m_col ),
40 m_array( mat.m_array ==
NULL ?
NULL : new double[ mat.m_row * mat.m_col ] ) {
67 throw FMT(
"This is not a square matrix." );
70 throw FMT(
"Matrix size is illegal." );
78 for(
unsigned int i = 0; i <
m_col; i++ ) {
89 throw FMT(
"This is not a square matrix." );
92 throw FMT(
"Matrix size is illegal." );
97 throw FMT(
"The specified element does not exist. [row=%d, col=%d]", row, col );
102 for(
unsigned int i = 0; i <
m_row - 1; i++ ) {
103 int r = ( i < row ) ? i : i + 1;
104 for(
unsigned int j = 0; j <
m_col - 1; j++ ) {
105 int c = ( j < col ) ? j : j + 1;
113 if( ( row + col ) % 2 != 0 ) {
124 throw FMT(
"This is not a square matrix." );
127 throw FMT(
"Matrix size is illegal." );
133 throw FMT(
"There isn't an inverse matrix." );
142 for(
unsigned int i = 0; i <
m_row; i++ ) {
143 for(
unsigned int j = 0; j <
m_col; j++ ) {
161 for(
unsigned int i = 0; i <
m_row; i++ ) {
163 for(
unsigned int j = 0; j <
m_col; j++ ) {
164 elm += (*this)( i, j ) * v( j );
176 throw FMT(
"Matrix size is illegal." );
190 throw FMT(
"The specified element does not exist. [row=%d, col=%d]", row, col );
200 throw FMT(
"Matrix size is illegal." );
207 for(
unsigned int i = 0; i < size; i++ ) {
218 throw FMT(
"Matrix size is illegal." );
225 for(
unsigned int i = 0; i < size; i++ ) {
238 for(
unsigned int i = 0; i < size; i++ ) {
251 for(
unsigned int i = 0; i < size; i++ ) {
278 throw FMT(
"Matrix size is illegal." );
285 unsigned int num = this->
m_col;
288 for(
unsigned int i = 0; i < this->
m_row; i++ ) {
289 for(
unsigned int j = 0; j < m.
m_col; j++ ) {
291 for(
unsigned int k = 0; k < num; k++ ) {
334 MatrixTest() : m_A( 2, 2 ), m_B( 2, 2 ), m_C( 3, 2 ), m_D( 2, 3 ) {
338 virtual void SetUp() {
373 ASSERT_EQ( A.getRowSize(), 3 );
380 ASSERT_EQ( A.getColSize(), 5 );
388 ASSERT_DOUBLE_EQ( 6.0, C( 0, 0 ) );
389 ASSERT_DOUBLE_EQ( 8.0, C( 0, 1 ) );
390 ASSERT_DOUBLE_EQ( 10.0, C( 1, 0 ) );
391 ASSERT_DOUBLE_EQ( 12.0, C( 1, 1 ) );
394 ASSERT_ANY_THROW( m_A + m_C );
Matrix operator-(const Matrix &m)
matrix subtraction
Matrix & operator-=(const Matrix &m)
matrix subtraction
double cofactor(const unsigned int row, const unsigned int col)
calculates cofactor (This matrix must be a square matrix.)
double & operator()(const unsigned int row, const unsigned int col)
gets reference of value of specified element
unsigned int getRowSize()
gets row size of matrix
Matrix operator=(const Matrix &m)
copy matrix
Matrix operator+(const Matrix &m)
matrix addition
Matrix & operator+=(const Matrix &m)
matrix addition
virtual ~Matrix()
destructor
unsigned int getColSize()
gets col size of matrix
unsigned int getDimention()
gets the dimention size of vector
Vector multiply(Vector &v)
multiplies vector
interfaces of Matrix class
double det()
calculates determinant. (This matrix must be a square matrix.)
Matrix operator*(const Matrix &m)
matrix multiplication
Matrix invert()
gets inverse matrix (This matrix must be a square matrix.)
Matrix & operator/=(const double k)
scalar division
void fillzero(void *p, size_t n)
This function fills a block of memory zeros.
Matrix & operator*=(const double k)
scalar multiplication
Matrix operator/(const double k)
scalar division
Matrix(const unsigned int row, const unsigned int col)
constructor