Skip to content

Commit

Permalink
feat(matrixwindow): some operations were too slow
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandini committed May 28, 2024
1 parent 1a18010 commit e795710
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions Matrix/TPZMatrixWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ TPZMatrixWindow<TVar> &TPZMatrixWindow<TVar>::operator=(const TPZFMatrix<TVar> &
const auto m_leading_dim = mat.Rows();
const auto nc = this->Cols();
const auto nr = this->Rows();
const auto sz = nc*nr;
for(int i = 0; i < sz; i++){
const int ic = i/nr;
const int ir = i%nr;
this->fStorage[ic*this->fLeadingDim+ir] = mat.Elem()[ic*m_leading_dim+ir];
auto *my_ptr = &this->fStorage[0];
auto *their_ptr = mat.Elem();
//mem dist to advance between cols
const auto my_adv = this->fLeadingDim-nr;
const auto their_adv = m_leading_dim-nr;

for(int ic = 0; ic < nc; ic++){
for(auto ir = 0; ir < nr; ir++){
*my_ptr++ = *their_ptr++;
}
my_ptr+=my_adv;
their_ptr+=their_adv;
}
// const auto sz = nc*nr;
// for(int i = 0; i < sz; i++){
// const int ic = i/nr;
// const int ir = i%nr;
// this->fStorage[ic*this->fLeadingDim+ir] = mat.Elem()[ic*m_leading_dim+ir];
// }

return *this;
}
Expand All @@ -54,25 +67,48 @@ TPZMatrixWindow<TVar> &TPZMatrixWindow<TVar>::operator=(const TPZMatrixWindow<TV
const auto m_leading_dim = mat.fLeadingDim;
const auto nc = this->Cols();
const auto nr = this->Rows();
const auto sz = nc*nr;
for(int i = 0; i < sz; i++){
const int ic = i/nr;
const int ir = i%nr;
this->fStorage[ic*this->fLeadingDim+ir] = mat.fStorage[ic*m_leading_dim+ir];
auto *my_ptr = &this->fStorage[0];
auto *their_ptr = &mat.fStorage[0];
//mem dist to advance between cols
const auto my_adv = this->fLeadingDim-nr;
const auto their_adv = m_leading_dim-nr;

for(int ic = 0; ic < nc; ic++){
for(auto ir = 0; ir < nr; ir++){
*my_ptr++ = *their_ptr++;
}
my_ptr+=my_adv;
their_ptr+=their_adv;
}
// const auto sz = nc*nr;
// for(int i = 0; i < sz; i++){
// const int ic = i/nr;
// const int ir = i%nr;
// this->fStorage[ic*this->fLeadingDim+ir] = mat.fStorage[ic*m_leading_dim+ir];
// }
return *this;
}

template<class TVar>
TPZMatrixWindow<TVar> &TPZMatrixWindow<TVar>::operator*=(const TVar val){
const auto nc = this->Cols();
const auto nr = this->Rows();
const auto sz = nc*nr;
for(int i = 0; i < sz; i++){
const int ic = i/nr;
const int ir = i%nr;
this->fStorage[ic*this->fLeadingDim+ir] *= val;
auto *my_ptr = &this->fStorage[0];
//mem dist to advance between cols
const auto my_adv = this->fLeadingDim-nr;

for(int ic = 0; ic < nc; ic++){
for(auto ir = 0; ir < nr; ir++,my_ptr++){
*my_ptr *= val;
}
my_ptr+=my_adv;
}
// const auto sz = nc*nr;
// for(int i = 0; i < sz; i++){
// const int ic = i/nr;
// const int ir = i%nr;
// this->fStorage[ic*this->fLeadingDim+ir] *= val;
// }
return *this;
}

Expand Down

0 comments on commit e795710

Please sign in to comment.