Inplace operators use std::transform(); and fixed resize problem when

resizing from bigger to smaller matrix.
This commit is contained in:
Samer Afach 2016-11-08 16:03:47 +01:00
parent d5638d0f65
commit 07043ecb2d
1 changed files with 11 additions and 6 deletions

View File

@ -394,9 +394,9 @@ void Matrix<T,M>::resize(size_type rows, size_type columns, const T& initialValu
this->_matEls.resize(newSize);
this->_rows = rows;
this->_columns = columns;
for(size_type i = 0; i < oldRows; i++)
for(size_type i = 0; i < (oldRows > rows ? rows : oldRows); i++)
{
for(size_type j = 0; j < oldColumns; j++)
for(size_type j = 0; j < (oldColumns > columns ? columns : oldColumns); j++)
{
this->at(i,j) = oldMat.at(i,j);
}
@ -482,6 +482,7 @@ bool Matrix<T,M>::operator!=(const Matrix<T,M>& rhs)
return !(*this == rhs);
}
//FIXME: Consider non-square matrices
template <typename T, int M>
void Matrix<T,M>::transpose_inplace()
{
@ -689,28 +690,32 @@ Matrix<std::complex<T>,M> operator-(const Matrix<T,M>& lhs, const Matrix<std::co
template <typename T, int M>
Matrix<T,M>& Matrix<T,M>::operator+=(const Matrix<T,M>& rhs)
{
(*this) = (*this) + rhs;
std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::plus<T>());
// (*this) = (*this) + rhs;
return *this;
}
template <typename T, int M>
Matrix<T,M>& Matrix<T,M>::operator-=(const Matrix<T,M>& rhs)
{
(*this) = (*this) - rhs;
std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::minus<T>());
// (*this) = (*this) - rhs;
return *this;
}
template <typename T, int M>
Matrix<T,M>& Matrix<T,M>::operator*=(const Matrix<T,M>& rhs)
{
(*this) = (*this) * rhs;
std::transform(this->begin(),this->end(),rhs.begin(),this->begin(),std::multiplies<T>());
// (*this) = (*this) * rhs;
return *this;
}
template <typename T, int M>
Matrix<T,M>& Matrix<T,M>::operator*=(const T& rhs)
{
(*this) = (*this) * rhs;
std::transform(this->begin(),this->end(),this->begin(),std::bind2nd(std::multiplies<T>(),rhs));
// (*this) = (*this) * rhs;
return *this;
}