#define uge_gm_tmpl_mnt template #define uge_gm_tmpl_mn template uge_gm_tmpl_mn MatrixMxN::MatrixMxN() { this->fill(0.0); } uge_gm_tmpl_mn MatrixMxN::MatrixMxN(double k) { this->fill(k); } uge_gm_tmpl_mn MatrixMxN::MatrixMxN(double scalars[M][N]) { this->fill(scalars); } uge_gm_tmpl_mn MatrixMxN::~MatrixMxN() { } uge_gm_tmpl_mnt GenericMatrix::~GenericMatrix() { } uge_gm_tmpl_mnt T &GenericMatrix::setScalar(unsigned i, unsigned j, double value) { _scalars[i][j] = value; return *getThis(); } uge_gm_tmpl_mnt double GenericMatrix::getScalar(unsigned i, unsigned j) const { return _scalars[i][j]; } uge_gm_tmpl_mnt bool GenericMatrix::isNull() const { return equal(T()); } uge_gm_tmpl_mnt bool GenericMatrix::equal(const T &other) const { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { if (_scalars[i][j] != other._scalars[i][j]) { return false; } } } return true; } uge_gm_tmpl_mnt T &GenericMatrix::fill(double k) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] = k; } } return *getThis(); } uge_gm_tmpl_mnt T &GenericMatrix::fill(double scalars[M][N]) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] = scalars[i][j]; } } return *getThis(); } uge_gm_tmpl_mnt T &GenericMatrix::add(double k) { return add(T(k)); } uge_gm_tmpl_mnt T &GenericMatrix::add(double scalars[M][N]) { return add(T(scalars)); } uge_gm_tmpl_mnt T &GenericMatrix::add(const T &other) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] += other._scalars[i][j]; } } return *getThis(); } uge_gm_tmpl_mnt T &GenericMatrix::sub(double k) { return sub(T(k)); } uge_gm_tmpl_mnt T &GenericMatrix::sub(double scalars[M][N]) { return sub(T(scalars)); } uge_gm_tmpl_mnt T &GenericMatrix::sub(const T &other) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] -= other._scalars[i][j]; } } return *getThis(); } uge_gm_tmpl_mnt T &GenericMatrix::mult(double k) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] *= k; } } return *getThis(); } uge_gm_tmpl_mnt T &GenericMatrix::mult(double scalars[M][N]) { return mult(T(scalars)); } uge_gm_tmpl_mnt T &GenericMatrix::mult(const T &other) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] *= other._scalars[i][j]; } } return *getThis(); } uge_gm_tmpl_mnt uge_gm_tmpl_p MatrixMxN GenericMatrix::multMatrix(double scalars[N][P]) { return multMatrix(MatrixMxN(scalars)); } uge_gm_tmpl_mnt uge_gm_tmpl_p MatrixMxN GenericMatrix::multMatrix(const MatrixMxN& other) { MatrixMxN m; for (int i = 0; i < M; ++i) { for (int j = 0; j < P; ++j) { double t = 0; for (int k = 0; k < N; ++k) { t += _scalars[i][k] * other._scalars[k][j]; } m._scalars[i][j] = t; } } return m; } uge_gm_tmpl_mnt T &GenericMatrix::div(double k) { return div(T(k)); } uge_gm_tmpl_mnt T &GenericMatrix::div(double scalars[M][N]) { return div(T(scalars)); } uge_gm_tmpl_mnt T &GenericMatrix::div(const T &other) { for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { _scalars[i][j] /= other._scalars[i][j]; } } return *getThis(); } uge_gm_tmpl_mnt T GenericMatrix::operator+() const { return *getThis(); } uge_gm_tmpl_mnt T GenericMatrix::operator+(const double &k) const { return T(*getThis()).add(k); } uge_gm_tmpl_mnt T &GenericMatrix::operator+=(const double &k) { return add(k); } uge_gm_tmpl_mnt T GenericMatrix::operator+(const T &other) const { return T(*getThis()).add(other); } uge_gm_tmpl_mnt T &GenericMatrix::operator+=(const T &other) { return add(other); } uge_gm_tmpl_mnt T GenericMatrix::operator-() const { return T() - (*getThis()); } uge_gm_tmpl_mnt T GenericMatrix::operator-(const double &k) const { return T(*getThis()).sub(k); } uge_gm_tmpl_mnt T &GenericMatrix::operator-=(const double &k) { return sub(k); } uge_gm_tmpl_mnt T GenericMatrix::operator-(const T &other) const { return T(*getThis()).sub(other); } uge_gm_tmpl_mnt T &GenericMatrix::operator-=(const T &other) { return sub(other); } uge_gm_tmpl_mnt T GenericMatrix::operator*(const double &k) const { return T(*getThis()).mult(k); } uge_gm_tmpl_mnt T &GenericMatrix::operator*=(const double &k) { return mult(k); } uge_gm_tmpl_mnt T GenericMatrix::operator*(const T &other) const { return T(*getThis()).mult(other); } uge_gm_tmpl_mnt T &GenericMatrix::operator*=(const T &other) { return mult(other); } uge_gm_tmpl_mnt T GenericMatrix::operator/(const double &k) const { return T(*getThis()).div(k); } uge_gm_tmpl_mnt T &GenericMatrix::operator/=(const double &k) { return div(k); } uge_gm_tmpl_mnt T GenericMatrix::operator/(const T &other) const { return T(*getThis()).div(other); } uge_gm_tmpl_mnt T &GenericMatrix::operator/=(const T &other) { return div(other); } uge_gm_tmpl_mnt bool GenericMatrix::operator==(const T &other) const { return equal(other); } uge_gm_tmpl_mnt bool GenericMatrix::operator!=(const T &other) const { return !equal(other); } uge_gm_tmpl_mnt bool GenericMatrix::operator!() const { return isNull(); } uge_gm_tmpl_mnt GenericMatrix::operator bool() const { return !isNull(); } uge_gm_tmpl_mnt T *GenericMatrix::getThis() const { return (T*)this; }