Skip to content

Commit

Permalink
dense: use lazyProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarpent committed Nov 8, 2022
1 parent f57f653 commit 1c8d6d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 10 additions & 2 deletions include/proxsuite/linalg/dense/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ noalias_mul_add_impl(Dst dst, Lhs lhs, Rhs rhs, T factor)
return;
}

#if !EIGEN_VERSION_AT_LEAST(3, 3, 8)
#define LAZY_PRODUCT(a, b) a.lazyProdcut(b)
#else
#define LAZY_PRODUCT(a, b) a.operator*(b)
#endif

#if !EIGEN_VERSION_AT_LEAST(3, 3, 8)
if ((dst.rows() < 20) && (dst.cols() < 20) && (rhs.rows() < 20)) {
// gemm
Expand All @@ -804,12 +810,14 @@ noalias_mul_add_impl(Dst dst, Lhs lhs, Rhs rhs, T factor)

auto dst_ =
MapMut(dst.data(), dst.rows(), dst.cols(), { dst.outerStride() });
dst_.noalias().operator+=(factor * lhs.operator*(rhs));
dst_.noalias().operator+=(factor * LAZY_PRODUCT(lhs, rhs));
} else
#endif
{
dst.noalias().operator+=(factor * lhs.operator*(rhs));
dst.noalias().operator+=(factor * LAZY_PRODUCT(lhs, rhs));
}

#undef LAZY_PRODUCT
}
} // namespace _detail
namespace util {
Expand Down
22 changes: 15 additions & 7 deletions include/proxsuite/proxqp/dense/views.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,12 @@ noalias_mul_add(MatrixViewMut<T, colmajor> dst,
return;
}

#if !EIGEN_VERSION_AT_LEAST(3, 3, 8)
#define LAZY_PRODUCT(a, b) a.lazyProdcut(b)
#else
#define LAZY_PRODUCT(a, b) a.operator*(b)
#endif

if (dst.cols == 1 && dst.rows == 1) {
// dot
auto rhs_col = rhs.col(0);
Expand All @@ -1133,7 +1139,7 @@ noalias_mul_add(MatrixViewMut<T, colmajor> dst,
auto rhs_col = rhs.col(0);
auto dst_col = dst.col(0);
dst_col.to_eigen().noalias().operator+=(
factor * (lhs.to_eigen().operator*(rhs_col.to_eigen())));
factor * (LAZY_PRODUCT(lhs.to_eigen(), rhs_col.to_eigen())));
}

#if !EIGEN_VERSION_AT_LEAST(3, 3, 8)
Expand All @@ -1150,19 +1156,21 @@ noalias_mul_add(MatrixViewMut<T, colmajor> dst,
MapMut(dst.data, dst.rows, dst.cols, Stride(dst.outer_stride))
.noalias()
.
operator+=(factor *
Map(lhs.data, lhs.rows, lhs.cols, Stride(lhs.outer_stride))
.
operator*(Map(
rhs.data, rhs.rows, rhs.cols, Stride(rhs.outer_stride))));
operator+=(
factor *
LAZY_PRODUCT(
Map(lhs.data, lhs.rows, lhs.cols, Stride(lhs.outer_stride)),
Map(rhs.data, rhs.rows, rhs.cols, Stride(rhs.outer_stride))));
}
#endif

else {
// gemm
dst.to_eigen().noalias().operator+=(
factor * lhs.to_eigen().operator*(rhs.to_eigen()));
factor * LAZY_PRODUCT(lhs.to_eigen(), rhs.to_eigen()));
}

#undef LAZY_PRODUCT
}

template<typename T>
Expand Down

0 comments on commit 1c8d6d9

Please sign in to comment.