Eigen::internal::selfadjoint_matrix_vector_product< Scalar, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs, Version > Struct Template Reference

#include <SelfadjointMatrixVector.h>

Static Public Member Functions

static EIGEN_DONT_INLINE EIGEN_DEVICE_FUNC void run (Index size, const Scalar *lhs, Index lhsStride, const Scalar *rhs, Scalar *res, Scalar alpha)
 

Member Function Documentation

◆ run()

template<typename Scalar , typename Index , int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs, int Version>
EIGEN_DONT_INLINE EIGEN_DEVICE_FUNC void Eigen::internal::selfadjoint_matrix_vector_product< Scalar, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs, Version >::run ( Index  size,
const Scalar lhs,
Index  lhsStride,
const Scalar rhs,
Scalar res,
Scalar  alpha 
)
static
43  {
44  typedef typename packet_traits<Scalar>::type Packet;
45  typedef typename NumTraits<Scalar>::Real RealScalar;
46  const Index PacketSize = sizeof(Packet) / sizeof(Scalar);
47 
48  enum {
49  IsRowMajor = StorageOrder == RowMajor ? 1 : 0,
50  IsLower = UpLo == Lower ? 1 : 0,
51  FirstTriangular = IsRowMajor == IsLower
52  };
53 
54  conj_helper<Scalar, Scalar, NumTraits<Scalar>::IsComplex && logical_xor(ConjugateLhs, IsRowMajor), ConjugateRhs> cj0;
55  conj_helper<Scalar, Scalar, NumTraits<Scalar>::IsComplex && logical_xor(ConjugateLhs, !IsRowMajor), ConjugateRhs> cj1;
56  conj_helper<RealScalar, Scalar, false, ConjugateRhs> cjd;
57 
58  conj_helper<Packet, Packet, NumTraits<Scalar>::IsComplex && logical_xor(ConjugateLhs, IsRowMajor), ConjugateRhs> pcj0;
59  conj_helper<Packet, Packet, NumTraits<Scalar>::IsComplex && logical_xor(ConjugateLhs, !IsRowMajor), ConjugateRhs>
60  pcj1;
61 
62  Scalar cjAlpha = ConjugateRhs ? numext::conj(alpha) : alpha;
63 
64  Index bound = numext::maxi(Index(0), size - 8) & 0xfffffffe;
65  if (FirstTriangular) bound = size - bound;
66 
67  for (Index j = FirstTriangular ? bound : 0; j < (FirstTriangular ? size : bound); j += 2) {
68  const Scalar* EIGEN_RESTRICT A0 = lhs + j * lhsStride;
69  const Scalar* EIGEN_RESTRICT A1 = lhs + (j + 1) * lhsStride;
70 
71  Scalar t0 = cjAlpha * rhs[j];
72  Packet ptmp0 = pset1<Packet>(t0);
73  Scalar t1 = cjAlpha * rhs[j + 1];
74  Packet ptmp1 = pset1<Packet>(t1);
75 
76  Scalar t2(0);
77  Packet ptmp2 = pset1<Packet>(t2);
78  Scalar t3(0);
79  Packet ptmp3 = pset1<Packet>(t3);
80 
81  Index starti = FirstTriangular ? 0 : j + 2;
82  Index endi = FirstTriangular ? j : size;
83  Index alignedStart = (starti) + internal::first_default_aligned(&res[starti], endi - starti);
84  Index alignedEnd = alignedStart + ((endi - alignedStart) / (PacketSize)) * (PacketSize);
85 
86  res[j] += cjd.pmul(numext::real(A0[j]), t0);
87  res[j + 1] += cjd.pmul(numext::real(A1[j + 1]), t1);
88  if (FirstTriangular) {
89  res[j] += cj0.pmul(A1[j], t1);
90  t3 += cj1.pmul(A1[j], rhs[j]);
91  } else {
92  res[j + 1] += cj0.pmul(A0[j + 1], t0);
93  t2 += cj1.pmul(A0[j + 1], rhs[j + 1]);
94  }
95 
96  for (Index i = starti; i < alignedStart; ++i) {
97  res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i], t1);
98  t2 += cj1.pmul(A0[i], rhs[i]);
99  t3 += cj1.pmul(A1[i], rhs[i]);
100  }
101  // Yes this an optimization for gcc 4.3 and 4.4 (=> huge speed up)
102  // gcc 4.2 does this optimization automatically.
103  const Scalar* EIGEN_RESTRICT a0It = A0 + alignedStart;
104  const Scalar* EIGEN_RESTRICT a1It = A1 + alignedStart;
105  const Scalar* EIGEN_RESTRICT rhsIt = rhs + alignedStart;
106  Scalar* EIGEN_RESTRICT resIt = res + alignedStart;
107  for (Index i = alignedStart; i < alignedEnd; i += PacketSize) {
108  Packet A0i = ploadu<Packet>(a0It);
109  a0It += PacketSize;
110  Packet A1i = ploadu<Packet>(a1It);
111  a1It += PacketSize;
112  Packet Bi = ploadu<Packet>(rhsIt);
113  rhsIt += PacketSize; // FIXME should be aligned in most cases
114  Packet Xi = pload<Packet>(resIt);
115 
116  Xi = pcj0.pmadd(A0i, ptmp0, pcj0.pmadd(A1i, ptmp1, Xi));
117  ptmp2 = pcj1.pmadd(A0i, Bi, ptmp2);
118  ptmp3 = pcj1.pmadd(A1i, Bi, ptmp3);
119  pstore(resIt, Xi);
120  resIt += PacketSize;
121  }
122  for (Index i = alignedEnd; i < endi; i++) {
123  res[i] += cj0.pmul(A0[i], t0) + cj0.pmul(A1[i], t1);
124  t2 += cj1.pmul(A0[i], rhs[i]);
125  t3 += cj1.pmul(A1[i], rhs[i]);
126  }
127 
128  res[j] += alpha * (t2 + predux(ptmp2));
129  res[j + 1] += alpha * (t3 + predux(ptmp3));
130  }
131  for (Index j = FirstTriangular ? 0 : bound; j < (FirstTriangular ? bound : size); j++) {
132  const Scalar* EIGEN_RESTRICT A0 = lhs + j * lhsStride;
133 
134  Scalar t1 = cjAlpha * rhs[j];
135  Scalar t2(0);
136  res[j] += cjd.pmul(numext::real(A0[j]), t1);
137  for (Index i = FirstTriangular ? 0 : j + 1; i < (FirstTriangular ? j : size); i++) {
138  res[i] += cj0.pmul(A0[i], t1);
139  t2 += cj1.pmul(A0[i], rhs[i]);
140  }
141  res[j] += alpha * t2;
142  }
143 }
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_RESTRICT
Definition: Macros.h:1067
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
internal::packet_traits< Scalar >::type Packet
Definition: benchmark-blocking-sizes.cpp:54
@ IsComplex
Definition: common.h:73
float real
Definition: datatypes.h:10
@ Lower
Definition: Constants.h:211
@ RowMajor
Definition: Constants.h:320
RealScalar alpha
Definition: level1_cplx_impl.h:151
constexpr bool logical_xor(bool a, bool b)
Definition: Meta.h:737
static Index first_default_aligned(const DenseBase< Derived > &m)
Definition: DenseCoeffsBase.h:539
EIGEN_DEVICE_FUNC void pstore(Scalar *to, const Packet &from)
Definition: GenericPacketMath.h:891
EIGEN_DEVICE_FUNC unpacket_traits< Packet >::type predux(const Packet &a)
Definition: GenericPacketMath.h:1232
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:926
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
double Bi
Biot number.
Definition: thermal_fibre.cc:85
T Real
Definition: NumTraits.h:183
Scalar type
Definition: GenericPacketMath.h:109
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References alpha, Global_Physical_Variables::Bi, conj(), EIGEN_RESTRICT, Eigen::internal::first_default_aligned(), i, j, Eigen::internal::logical_xor(), Eigen::Lower, Eigen::numext::maxi(), Eigen::internal::conj_helper< LhsType, RhsType, ConjLhs, ConjRhs >::pmadd(), Eigen::internal::conj_helper< LhsType, RhsType, ConjLhs, ConjRhs >::pmul(), Eigen::internal::predux(), Eigen::internal::pstore(), res, Eigen::RowMajor, and size.


The documentation for this struct was generated from the following file: