Commit d6a79b1e authored by Benoît LÉ's avatar Benoît LÉ

Add missing policies, modify toDense function

Added missing policies to cpy sparse matrix in dense matrix.

Added an optional parameter to toDense function in xGenericSparseMatrix: if zero fill==false, toDense does not reset the dense matrix to zero
before filling it. It can be used to fill a dense matrix blockwise. The default value of this parameter is true, so it does not change anything in
pieces of code which were previously using this function.
parent 262f95da
Pipeline #411 failed with stages
......@@ -298,8 +298,7 @@ class xGenericSparseMatrix
//! denseIndex is a function that, giving i and j argument coming from ids_r or ids_c, return the index of corresponding term in array dense matrix.
//! User is providing this function to sort dense matrix in row or column wise form.
//
void toDense(int nbr,int nbc, T * dense_matrix,int* ids_r,int *ids_c,std::function < int (int,int) > denseIndex);
void toDense(int nbr,int nbc, T * dense_matrix,int* ids_r,int *ids_c,std::function < int (int,int) > denseIndex, bool zeroFill = true);
//! Return the number of ligne, column and non-zero terms
int getN() const;
......
......@@ -2312,6 +2312,84 @@ class xPolicyDenseMatrixCopy < xTraitMatrixUnSym,false,false > : public xPolicyD
return denseIndex(i-1,j-1);
}
};
template < >
class xPolicyDenseMatrixCopy < xTraitMatrixLowerSym,true,true > : public xPolicyDenseMatrixCopyBase
{
public:
xPolicyDenseMatrixCopy(int nbr,int nbc,int *ids_r_,int * ids_c_,std::function < int (int,int) > denseIndex_) :
xPolicyDenseMatrixCopyBase(nbr,nbc,ids_r_,ids_c_,denseIndex_){}
int denseSelectedIndex( int i, int j) const override
{
const int k = ids_r[i];
const int l = ids_c[j];
assert(k < nbr);
assert(l < nbc);
if (k > -1 && l > -1)
{
if(k>l) return denseIndex(k,l);
else return denseIndex(l,k);
}
return -1;
}
};
template < >
class xPolicyDenseMatrixCopy < xTraitMatrixLowerSym,false,true > : public xPolicyDenseMatrixCopyBase
{
public:
xPolicyDenseMatrixCopy(int nbr,int nbc,int *ids_r_,int * ids_c_,std::function < int (int,int) > denseIndex_) :
xPolicyDenseMatrixCopyBase(nbr,nbc,ids_r_,ids_c_,denseIndex_){}
int denseSelectedIndex( int i, int j) const override
{
const int l = ids_c[j];
assert(l < nbc);
if (l > -1)
{
if(i-1>l) return denseIndex(i-1,l);
else return denseIndex(l,i-1);
}
return -1;
}
};
template < >
class xPolicyDenseMatrixCopy < xTraitMatrixLowerSym,true,false > : public xPolicyDenseMatrixCopyBase
{
public:
xPolicyDenseMatrixCopy(int nbr,int nbc,int *ids_r_,int * ids_c_,std::function < int (int,int) > denseIndex_) :
xPolicyDenseMatrixCopyBase(nbr,nbc,ids_r_,ids_c_,denseIndex_){}
int denseSelectedIndex( int i, int j) const override
{
const int k = ids_r[i];
assert(k < nbr);
if (k > -1)
{
if(k> j-1) return denseIndex(k,j-1);
else return denseIndex(j-1,k);
}
return -1;
}
};
template < >
class xPolicyDenseMatrixCopy < xTraitMatrixLowerSym,false,false > : public xPolicyDenseMatrixCopyBase
{
public:
xPolicyDenseMatrixCopy(int nbr,int nbc,int *ids_r_,int * ids_c_,std::function < int (int,int) > denseIndex_) :
xPolicyDenseMatrixCopyBase(nbr,nbc,ids_r_,ids_c_,denseIndex_){}
int denseSelectedIndex( int i, int j) const override
{
printf("%i %i\n",i-1,j-1);
if(i-1> j-1) return denseIndex(i-1,j-1);
else return denseIndex(i-1,j-1);
}
};
//------------------------------------------------------ End Pattern dependante
} // end of namespace
......
......@@ -1293,13 +1293,13 @@ void xGenericSparseMatrix < T,DEFINED,PATTERN,STORAGE_TYPE,INDEXING >::operator
}
template < typename T, typename DEFINED, typename PATTERN, typename STORAGE_TYPE, typename INDEXING >
void xGenericSparseMatrix < T,DEFINED,PATTERN,STORAGE_TYPE,INDEXING >::toDense(int nbr,int nbc,T * dense_matrix,int* ids_r,int* ids_c,std::function < int (int,int) > denseIndex)
void xGenericSparseMatrix < T,DEFINED,PATTERN,STORAGE_TYPE,INDEXING >::toDense(int nbr,int nbc,T * dense_matrix,int* ids_r,int* ids_c,std::function < int (int,int) > denseIndex, bool zeroFill)
{
int i,j,k,l,ke,le,idxd;
T val;
// reset to zero
std::fill(dense_matrix,dense_matrix+nbr*nbc, xTraitsGenericSparseMatrixType < T >::zero());
if(zeroFill) std::fill(dense_matrix,dense_matrix+nbr*nbc, xTraitsGenericSparseMatrixType < T >::zero());
// generate apropriate policy
xPolicyDenseMatrixCopyBase *pp {nullptr};
......@@ -1332,6 +1332,7 @@ void xGenericSparseMatrix < T,DEFINED,PATTERN,STORAGE_TYPE,INDEXING >::toDense(i
delete pp;
}
template < typename T, typename DEFINED, typename PATTERN, typename STORAGE_TYPE, typename INDEXING >
int xGenericSparseMatrix < T,DEFINED,PATTERN,STORAGE_TYPE,INDEXING >::getN() const
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment