mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-05-22 12:37:35 +08:00
Fix nesting sub-expression in outer-products
This commit is contained in:
parent
4140ee039d
commit
c9718514f5
@ -218,12 +218,12 @@ template<typename Dst, typename Lhs, typename Rhs, typename Func>
|
|||||||
EIGEN_DONT_INLINE void outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const false_type&)
|
EIGEN_DONT_INLINE void outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const false_type&)
|
||||||
{
|
{
|
||||||
evaluator<Rhs> rhsEval(rhs);
|
evaluator<Rhs> rhsEval(rhs);
|
||||||
// FIXME make sure lhs is sequentially stored
|
typename nested_eval<Lhs,Rhs::SizeAtCompileTime>::type actual_lhs(lhs);
|
||||||
|
// FIXME if cols is large enough, then it might be useful to make sure that lhs is sequentially stored
|
||||||
// FIXME not very good if rhs is real and lhs complex while alpha is real too
|
// FIXME not very good if rhs is real and lhs complex while alpha is real too
|
||||||
// FIXME we should probably build an evaluator for dst
|
|
||||||
const Index cols = dst.cols();
|
const Index cols = dst.cols();
|
||||||
for (Index j=0; j<cols; ++j)
|
for (Index j=0; j<cols; ++j)
|
||||||
func(dst.col(j), rhsEval.coeff(0,j) * lhs);
|
func(dst.col(j), rhsEval.coeff(0,j) * actual_lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Row major result
|
// Row major result
|
||||||
@ -231,12 +231,12 @@ template<typename Dst, typename Lhs, typename Rhs, typename Func>
|
|||||||
EIGEN_DONT_INLINE void outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const true_type&)
|
EIGEN_DONT_INLINE void outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const true_type&)
|
||||||
{
|
{
|
||||||
evaluator<Lhs> lhsEval(lhs);
|
evaluator<Lhs> lhsEval(lhs);
|
||||||
// FIXME make sure rhs is sequentially stored
|
typename nested_eval<Rhs,Lhs::SizeAtCompileTime>::type actual_rhs(rhs);
|
||||||
|
// FIXME if rows is large enough, then it might be useful to make sure that rhs is sequentially stored
|
||||||
// FIXME not very good if lhs is real and rhs complex while alpha is real too
|
// FIXME not very good if lhs is real and rhs complex while alpha is real too
|
||||||
// FIXME we should probably build an evaluator for dst
|
|
||||||
const Index rows = dst.rows();
|
const Index rows = dst.rows();
|
||||||
for (Index i=0; i<rows; ++i)
|
for (Index i=0; i<rows; ++i)
|
||||||
func(dst.row(i), lhsEval.coeff(i,0) * rhs);
|
func(dst.row(i), lhsEval.coeff(i,0) * actual_rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs>
|
template<typename Lhs, typename Rhs>
|
||||||
|
@ -62,7 +62,7 @@ template<typename MatrixType> void product_notemporary(const MatrixType& m)
|
|||||||
VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).template triangularView<Lower>() * m2, 0);
|
VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).template triangularView<Lower>() * m2, 0);
|
||||||
VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView<Upper>() * (m2+m2), 1);
|
VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView<Upper>() * (m2+m2), 1);
|
||||||
VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView<UnitUpper>() * m2.adjoint(), 0);
|
VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView<UnitUpper>() * m2.adjoint(), 0);
|
||||||
|
|
||||||
VERIFY_EVALUATION_COUNT( m3.template triangularView<Upper>() = (m1 * m2.adjoint()), 0);
|
VERIFY_EVALUATION_COUNT( m3.template triangularView<Upper>() = (m1 * m2.adjoint()), 0);
|
||||||
VERIFY_EVALUATION_COUNT( m3.template triangularView<Upper>() -= (m1 * m2.adjoint()), 0);
|
VERIFY_EVALUATION_COUNT( m3.template triangularView<Upper>() -= (m1 * m2.adjoint()), 0);
|
||||||
|
|
||||||
@ -112,6 +112,17 @@ template<typename MatrixType> void product_notemporary(const MatrixType& m)
|
|||||||
VERIFY_EVALUATION_COUNT( cvres.noalias() = (rm3+rm3) * cv1, 0 );
|
VERIFY_EVALUATION_COUNT( cvres.noalias() = (rm3+rm3) * cv1, 0 );
|
||||||
VERIFY_EVALUATION_COUNT( cvres.noalias() = (m1+m1) * (m1*cv1), 1 );
|
VERIFY_EVALUATION_COUNT( cvres.noalias() = (m1+m1) * (m1*cv1), 1 );
|
||||||
VERIFY_EVALUATION_COUNT( cvres.noalias() = (rm3+rm3) * (m1*cv1), 1 );
|
VERIFY_EVALUATION_COUNT( cvres.noalias() = (rm3+rm3) * (m1*cv1), 1 );
|
||||||
|
|
||||||
|
// Check outer products
|
||||||
|
m3 = cv1 * rv1;
|
||||||
|
VERIFY_EVALUATION_COUNT( m3.noalias() = cv1 * rv1, 0 );
|
||||||
|
VERIFY_EVALUATION_COUNT( m3.noalias() = (cv1+cv1) * (rv1+rv1), 1 );
|
||||||
|
VERIFY_EVALUATION_COUNT( m3.noalias() = (m1*cv1) * (rv1), 1 );
|
||||||
|
VERIFY_EVALUATION_COUNT( m3.noalias() += (m1*cv1) * (rv1), 1 );
|
||||||
|
VERIFY_EVALUATION_COUNT( rm3.noalias() = (cv1) * (rv1 * m1), 1 );
|
||||||
|
VERIFY_EVALUATION_COUNT( rm3.noalias() -= (cv1) * (rv1 * m1), 1 );
|
||||||
|
VERIFY_EVALUATION_COUNT( rm3.noalias() = (m1*cv1) * (rv1 * m1), 2 );
|
||||||
|
VERIFY_EVALUATION_COUNT( rm3.noalias() += (m1*cv1) * (rv1 * m1), 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_product_notemporary()
|
void test_product_notemporary()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user