Inplace operators use std::transform(); and fixed resize problem when
resizing from bigger to smaller matrix.
This commit is contained in:
parent
d5638d0f65
commit
07043ecb2d
@ -394,9 +394,9 @@ void Matrix<T,M>::resize(size_type rows, size_type columns, const T& initialValu
|
|||||||
this->_matEls.resize(newSize);
|
this->_matEls.resize(newSize);
|
||||||
this->_rows = rows;
|
this->_rows = rows;
|
||||||
this->_columns = columns;
|
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);
|
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);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: Consider non-square matrices
|
||||||
template <typename T, int M>
|
template <typename T, int M>
|
||||||
void Matrix<T,M>::transpose_inplace()
|
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>
|
template <typename T, int M>
|
||||||
Matrix<T,M>& Matrix<T,M>::operator+=(const Matrix<T,M>& rhs)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, int M>
|
template <typename T, int M>
|
||||||
Matrix<T,M>& Matrix<T,M>::operator-=(const Matrix<T,M>& rhs)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, int M>
|
template <typename T, int M>
|
||||||
Matrix<T,M>& Matrix<T,M>::operator*=(const Matrix<T,M>& rhs)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, int M>
|
template <typename T, int M>
|
||||||
Matrix<T,M>& Matrix<T,M>::operator*=(const T& rhs)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user