Guest User

Untitled

a guest
Mar 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. template<typename T>
  2. Matrix<T>& Matrix<T>::operator=(Matrix<T>& rhs){
  3. assert(this->n_row == rhs.n_row);
  4. assert(this->n_col == rhs.n_col);
  5. int offset;
  6. for(int i=0; i<this->n_row; i++){
  7. offset = i * n_col;
  8. for(int j =0; j<this->n_col; j++){
  9. this->data[offset+j] = rhs.data[offset+j];
  10. }
  11. }
  12. return *this;
  13. }
  14.  
  15. template<typename T>
  16. Matrix<T>& Matrix<T>::operator*=(const T scalar){
  17. int offset;
  18. for(int i=0; i<this->n_row; i++){
  19. offset = i * this->n_col;
  20. for(int j=0; j<this->n_col; j++){
  21. this->data[offset+j] *= scalar;
  22. }
  23. }
  24. return *this;
  25. }
  26.  
  27. template<typename T>
  28. Matrix<T> Matrix<T>::operator*(const T scalar){
  29. Matrix<T> lhs(*this);
  30. lhs *= scalar;
  31. return lhs;
  32. }
Add Comment
Please, Sign In to add comment