Made fastSparseProduct std::move-friendly

This commit is contained in:
babrodtk 2015-08-28 14:16:05 +02:00
parent 0b1f993588
commit a30d6586a3
2 changed files with 23 additions and 20 deletions

View File

@ -462,8 +462,7 @@ namespace Opm
retval.type_ = S;
retval.rows_ = lhs.rows_;
retval.cols_ = rhs.cols_;
retval.sparse_[0] = Sparse(retval.rows_, retval.cols_);
fastDiagSparseProduct(lhs.diag_, rhs.sparse_[0], retval.sparse_[0]);
retval.sparse_[0] = std::move(fastDiagSparseProduct(lhs.diag_, rhs.sparse_[0]));
return retval;
}
@ -475,8 +474,7 @@ namespace Opm
retval.type_ = S;
retval.rows_ = lhs.rows_;
retval.cols_ = rhs.cols_;
retval.sparse_[0] = Sparse(retval.rows_, retval.cols_);
fastSparseDiagProduct(lhs.sparse_[0], rhs.diag_, retval.sparse_[0]);
retval.sparse_[0] = std::move(fastSparseDiagProduct(lhs.sparse_[0], rhs.diag_));
return retval;
}
@ -488,8 +486,7 @@ namespace Opm
retval.type_ = S;
retval.rows_ = lhs.rows_;
retval.cols_ = rhs.cols_;
retval.sparse_[0] = Sparse(retval.rows_, retval.cols_);
fastSparseProduct(lhs.sparse_[0], rhs.sparse_[0], retval.sparse_[0]);
retval.sparse_[0] = std::move(fastSparseProduct<Sparse>(lhs.sparse_[0], rhs.sparse_[0]));
return retval;
}

View File

@ -56,16 +56,16 @@ struct QuickSort< 0 >
};
template<typename Lhs, typename Rhs, typename ResultType>
void fastSparseProduct(const Lhs& lhs, const Rhs& rhs, ResultType& res)
template<typename ResultType, typename Lhs, typename Rhs>
ResultType fastSparseProduct(const Lhs& lhs, const Rhs& rhs)
{
// initialize result
res = ResultType(lhs.rows(), rhs.cols());
ResultType res(lhs.rows(), rhs.cols());
// if one of the matrices does not contain non zero elements
// the result will only contain an empty matrix
if( lhs.nonZeros() == 0 || rhs.nonZeros() == 0 )
return;
return res;
typedef typename Eigen::internal::remove_all<Lhs>::type::Scalar Scalar;
typedef typename Eigen::internal::remove_all<Lhs>::type::Index Index;
@ -137,17 +137,19 @@ void fastSparseProduct(const Lhs& lhs, const Rhs& rhs, ResultType& res)
}
res.finalize();
return res;
}
inline void fastDiagSparseProduct(// const Eigen::DiagonalMatrix<double, Eigen::Dynamic>& lhs,
const std::vector<double>& lhs,
const Eigen::SparseMatrix<double>& rhs,
Eigen::SparseMatrix<double>& res)
inline
Eigen::SparseMatrix<double>
fastDiagSparseProduct(const std::vector<double>& lhs,
const Eigen::SparseMatrix<double>& rhs)
{
res = rhs;
Eigen::SparseMatrix<double> res = rhs;
// Multiply rows by diagonal lhs.
int n = res.cols();
@ -157,17 +159,19 @@ inline void fastDiagSparseProduct(// const Eigen::DiagonalMatrix<double, Eigen::
it.valueRef() *= lhs[it.row()]; // lhs.diagonal()(it.row());
}
}
return res;
}
inline void fastSparseDiagProduct(const Eigen::SparseMatrix<double>& lhs,
// const Eigen::DiagonalMatrix<double, Eigen::Dynamic>& rhs,
const std::vector<double>& rhs,
Eigen::SparseMatrix<double>& res)
inline
Eigen::SparseMatrix<double>
fastSparseDiagProduct(const Eigen::SparseMatrix<double>& lhs,
const std::vector<double>& rhs)
{
res = lhs;
Eigen::SparseMatrix<double> res = lhs;
// Multiply columns by diagonal rhs.
int n = res.cols();
@ -177,6 +181,8 @@ inline void fastSparseDiagProduct(const Eigen::SparseMatrix<double>& lhs,
it.valueRef() *= rhs[col]; // rhs.diagonal()(col);
}
}
return res;
}