10 #ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_H
11 #define EIGEN_SELFADJOINT_MATRIX_VECTOR_H
23 template<
typename Scalar,
typename Index,
int StorageOrder,
int UpLo,
bool ConjugateLhs,
bool ConjugateRhs,
int Version=Specialized>
24 struct selfadjoint_matrix_vector_product;
26 template<
typename Scalar,
typename Index,
int StorageOrder,
int UpLo,
bool ConjugateLhs,
bool ConjugateRhs,
int Version>
27 struct selfadjoint_matrix_vector_product
30 static EIGEN_DONT_INLINE
void run(
32 const Scalar* lhs, Index lhsStride,
33 const Scalar* _rhs, Index rhsIncr,
38 template<
typename Scalar,
typename Index,
int StorageOrder,
int UpLo,
bool ConjugateLhs,
bool ConjugateRhs,
int Version>
39 EIGEN_DONT_INLINE
void selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Version>::run(
41 const Scalar* lhs, Index lhsStride,
42 const Scalar* _rhs, Index rhsIncr,
46 typedef typename packet_traits<Scalar>::type Packet;
47 const Index PacketSize =
sizeof(Packet)/
sizeof(Scalar);
50 IsRowMajor = StorageOrder==
RowMajor ? 1 : 0,
51 IsLower = UpLo ==
Lower ? 1 : 0,
52 FirstTriangular = IsRowMajor == IsLower
55 conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> cj0;
56 conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> cj1;
57 conj_helper<Scalar,Scalar,NumTraits<Scalar>::IsComplex, ConjugateRhs> cjd;
59 conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> pcj0;
60 conj_helper<Packet,Packet,NumTraits<Scalar>::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> pcj1;
62 Scalar cjAlpha = ConjugateRhs ? numext::conj(alpha) : alpha;
67 ei_declare_aligned_stack_constructed_variable(Scalar,rhs,size,rhsIncr==1 ? const_cast<Scalar*>(_rhs) : 0);
70 const Scalar* it = _rhs;
71 for (Index i=0; i<size; ++i, it+=rhsIncr)
75 Index bound = (std::max)(Index(0),size-8) & 0xfffffffe;
79 for (Index j=FirstTriangular ? bound : 0;
80 j<(FirstTriangular ? size : bound);j+=2)
82 const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride;
83 const Scalar* EIGEN_RESTRICT A1 = lhs + (j+1)*lhsStride;
85 Scalar t0 = cjAlpha * rhs[j];
86 Packet ptmp0 = pset1<Packet>(t0);
87 Scalar t1 = cjAlpha * rhs[j+1];
88 Packet ptmp1 = pset1<Packet>(t1);
91 Packet ptmp2 = pset1<Packet>(t2);
93 Packet ptmp3 = pset1<Packet>(t3);
95 size_t starti = FirstTriangular ? 0 : j+2;
96 size_t endi = FirstTriangular ? j : size;
97 size_t alignedStart = (starti) + internal::first_default_aligned(&res[starti], endi-starti);
98 size_t alignedEnd = alignedStart + ((endi-alignedStart)/(PacketSize))*(PacketSize);
101 res[j] += cjd.pmul(numext::real(A0[j]), t0);
102 res[j+1] += cjd.pmul(numext::real(A1[j+1]), t1);
105 res[j] += cj0.pmul(A1[j], t1);
106 t3 += cj1.pmul(A1[j], rhs[j]);
110 res[j+1] += cj0.pmul(A0[j+1],t0);
111 t2 += cj1.pmul(A0[j+1], rhs[j+1]);
114 for (
size_t i=starti; i<alignedStart; ++i)
116 res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i],t1);
117 t2 += cj1.pmul(A0[i], rhs[i]);
118 t3 += cj1.pmul(A1[i], rhs[i]);
122 const Scalar* EIGEN_RESTRICT a0It = A0 + alignedStart;
123 const Scalar* EIGEN_RESTRICT a1It = A1 + alignedStart;
124 const Scalar* EIGEN_RESTRICT rhsIt = rhs + alignedStart;
125 Scalar* EIGEN_RESTRICT resIt = res + alignedStart;
126 for (
size_t i=alignedStart; i<alignedEnd; i+=PacketSize)
128 Packet A0i = ploadu<Packet>(a0It); a0It += PacketSize;
129 Packet A1i = ploadu<Packet>(a1It); a1It += PacketSize;
130 Packet Bi = ploadu<Packet>(rhsIt); rhsIt += PacketSize;
131 Packet Xi = pload <Packet>(resIt);
133 Xi = pcj0.pmadd(A0i,ptmp0, pcj0.pmadd(A1i,ptmp1,Xi));
134 ptmp2 = pcj1.pmadd(A0i, Bi, ptmp2);
135 ptmp3 = pcj1.pmadd(A1i, Bi, ptmp3);
136 pstore(resIt,Xi); resIt += PacketSize;
138 for (
size_t i=alignedEnd; i<endi; i++)
140 res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i],t1);
141 t2 += cj1.pmul(A0[i], rhs[i]);
142 t3 += cj1.pmul(A1[i], rhs[i]);
145 res[j] += alpha * (t2 + predux(ptmp2));
146 res[j+1] += alpha * (t3 + predux(ptmp3));
148 for (Index j=FirstTriangular ? 0 : bound;j<(FirstTriangular ? bound : size);j++)
150 const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride;
152 Scalar t1 = cjAlpha * rhs[j];
155 res[j] += cjd.pmul(numext::real(A0[j]), t1);
156 for (Index i=FirstTriangular ? 0 : j+1; i<(FirstTriangular ? j : size); i++)
158 res[i] += cj0.pmul(A0[i], t1);
159 t2 += cj1.pmul(A0[i], rhs[i]);
161 res[j] += alpha * t2;
173 template<
typename Lhs,
int LhsMode,
typename Rhs>
174 struct selfadjoint_product_impl<Lhs,LhsMode,false,Rhs,0,true>
176 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
178 typedef internal::blas_traits<Lhs> LhsBlasTraits;
179 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
180 typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned;
182 typedef internal::blas_traits<Rhs> RhsBlasTraits;
183 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
184 typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
188 template<
typename Dest>
189 static void run(Dest& dest,
const Lhs &a_lhs,
const Rhs &a_rhs,
const Scalar& alpha)
191 typedef typename Dest::Scalar ResScalar;
192 typedef typename Rhs::Scalar RhsScalar;
193 typedef Map<Matrix<ResScalar,Dynamic,1>,
Aligned> MappedDest;
195 eigen_assert(dest.rows()==a_lhs.rows() && dest.cols()==a_rhs.cols());
197 typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs);
198 typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs);
200 Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs)
201 * RhsBlasTraits::extractScalarFactor(a_rhs);
204 EvalToDest = (Dest::InnerStrideAtCompileTime==1),
205 UseRhs = (ActualRhsTypeCleaned::InnerStrideAtCompileTime==1)
208 internal::gemv_static_vector_if<ResScalar,Dest::SizeAtCompileTime,Dest::MaxSizeAtCompileTime,!EvalToDest> static_dest;
209 internal::gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!UseRhs> static_rhs;
211 ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(),
212 EvalToDest ? dest.data() : static_dest.data());
214 ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,rhs.size(),
215 UseRhs ?
const_cast<RhsScalar*
>(rhs.data()) : static_rhs.data());
219 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
220 Index size = dest.size();
221 EIGEN_DENSE_STORAGE_CTOR_PLUGIN
223 MappedDest(actualDestPtr, dest.size()) = dest;
228 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
229 Index size = rhs.size();
230 EIGEN_DENSE_STORAGE_CTOR_PLUGIN
232 Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, rhs.size()) = rhs;
236 internal::selfadjoint_matrix_vector_product<Scalar, Index, (internal::traits<ActualLhsTypeCleaned>::Flags&
RowMajorBit) ?
RowMajor :
ColMajor,
237 int(LhsUpLo), bool(LhsBlasTraits::NeedToConjugate), bool(RhsBlasTraits::NeedToConjugate)>::run
240 &lhs.coeffRef(0,0), lhs.outerStride(),
247 dest = MappedDest(actualDestPtr, dest.size());
251 template<
typename Lhs,
typename Rhs,
int RhsMode>
252 struct selfadjoint_product_impl<Lhs,0,true,Rhs,RhsMode,false>
254 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
257 template<
typename Dest>
258 static void run(Dest& dest,
const Lhs &a_lhs,
const Rhs &a_rhs,
const Scalar& alpha)
261 Transpose<Dest> destT(dest);
262 selfadjoint_product_impl<Transpose<const Rhs>, int(RhsUpLo)==
Upper ?
Lower :
Upper,
false,
263 Transpose<const Lhs>, 0,
true>::run(destT, a_rhs.transpose(), a_lhs.transpose(), alpha);
271 #endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_H
Definition: Constants.h:314
Definition: Constants.h:196
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Constants.h:198
Definition: Eigen_Colamd.h:54
Definition: Constants.h:312
Definition: Constants.h:227