You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

matrixmxn.hxx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #define uge_gm_tmpl_mnt template<unsigned M, unsigned N, class T>
  2. #define uge_gm_tmpl_mn template<unsigned M, unsigned N>
  3. uge_gm_tmpl_mn MatrixMxN<M, N>::MatrixMxN()
  4. {
  5. this->fill(0.0);
  6. }
  7. uge_gm_tmpl_mn MatrixMxN<M, N>::MatrixMxN(double k)
  8. {
  9. this->fill(k);
  10. }
  11. uge_gm_tmpl_mn MatrixMxN<M, N>::MatrixMxN(double scalars[M][N])
  12. {
  13. this->fill(scalars);
  14. }
  15. uge_gm_tmpl_mn MatrixMxN<M, N>::~MatrixMxN()
  16. {
  17. }
  18. uge_gm_tmpl_mnt GenericMatrix<M, N, T>::~GenericMatrix()
  19. {
  20. }
  21. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::setScalar(unsigned i, unsigned j, double value)
  22. {
  23. _scalars[i][j] = value;
  24. return *getThis();
  25. }
  26. uge_gm_tmpl_mnt double GenericMatrix<M, N, T>::getScalar(unsigned i, unsigned j) const
  27. {
  28. return _scalars[i][j];
  29. }
  30. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::isNull() const
  31. {
  32. return equal(T());
  33. }
  34. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::equal(const T &other) const
  35. {
  36. for (int i = 0; i < M; ++i) {
  37. for (int j = 0; j < N; ++j) {
  38. if (_scalars[i][j] != other._scalars[i][j]) {
  39. return false;
  40. }
  41. }
  42. }
  43. return true;
  44. }
  45. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::fill(double k)
  46. {
  47. for (int i = 0; i < M; ++i) {
  48. for (int j = 0; j < N; ++j) {
  49. _scalars[i][j] = k;
  50. }
  51. }
  52. return *getThis();
  53. }
  54. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::fill(double scalars[M][N])
  55. {
  56. for (int i = 0; i < M; ++i) {
  57. for (int j = 0; j < N; ++j) {
  58. _scalars[i][j] = scalars[i][j];
  59. }
  60. }
  61. return *getThis();
  62. }
  63. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::add(double k)
  64. {
  65. return add(T(k));
  66. }
  67. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::add(double scalars[M][N])
  68. {
  69. return add(T(scalars));
  70. }
  71. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::add(const T &other)
  72. {
  73. for (int i = 0; i < M; ++i) {
  74. for (int j = 0; j < N; ++j) {
  75. _scalars[i][j] += other._scalars[i][j];
  76. }
  77. }
  78. return *getThis();
  79. }
  80. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::sub(double k)
  81. {
  82. return sub(T(k));
  83. }
  84. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::sub(double scalars[M][N])
  85. {
  86. return sub(T(scalars));
  87. }
  88. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::sub(const T &other)
  89. {
  90. for (int i = 0; i < M; ++i) {
  91. for (int j = 0; j < N; ++j) {
  92. _scalars[i][j] -= other._scalars[i][j];
  93. }
  94. }
  95. return *getThis();
  96. }
  97. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::mult(double k)
  98. {
  99. for (int i = 0; i < M; ++i) {
  100. for (int j = 0; j < N; ++j) {
  101. _scalars[i][j] *= k;
  102. }
  103. }
  104. return *getThis();
  105. }
  106. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::mult(double scalars[M][N])
  107. {
  108. return mult(T(scalars));
  109. }
  110. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::mult(const T &other)
  111. {
  112. for (int i = 0; i < M; ++i) {
  113. for (int j = 0; j < N; ++j) {
  114. _scalars[i][j] *= other._scalars[i][j];
  115. }
  116. }
  117. return *getThis();
  118. }
  119. uge_gm_tmpl_mnt uge_gm_tmpl_p
  120. MatrixMxN<M, P> GenericMatrix<M, N, T>::multMatrix(double scalars[N][P])
  121. {
  122. return multMatrix(MatrixMxN<N, P>(scalars));
  123. }
  124. uge_gm_tmpl_mnt uge_gm_tmpl_p
  125. MatrixMxN<M, P> GenericMatrix<M, N, T>::multMatrix(const MatrixMxN<N, P>& other)
  126. {
  127. MatrixMxN<M, P> m;
  128. for (int i = 0; i < M; ++i) {
  129. for (int j = 0; j < P; ++j) {
  130. double t = 0;
  131. for (int k = 0; k < N; ++k) {
  132. t += _scalars[i][k] * other._scalars[k][j];
  133. }
  134. m._scalars[i][j] = t;
  135. }
  136. }
  137. return m;
  138. }
  139. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::div(double k)
  140. {
  141. return div(T(k));
  142. }
  143. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::div(double scalars[M][N])
  144. {
  145. return div(T(scalars));
  146. }
  147. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::div(const T &other)
  148. {
  149. for (int i = 0; i < M; ++i) {
  150. for (int j = 0; j < N; ++j) {
  151. _scalars[i][j] /= other._scalars[i][j];
  152. }
  153. }
  154. return *getThis();
  155. }
  156. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator+() const
  157. {
  158. return *getThis();
  159. }
  160. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator+(const double &k) const
  161. {
  162. return T(*getThis()).add(k);
  163. }
  164. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator+=(const double &k)
  165. {
  166. return add(k);
  167. }
  168. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator+(const T &other) const
  169. {
  170. return T(*getThis()).add(other);
  171. }
  172. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator+=(const T &other)
  173. {
  174. return add(other);
  175. }
  176. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator-() const
  177. {
  178. return T() - (*getThis());
  179. }
  180. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator-(const double &k) const
  181. {
  182. return T(*getThis()).sub(k);
  183. }
  184. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator-=(const double &k)
  185. {
  186. return sub(k);
  187. }
  188. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator-(const T &other) const
  189. {
  190. return T(*getThis()).sub(other);
  191. }
  192. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator-=(const T &other)
  193. {
  194. return sub(other);
  195. }
  196. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator*(const double &k) const
  197. {
  198. return T(*getThis()).mult(k);
  199. }
  200. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator*=(const double &k)
  201. {
  202. return mult(k);
  203. }
  204. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator*(const T &other) const
  205. {
  206. return T(*getThis()).mult(other);
  207. }
  208. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator*=(const T &other)
  209. {
  210. return mult(other);
  211. }
  212. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator/(const double &k) const
  213. {
  214. return T(*getThis()).div(k);
  215. }
  216. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator/=(const double &k)
  217. {
  218. return div(k);
  219. }
  220. uge_gm_tmpl_mnt T GenericMatrix<M, N, T>::operator/(const T &other) const
  221. {
  222. return T(*getThis()).div(other);
  223. }
  224. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::operator/=(const T &other)
  225. {
  226. return div(other);
  227. }
  228. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::operator==(const T &other) const
  229. {
  230. return equal(other);
  231. }
  232. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::operator!=(const T &other) const
  233. {
  234. return !equal(other);
  235. }
  236. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::operator!() const
  237. {
  238. return isNull();
  239. }
  240. uge_gm_tmpl_mnt GenericMatrix<M, N, T>::operator bool() const
  241. {
  242. return !isNull();
  243. }
  244. uge_gm_tmpl_mnt T *GenericMatrix<M, N, T>::getThis() const
  245. {
  246. return (T*)this;
  247. }