/* * Matrix.cpp * * Created on: Jun 25, 2010 * Author: crueger */ #include "Matrix.hpp" #include "Helpers/Assert.hpp" #include "Exceptions/NotInvertibleException.hpp" #include "Helpers/fast_functions.hpp" #include "Helpers/Assert.hpp" #include "vector.hpp" #include #include #include using namespace std; Matrix::Matrix() { content = gsl_matrix_calloc(NDIM, NDIM); } Matrix::Matrix(const double* src){ content = gsl_matrix_alloc(NDIM, NDIM); set(0,0, src[0]); set(1,0, src[1]); set(2,0, src[2]); set(0,1, src[3]); set(1,1, src[4]); set(2,1, src[5]); set(0,2, src[6]); set(1,2, src[7]); set(2,2, src[8]); } Matrix::Matrix(const Matrix &src){ content = gsl_matrix_alloc(NDIM, NDIM); gsl_matrix_memcpy(content,src.content); } Matrix::Matrix(gsl_matrix* _content) : content(_content) {} Matrix::~Matrix() { gsl_matrix_free(content); } void Matrix::one(){ gsl_matrix_free(content); content = gsl_matrix_calloc(NDIM, NDIM); for(int i = NDIM;i--;){ set(i,i,1.); } } Matrix &Matrix::operator=(const Matrix &src){ if(&src!=this){ gsl_matrix_memcpy(content,src.content); } return *this; } Matrix &Matrix::operator+=(const Matrix &rhs){ gsl_matrix_add(content, rhs.content); return *this; } Matrix &Matrix::operator-=(const Matrix &rhs){ gsl_matrix_sub(content, rhs.content); return *this; } Matrix &Matrix::operator*=(const Matrix &rhs){ (*this) = (*this)*rhs; return *this; } Matrix Matrix::operator+(const Matrix &rhs) const{ Matrix tmp = *this; tmp+=rhs; return tmp; } Matrix Matrix::operator-(const Matrix &rhs) const{ Matrix tmp = *this; tmp-=rhs; return tmp; } Matrix Matrix::operator*(const Matrix &rhs) const{ gsl_matrix *res = gsl_matrix_alloc(NDIM, NDIM); gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, this->content, rhs.content, 0.0, res); return Matrix(res); } double &Matrix::at(size_t i, size_t j){ ASSERT(i>=0&&i=0&&j=0&&i=0&&j=0&&i=0&&j