10 #ifndef EIGEN_SKYLINEPRODUCT_H
11 #define EIGEN_SKYLINEPRODUCT_H
13 #include "./InternalHeaderCheck.h"
17 template<
typename Lhs,
typename Rhs,
int ProductMode>
18 struct SkylineProductReturnType {
19 typedef const typename internal::nested_eval<Lhs, Rhs::RowsAtCompileTime>::type LhsNested;
20 typedef const typename internal::nested_eval<Rhs, Lhs::RowsAtCompileTime>::type RhsNested;
22 typedef SkylineProduct<LhsNested, RhsNested, ProductMode> Type;
25 template<
typename LhsNested,
typename RhsNested,
int ProductMode>
26 struct internal::traits<SkylineProduct<LhsNested, RhsNested, ProductMode> > {
28 typedef internal::remove_all_t<LhsNested> LhsNested_;
29 typedef internal::remove_all_t<RhsNested> RhsNested_;
30 typedef typename LhsNested_::Scalar Scalar;
33 LhsCoeffReadCost = LhsNested_::CoeffReadCost,
34 RhsCoeffReadCost = RhsNested_::CoeffReadCost,
35 LhsFlags = LhsNested_::Flags,
36 RhsFlags = RhsNested_::Flags,
38 RowsAtCompileTime = LhsNested_::RowsAtCompileTime,
39 ColsAtCompileTime = RhsNested_::ColsAtCompileTime,
40 InnerSize = internal::min_size_prefer_fixed(LhsNested_::ColsAtCompileTime, RhsNested_::RowsAtCompileTime),
42 MaxRowsAtCompileTime = LhsNested_::MaxRowsAtCompileTime,
43 MaxColsAtCompileTime = RhsNested_::MaxColsAtCompileTime,
45 EvalToRowMajor = (RhsFlags & LhsFlags &
RowMajorBit),
46 ResultIsSkyline = ProductMode == SkylineTimeSkylineProduct,
48 RemovedBits = ~((EvalToRowMajor ? 0 :
RowMajorBit) | (ResultIsSkyline ? 0 : SkylineBit)),
50 Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
57 typedef std::conditional_t<ResultIsSkyline,
58 SkylineMatrixBase<SkylineProduct<LhsNested, RhsNested, ProductMode> >,
59 MatrixBase<SkylineProduct<LhsNested, RhsNested, ProductMode> > > Base;
63 template<
typename LhsNested,
typename RhsNested,
int ProductMode>
64 class SkylineProduct : no_assignment_operator,
65 public traits<SkylineProduct<LhsNested, RhsNested, ProductMode> >::Base {
68 EIGEN_GENERIC_PUBLIC_INTERFACE(SkylineProduct)
72 typedef typename traits<SkylineProduct>::LhsNested_ LhsNested_;
73 typedef typename traits<SkylineProduct>::RhsNested_ RhsNested_;
77 template<
typename Lhs,
typename Rhs>
78 EIGEN_STRONG_INLINE SkylineProduct(
const Lhs& lhs,
const Rhs& rhs)
79 : m_lhs(lhs), m_rhs(rhs) {
80 eigen_assert(lhs.cols() == rhs.rows());
83 ProductIsValid = LhsNested_::ColsAtCompileTime ==
Dynamic
84 || RhsNested_::RowsAtCompileTime ==
Dynamic
85 || int(LhsNested_::ColsAtCompileTime) == int(RhsNested_::RowsAtCompileTime),
86 AreVectors = LhsNested_::IsVectorAtCompileTime && RhsNested_::IsVectorAtCompileTime,
87 SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(LhsNested_, RhsNested_)
92 EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
93 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
94 EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
95 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
96 EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
99 EIGEN_STRONG_INLINE
Index rows()
const {
103 EIGEN_STRONG_INLINE
Index cols()
const {
107 EIGEN_STRONG_INLINE
const LhsNested_& lhs()
const {
111 EIGEN_STRONG_INLINE
const RhsNested_& rhs()
const {
123 template<
typename Lhs,
typename Rhs,
typename Dest>
124 EIGEN_DONT_INLINE
void skyline_row_major_time_dense_product(
const Lhs& lhs,
const Rhs& rhs, Dest& dst) {
125 typedef remove_all_t<Lhs> Lhs_;
126 typedef remove_all_t<Rhs> Rhs_;
127 typedef typename traits<Lhs>::Scalar Scalar;
131 LhsIsSelfAdjoint = (Lhs_::Flags & SelfAdjointBit) == SelfAdjointBit,
132 ProcessFirstHalf = LhsIsSelfAdjoint
133 && (((Lhs_::Flags & (UpperTriangularBit | LowerTriangularBit)) == 0)
134 || ((Lhs_::Flags & UpperTriangularBit) && !LhsIsRowMajor)
135 || ((Lhs_::Flags & LowerTriangularBit) && LhsIsRowMajor)),
136 ProcessSecondHalf = LhsIsSelfAdjoint && (!ProcessFirstHalf)
140 for (
Index col = 0; col < rhs.cols(); col++) {
141 for (
Index row = 0; row < lhs.rows(); row++) {
142 dst(row, col) = lhs.coeffDiag(row) * rhs(row, col);
146 for (
Index row = 0; row < lhs.rows(); row++) {
147 typename Lhs_::InnerLowerIterator lIt(lhs, row);
148 const Index stop = lIt.col() + lIt.size();
149 for (
Index col = 0; col < rhs.cols(); col++) {
159 dst(row, col) += tmp;
166 for (
Index lhscol = 0; lhscol < lhs.cols(); lhscol++) {
167 typename Lhs_::InnerUpperIterator uIt(lhs, lhscol);
168 const Index stop = uIt.size() + uIt.row();
169 for (
Index rhscol = 0; rhscol < rhs.cols(); rhscol++) {
172 const Scalar rhsCoeff = rhs.coeff(lhscol, rhscol);
186 template<
typename Lhs,
typename Rhs,
typename Dest>
187 EIGEN_DONT_INLINE
void skyline_col_major_time_dense_product(
const Lhs& lhs,
const Rhs& rhs, Dest& dst) {
188 typedef remove_all_t<Lhs> Lhs_;
189 typedef remove_all_t<Rhs> Rhs_;
190 typedef typename traits<Lhs>::Scalar Scalar;
194 LhsIsSelfAdjoint = (Lhs_::Flags & SelfAdjointBit) == SelfAdjointBit,
195 ProcessFirstHalf = LhsIsSelfAdjoint
196 && (((Lhs_::Flags & (UpperTriangularBit | LowerTriangularBit)) == 0)
197 || ((Lhs_::Flags & UpperTriangularBit) && !LhsIsRowMajor)
198 || ((Lhs_::Flags & LowerTriangularBit) && LhsIsRowMajor)),
199 ProcessSecondHalf = LhsIsSelfAdjoint && (!ProcessFirstHalf)
203 for (
Index col = 0; col < rhs.cols(); col++) {
204 for (
Index row = 0; row < lhs.rows(); row++) {
205 dst(row, col) = lhs.coeffDiag(row) * rhs(row, col);
210 for (
Index row = 0; row < lhs.rows(); row++) {
211 typename Lhs_::InnerUpperIterator uIt(lhs, row);
212 const Index stop = uIt.col() + uIt.size();
213 for (
Index col = 0; col < rhs.cols(); col++) {
225 dst(row, col) += tmp;
231 for (
Index lhscol = 0; lhscol < lhs.cols(); lhscol++) {
232 typename Lhs_::InnerLowerIterator lIt(lhs, lhscol);
233 const Index stop = lIt.size() + lIt.row();
234 for (
Index rhscol = 0; rhscol < rhs.cols(); rhscol++) {
236 const Scalar rhsCoeff = rhs.coeff(lhscol, rhscol);
250 template<
typename Lhs,
typename Rhs,
typename ResultType,
251 int LhsStorageOrder = traits<Lhs>::Flags&
RowMajorBit>
252 struct skyline_product_selector;
254 template<
typename Lhs,
typename Rhs,
typename ResultType>
255 struct skyline_product_selector<Lhs, Rhs, ResultType,
RowMajor> {
256 typedef typename traits<remove_all_t<Lhs>>::Scalar Scalar;
258 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType & res) {
259 skyline_row_major_time_dense_product<Lhs, Rhs, ResultType > (lhs, rhs, res);
263 template<
typename Lhs,
typename Rhs,
typename ResultType>
264 struct skyline_product_selector<Lhs, Rhs, ResultType,
ColMajor> {
265 typedef typename traits<remove_all_t<Lhs>>::Scalar Scalar;
267 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType & res) {
268 skyline_col_major_time_dense_product<Lhs, Rhs, ResultType > (lhs, rhs, res);
287 template<
typename Derived>
288 template<
typename OtherDerived >
289 EIGEN_STRONG_INLINE
const typename SkylineProductReturnType<Derived, OtherDerived>::Type
290 SkylineMatrixBase<Derived>::operator*(
const MatrixBase<OtherDerived> &other)
const {
292 return typename SkylineProductReturnType<Derived, OtherDerived>::Type(derived(), other.derived());
EIGEN_DEPRECATED const unsigned int EvalBeforeAssigningBit
const unsigned int EvalBeforeNestingBit
const unsigned int RowMajorBit
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index