mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-30 17:40:05 +08:00
Make sparse unit-test helpers aware of StorageIndex
This commit is contained in:
parent
39228cb224
commit
cf9940e17b
@ -53,15 +53,15 @@ enum {
|
||||
* \param zeroCoords and nonzeroCoords allows to get the coordinate lists of the non zero,
|
||||
* and zero coefficients respectively.
|
||||
*/
|
||||
template<typename Scalar,int Opt1,int Opt2,typename Index> void
|
||||
template<typename Scalar,int Opt1,int Opt2,typename StorageIndex> void
|
||||
initSparse(double density,
|
||||
Matrix<Scalar,Dynamic,Dynamic,Opt1>& refMat,
|
||||
SparseMatrix<Scalar,Opt2,Index>& sparseMat,
|
||||
SparseMatrix<Scalar,Opt2,StorageIndex>& sparseMat,
|
||||
int flags = 0,
|
||||
std::vector<Matrix<Index,2,1> >* zeroCoords = 0,
|
||||
std::vector<Matrix<Index,2,1> >* nonzeroCoords = 0)
|
||||
std::vector<Matrix<StorageIndex,2,1> >* zeroCoords = 0,
|
||||
std::vector<Matrix<StorageIndex,2,1> >* nonzeroCoords = 0)
|
||||
{
|
||||
enum { IsRowMajor = SparseMatrix<Scalar,Opt2,Index>::IsRowMajor };
|
||||
enum { IsRowMajor = SparseMatrix<Scalar,Opt2,StorageIndex>::IsRowMajor };
|
||||
sparseMat.setZero();
|
||||
//sparseMat.reserve(int(refMat.rows()*refMat.cols()*density));
|
||||
sparseMat.reserve(VectorXi::Constant(IsRowMajor ? refMat.rows() : refMat.cols(), int((1.5*density)*(IsRowMajor?refMat.cols():refMat.rows()))));
|
||||
@ -93,11 +93,11 @@ initSparse(double density,
|
||||
//sparseMat.insertBackByOuterInner(j,i) = v;
|
||||
sparseMat.insertByOuterInner(j,i) = v;
|
||||
if (nonzeroCoords)
|
||||
nonzeroCoords->push_back(Matrix<Index,2,1> (ai,aj));
|
||||
nonzeroCoords->push_back(Matrix<StorageIndex,2,1> (ai,aj));
|
||||
}
|
||||
else if (zeroCoords)
|
||||
{
|
||||
zeroCoords->push_back(Matrix<Index,2,1> (ai,aj));
|
||||
zeroCoords->push_back(Matrix<StorageIndex,2,1> (ai,aj));
|
||||
}
|
||||
refMat(ai,aj) = v;
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ template<typename Solver> void check_sparse_spd_solving(Solver& solver)
|
||||
{
|
||||
typedef typename Solver::MatrixType Mat;
|
||||
typedef typename Mat::Scalar Scalar;
|
||||
typedef SparseMatrix<Scalar,ColMajor> SpMat;
|
||||
typedef SparseMatrix<Scalar,ColMajor, typename Mat::StorageIndex> SpMat;
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
|
||||
typedef Matrix<Scalar,Dynamic,1> DenseVector;
|
||||
|
||||
@ -304,12 +304,12 @@ template<typename Solver> void check_sparse_spd_determinant(Solver& solver)
|
||||
}
|
||||
|
||||
template<typename Solver, typename DenseMat>
|
||||
int generate_sparse_square_problem(Solver&, typename Solver::MatrixType& A, DenseMat& dA, int maxSize = 300, int options = ForceNonZeroDiag)
|
||||
Index generate_sparse_square_problem(Solver&, typename Solver::MatrixType& A, DenseMat& dA, int maxSize = 300, int options = ForceNonZeroDiag)
|
||||
{
|
||||
typedef typename Solver::MatrixType Mat;
|
||||
typedef typename Mat::Scalar Scalar;
|
||||
|
||||
int size = internal::random<int>(1,maxSize);
|
||||
Index size = internal::random<int>(1,maxSize);
|
||||
double density = (std::max)(8./(size*size), 0.01);
|
||||
|
||||
A.resize(size,size);
|
||||
@ -324,7 +324,7 @@ template<typename Solver> void check_sparse_square_solving(Solver& solver)
|
||||
{
|
||||
typedef typename Solver::MatrixType Mat;
|
||||
typedef typename Mat::Scalar Scalar;
|
||||
typedef SparseMatrix<Scalar,ColMajor> SpMat;
|
||||
typedef SparseMatrix<Scalar,ColMajor, typename Mat::StorageIndex> SpMat;
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
|
||||
typedef Matrix<Scalar,Dynamic,1> DenseVector;
|
||||
|
||||
@ -333,7 +333,7 @@ template<typename Solver> void check_sparse_square_solving(Solver& solver)
|
||||
Mat A;
|
||||
DenseMatrix dA;
|
||||
for (int i = 0; i < g_repeat; i++) {
|
||||
int size = generate_sparse_square_problem(solver, A, dA);
|
||||
Index size = generate_sparse_square_problem(solver, A, dA);
|
||||
|
||||
A.makeCompressed();
|
||||
DenseVector b = DenseVector::Random(size);
|
||||
@ -430,7 +430,7 @@ template<typename Solver> void check_sparse_leastsquare_solving(Solver& solver)
|
||||
{
|
||||
typedef typename Solver::MatrixType Mat;
|
||||
typedef typename Mat::Scalar Scalar;
|
||||
typedef SparseMatrix<Scalar,ColMajor> SpMat;
|
||||
typedef SparseMatrix<Scalar,ColMajor, typename Mat::StorageIndex> SpMat;
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
|
||||
typedef Matrix<Scalar,Dynamic,1> DenseVector;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user