mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-12-26 17:20:59 -06:00
Made fastSparseProduct std::move-friendly
This commit is contained in:
parent
0b1f993588
commit
a30d6586a3
@ -462,8 +462,7 @@ namespace Opm
|
|||||||
retval.type_ = S;
|
retval.type_ = S;
|
||||||
retval.rows_ = lhs.rows_;
|
retval.rows_ = lhs.rows_;
|
||||||
retval.cols_ = rhs.cols_;
|
retval.cols_ = rhs.cols_;
|
||||||
retval.sparse_[0] = Sparse(retval.rows_, retval.cols_);
|
retval.sparse_[0] = std::move(fastDiagSparseProduct(lhs.diag_, rhs.sparse_[0]));
|
||||||
fastDiagSparseProduct(lhs.diag_, rhs.sparse_[0], retval.sparse_[0]);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,8 +474,7 @@ namespace Opm
|
|||||||
retval.type_ = S;
|
retval.type_ = S;
|
||||||
retval.rows_ = lhs.rows_;
|
retval.rows_ = lhs.rows_;
|
||||||
retval.cols_ = rhs.cols_;
|
retval.cols_ = rhs.cols_;
|
||||||
retval.sparse_[0] = Sparse(retval.rows_, retval.cols_);
|
retval.sparse_[0] = std::move(fastSparseDiagProduct(lhs.sparse_[0], rhs.diag_));
|
||||||
fastSparseDiagProduct(lhs.sparse_[0], rhs.diag_, retval.sparse_[0]);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,8 +486,7 @@ namespace Opm
|
|||||||
retval.type_ = S;
|
retval.type_ = S;
|
||||||
retval.rows_ = lhs.rows_;
|
retval.rows_ = lhs.rows_;
|
||||||
retval.cols_ = rhs.cols_;
|
retval.cols_ = rhs.cols_;
|
||||||
retval.sparse_[0] = Sparse(retval.rows_, retval.cols_);
|
retval.sparse_[0] = std::move(fastSparseProduct<Sparse>(lhs.sparse_[0], rhs.sparse_[0]));
|
||||||
fastSparseProduct(lhs.sparse_[0], rhs.sparse_[0], retval.sparse_[0]);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,16 +56,16 @@ struct QuickSort< 0 >
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs, typename ResultType>
|
template<typename ResultType, typename Lhs, typename Rhs>
|
||||||
void fastSparseProduct(const Lhs& lhs, const Rhs& rhs, ResultType& res)
|
ResultType fastSparseProduct(const Lhs& lhs, const Rhs& rhs)
|
||||||
{
|
{
|
||||||
// initialize result
|
// 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
|
// if one of the matrices does not contain non zero elements
|
||||||
// the result will only contain an empty matrix
|
// the result will only contain an empty matrix
|
||||||
if( lhs.nonZeros() == 0 || rhs.nonZeros() == 0 )
|
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::Scalar Scalar;
|
||||||
typedef typename Eigen::internal::remove_all<Lhs>::type::Index Index;
|
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();
|
res.finalize();
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void fastDiagSparseProduct(// const Eigen::DiagonalMatrix<double, Eigen::Dynamic>& lhs,
|
inline
|
||||||
const std::vector<double>& lhs,
|
Eigen::SparseMatrix<double>
|
||||||
const Eigen::SparseMatrix<double>& rhs,
|
fastDiagSparseProduct(const std::vector<double>& lhs,
|
||||||
Eigen::SparseMatrix<double>& res)
|
const Eigen::SparseMatrix<double>& rhs)
|
||||||
{
|
{
|
||||||
res = rhs;
|
Eigen::SparseMatrix<double> res = rhs;
|
||||||
|
|
||||||
// Multiply rows by diagonal lhs.
|
// Multiply rows by diagonal lhs.
|
||||||
int n = res.cols();
|
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());
|
it.valueRef() *= lhs[it.row()]; // lhs.diagonal()(it.row());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void fastSparseDiagProduct(const Eigen::SparseMatrix<double>& lhs,
|
inline
|
||||||
// const Eigen::DiagonalMatrix<double, Eigen::Dynamic>& rhs,
|
Eigen::SparseMatrix<double>
|
||||||
const std::vector<double>& rhs,
|
fastSparseDiagProduct(const Eigen::SparseMatrix<double>& lhs,
|
||||||
Eigen::SparseMatrix<double>& res)
|
const std::vector<double>& rhs)
|
||||||
{
|
{
|
||||||
res = lhs;
|
Eigen::SparseMatrix<double> res = lhs;
|
||||||
|
|
||||||
// Multiply columns by diagonal rhs.
|
// Multiply columns by diagonal rhs.
|
||||||
int n = res.cols();
|
int n = res.cols();
|
||||||
@ -177,6 +181,8 @@ inline void fastSparseDiagProduct(const Eigen::SparseMatrix<double>& lhs,
|
|||||||
it.valueRef() *= rhs[col]; // rhs.diagonal()(col);
|
it.valueRef() *= rhs[col]; // rhs.diagonal()(col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user