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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. for (int i = 0; i < M; ++i) {
  6. for (int j = 0; j < N; ++j) {
  7. _scalars[i][j] = 0;
  8. }
  9. }
  10. }
  11. uge_gm_tmpl_mn MatrixMxN<M, N>::MatrixMxN(double k)
  12. {
  13. for (int i = 0; i < M; ++i) {
  14. for (int j = 0; j < N; ++j) {
  15. _scalars[i][j] = k;
  16. }
  17. }
  18. }
  19. uge_gm_tmpl_mn MatrixMxN<M, N>::MatrixMxN(double scalars[M][N])
  20. {
  21. for (int i = 0; i < M; ++i) {
  22. for (int j = 0; j < N; ++j) {
  23. _scalars[i][j] = scalars[i][j];
  24. }
  25. }
  26. }
  27. uge_gm_tmpl_mn MatrixMxN<M, N>::~MatrixMxN()
  28. {
  29. }
  30. uge_gm_tmpl_mnt GenericMatrix<M, N, T>::~GenericMatrix()
  31. {
  32. }
  33. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::setScalar(unsigned i, unsigned j, double value)
  34. {
  35. _scalars[i][j] = value;
  36. return *getThis();
  37. }
  38. uge_gm_tmpl_mnt double GenericMatrix<M, N, T>::getScalar(unsigned i, unsigned j) const
  39. {
  40. return _scalars[i][j];
  41. }
  42. uge_gm_tmpl_mnt T *GenericMatrix<M, N, T>::getThis() const
  43. {
  44. return (T*)this;
  45. }
  46. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::isNull() const
  47. {
  48. return equal(T());
  49. }
  50. uge_gm_tmpl_mnt bool GenericMatrix<M, N, T>::equal(const T &other) const
  51. {
  52. for (int i = 0; i < M; ++i) {
  53. for (int j = 0; j < N; ++j) {
  54. if (_scalars[i][j] != other._scalars[i][j]) {
  55. return false;
  56. }
  57. }
  58. }
  59. return true;
  60. }
  61. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::add(double k)
  62. {
  63. return add(T(k));
  64. }
  65. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::add(double scalars[M][N])
  66. {
  67. return add(T(scalars));
  68. }
  69. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::add(const T &other)
  70. {
  71. for (int i = 0; i < M; ++i) {
  72. for (int j = 0; j < N; ++j) {
  73. _scalars[i][j] += other._scalars[i][j];
  74. }
  75. }
  76. return *getThis();
  77. }
  78. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::sub(double k)
  79. {
  80. return sub(T(k));
  81. }
  82. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::sub(double scalars[M][N])
  83. {
  84. return sub(T(scalars));
  85. }
  86. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::sub(const T &other)
  87. {
  88. for (int i = 0; i < M; ++i) {
  89. for (int j = 0; j < N; ++j) {
  90. _scalars[i][j] -= other._scalars[i][j];
  91. }
  92. }
  93. return *getThis();
  94. }
  95. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::mult(double k)
  96. {
  97. for (int i = 0; i < M; ++i) {
  98. for (int j = 0; j < N; ++j) {
  99. _scalars[i][j] *= k;
  100. }
  101. }
  102. return *getThis();
  103. }
  104. uge_gm_tmpl_mnt uge_gm_tmpl_p MatrixMxN<M, P> GenericMatrix<M, N, T>::mult(double scalars[N][P])
  105. {
  106. return mult(MatrixMxN<N, P>(scalars));
  107. }
  108. uge_gm_tmpl_mnt uge_gm_tmpl_p MatrixMxN<M, P> GenericMatrix<M, N, T>::mult(const MatrixMxN<N, P>& other)
  109. {
  110. MatrixMxN<N, P> m;
  111. return m;
  112. }
  113. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::div(double k)
  114. {
  115. return div(T(k));
  116. }
  117. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::div(double scalars[M][N])
  118. {
  119. return div(T(scalars));
  120. }
  121. uge_gm_tmpl_mnt T &GenericMatrix<M, N, T>::div(const T &other)
  122. {
  123. for (int i = 0; i < M; ++i) {
  124. for (int j = 0; j < N; ++j) {
  125. _scalars[i][j] /= other._scalars[i][j];
  126. }
  127. }
  128. return *getThis();
  129. }