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