Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Loop unroll
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Aug 31, 2017
1 parent c3488d9 commit 9564d7a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 71 deletions.
42 changes: 21 additions & 21 deletions include/cppmat/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2638,12 +2638,12 @@ std::ostream& operator<<(std::ostream& out, tensor4<X>& src)

template<class X> void inline tensor2<X>::printf(std::string fmt) const
{
size_t nd = this->m_nd;
size_t nd = m_nd;

for ( size_t h=0; h<nd; ++h ) {
for ( size_t i=0; i<nd-1; ++i )
std::printf((fmt+",").c_str(),this->m_data[h*nd+i]);
std::printf((fmt+";\n").c_str(),this->m_data[h*nd+(nd-1)]);
std::printf((fmt+",").c_str(),m_data[h*nd+i]);
std::printf((fmt+";\n").c_str(),m_data[h*nd+(nd-1)]);
}
}

Expand All @@ -2664,17 +2664,17 @@ std::ostream& operator<<(std::ostream& out, tensor2<X>& src)

template<class X> void inline tensor2s<X>::printf(std::string fmt) const
{
size_t nd = this->m_nd;
size_t nd = m_nd;
size_t i,j;

for ( i=0; i<nd; ++i ) {
for ( j=0; j<nd-1; ++j ) {
if (i <= j) std::printf((fmt+",").c_str(),this->m_data[ i * nd - (i - 1) * i / 2 + j - i ]);
else std::printf((fmt+",").c_str(),this->m_data[ j * nd - (j - 1) * j / 2 + i - j ]);
if (i <= j) std::printf((fmt+",").c_str(),m_data[ i * nd - (i - 1) * i / 2 + j - i ]);
else std::printf((fmt+",").c_str(),m_data[ j * nd - (j - 1) * j / 2 + i - j ]);
}
j = nd-1;
if (i <= j) std::printf((fmt+";\n").c_str(),this->m_data[ i * nd - (i - 1) * i / 2 + j - i ]);
else std::printf((fmt+";\n").c_str(),this->m_data[ j * nd - (j - 1) * j / 2 + i - j ]);
if (i <= j) std::printf((fmt+";\n").c_str(),m_data[ i * nd - (i - 1) * i / 2 + j - i ]);
else std::printf((fmt+";\n").c_str(),m_data[ j * nd - (j - 1) * j / 2 + i - j ]);
}
}

Expand All @@ -2695,17 +2695,17 @@ std::ostream& operator<<(std::ostream& out, tensor2s<X>& src)

template<class X> void inline tensor2d<X>::printf(std::string fmt) const
{
size_t nd = this->m_nd;
size_t nd = m_nd;
size_t i,j;

for ( i=0; i<nd; ++i ) {
for ( j=0; j<nd-1; ++j ) {
if (i == j) std::printf((fmt+",").c_str(),this->m_data[i ]);
else std::printf((fmt+",").c_str(),this->m_data[m_nd]);
if (i == j) std::printf((fmt+",").c_str(),m_data[i ]);
else std::printf((fmt+",").c_str(),m_data[m_nd]);
}
j = nd-1;
if (i == j) std::printf((fmt+";\n").c_str(),this->m_data[i ]);
else std::printf((fmt+";\n").c_str(),this->m_data[m_nd]);
if (i == j) std::printf((fmt+";\n").c_str(),m_data[i ]);
else std::printf((fmt+";\n").c_str(),m_data[m_nd]);
}
}

Expand All @@ -2726,11 +2726,11 @@ std::ostream& operator<<(std::ostream& out, tensor2d<X>& src)

template<class X> void inline vector<X>::printf(std::string fmt) const
{
size_t nd = this->m_nd;
size_t nd = m_nd;

for ( size_t i=0; i<nd-1; ++i )
std::printf((fmt+",").c_str(),this->m_data[i]);
std::printf((fmt+"\n").c_str(),this->m_data[nd-1]);
std::printf((fmt+",").c_str(),m_data[i]);
std::printf((fmt+"\n").c_str(),m_data[nd-1]);
}

// -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -3567,7 +3567,7 @@ template<class X> tensor2s<X> inline tensor2s<X>::T() const
{
tensor2s<X> C(m_nd);

for ( size_t i=0; i<this->size(); ++i )
for ( size_t i=0; i<size(); ++i )
C[i] = (*this)[i];

return C;
Expand All @@ -3579,7 +3579,7 @@ template<class X> tensor2d<X> inline tensor2d<X>::T() const
{
tensor2d<X> C(m_nd);

for ( size_t i=0; i<this->size(); ++i )
for ( size_t i=0; i<size(); ++i )
C[i] = (*this)[i];

return C;
Expand Down Expand Up @@ -3617,7 +3617,7 @@ template<class X> X inline tensor2d<X>::trace() const
{
X C = static_cast<X>(0);

for ( size_t i=0; i<this->size(); ++i )
for ( size_t i=0; i<size(); ++i )
C += (*this)[i];

return C;
Expand Down Expand Up @@ -3675,7 +3675,7 @@ template<class X> X inline tensor2d<X>::det() const
template<class X> tensor2<X> inline tensor2<X>::inv() const
{
// compute determinant
X D = this->det();
X D = det();

// allocate result
tensor2<X> C(m_nd);
Expand Down Expand Up @@ -3709,7 +3709,7 @@ template<class X> tensor2<X> inline tensor2<X>::inv() const
template<class X> tensor2s<X> inline tensor2s<X>::inv() const
{
// compute determinant
X D = this->det();
X D = det();

// allocate result
tensor2s<X> C(m_nd);
Expand Down
76 changes: 26 additions & 50 deletions include/cppmat/tensor3.h
Original file line number Diff line number Diff line change
Expand Up @@ -2668,103 +2668,79 @@ std::ostream& operator<<(std::ostream& out, tensor3_4<X>& src)

template<class X> void inline tensor3_2<X>::printf(std::string fmt) const
{
for ( size_t h=0; h<3; ++h ) {
for ( size_t i=0; i<3-1; ++i )
std::printf((fmt+",").c_str(),this->m_data[h*3+i]);
std::printf((fmt+";\n").c_str(),this->m_data[h*3+(3-1)]);
}
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[0],m_data[1],m_data[2]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[3],m_data[4],m_data[5]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[6],m_data[7],m_data[8]);
}

// -------------------------------------------------------------------------------------------------

template <class X>
std::ostream& operator<<(std::ostream& out, tensor3_2<X>& src)
{
for ( size_t i=0; i<3; ++i ) {
for ( size_t j=0; j<3-1; ++j )
out << src(i,j) << ", ";
out << src(i,3-1) << "; " << std::endl;
}
out << src(0,0) << ", " << src(0,1) << ", " << src(0,2) << ";" << std::endl;
out << src(1,0) << ", " << src(1,1) << ", " << src(1,2) << ";" << std::endl;
out << src(2,0) << ", " << src(2,1) << ", " << src(2,2) << ";" << std::endl;

return out;
}

// -------------------------------------------------------------------------------------------------

template<class X> void inline tensor3_2s<X>::printf(std::string fmt) const
{
size_t i,j;

for ( i=0; i<3; ++i ) {
for ( j=0; j<3-1; ++j ) {
if (i <= j) std::printf((fmt+",").c_str(),this->m_data[ i * 3 - (i - 1) * i / 2 + j - i ]);
else std::printf((fmt+",").c_str(),this->m_data[ j * 3 - (j - 1) * j / 2 + i - j ]);
}
j = 3-1;
if (i <= j) std::printf((fmt+";\n").c_str(),this->m_data[ i * 3 - (i - 1) * i / 2 + j - i ]);
else std::printf((fmt+";\n").c_str(),this->m_data[ j * 3 - (j - 1) * j / 2 + i - j ]);
}
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[0],m_data[1],m_data[2]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[1],m_data[3],m_data[4]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[2],m_data[4],m_data[5]);
}

// -------------------------------------------------------------------------------------------------

template <class X>
std::ostream& operator<<(std::ostream& out, tensor3_2s<X>& src)
{
for ( size_t i=0; i<3; ++i ) {
for ( size_t j=0; j<3-1; ++j )
out << src(i,j) << ", ";
out << src(i,3-1) << "; " << std::endl;
}
out << src(0,0) << ", " << src(0,1) << ", " << src(0,2) << ";" << std::endl;
out << src(1,0) << ", " << src(1,1) << ", " << src(1,2) << ";" << std::endl;
out << src(2,0) << ", " << src(2,1) << ", " << src(2,2) << ";" << std::endl;

return out;
}

// -------------------------------------------------------------------------------------------------

template<class X> void inline tensor3_2d<X>::printf(std::string fmt) const
{
size_t i,j;

for ( i=0; i<3; ++i ) {
for ( j=0; j<3-1; ++j ) {
if (i == j) std::printf((fmt+",").c_str(),this->m_data[i]);
else std::printf((fmt+",").c_str(),this->m_data[3]);
}
j = 3-1;
if (i == j) std::printf((fmt+";\n").c_str(),this->m_data[i]);
else std::printf((fmt+";\n").c_str(),this->m_data[3]);
}
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[0],m_data[3],m_data[3]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[3],m_data[1],m_data[3]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[3],m_data[3],m_data[2]);
}

// -------------------------------------------------------------------------------------------------

template <class X>
std::ostream& operator<<(std::ostream& out, tensor3_2d<X>& src)
{
for ( size_t i=0; i<3; ++i ) {
for ( size_t j=0; j<3-1; ++j )
out << src(i,j) << ", ";
out << src(i,3-1) << "; " << std::endl;
}
out << src(0,0) << ", " << src(0,1) << ", " << src(0,2) << ";" << std::endl;
out << src(1,0) << ", " << src(1,1) << ", " << src(1,2) << ";" << std::endl;
out << src(2,0) << ", " << src(2,1) << ", " << src(2,2) << ";" << std::endl;

return out;
}

// -------------------------------------------------------------------------------------------------

template<class X> void inline vector3<X>::printf(std::string fmt) const
{
for ( size_t i=0; i<3-1; ++i )
std::printf((fmt+",").c_str(),this->m_data[i]);
std::printf((fmt+"\n").c_str(),this->m_data[3-1]);
std::printf((fmt+","+fmt+","+fmt+";\n").c_str(),m_data[0],m_data[1],m_data[2]);
}

// -------------------------------------------------------------------------------------------------

template <class X>
std::ostream& operator<<(std::ostream& out, vector3<X>& src)
{
for ( size_t i=0; i<3-1; ++i )
out << src(i) << ", ";
out << src(3-1) << std::endl;
out << src(0) << ", " << src(1) << ", " << src(2) << ";" << std::endl;

return out;
}

Expand Down Expand Up @@ -3570,7 +3546,7 @@ template<class X> X inline tensor3_2d<X>::det() const
template<class X> tensor3_2<X> inline tensor3_2<X>::inv() const
{
// compute determinant
X D = this->det();
X D = det();

// allocate result
tensor3_2<X> C;
Expand All @@ -3592,7 +3568,7 @@ template<class X> tensor3_2<X> inline tensor3_2<X>::inv() const
template<class X> tensor3_2s<X> inline tensor3_2s<X>::inv() const
{
// compute determinant
X D = this->det();
X D = det();

// allocate result
tensor3_2s<X> C;
Expand Down

0 comments on commit 9564d7a

Please sign in to comment.