10 #ifndef EIGEN_BLASUTIL_H 11 #define EIGEN_BLASUTIL_H 21 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
typename DataMapper,
int mr,
int nr,
bool ConjugateLhs=false,
bool ConjugateRhs=false>
24 template<
typename Scalar,
typename Index,
typename DataMapper,
int nr,
int StorageOrder,
bool Conjugate = false,
bool PanelMode=false>
27 template<
typename Scalar,
typename Index,
typename DataMapper,
int Pack1,
int Pack2,
int StorageOrder,
bool Conjugate = false,
bool PanelMode = false>
32 typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
33 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
37 template<
typename Index,
38 typename LhsScalar,
typename LhsMapper,
int LhsStorageOrder,
bool ConjugateLhs,
39 typename RhsScalar,
typename RhsMapper,
bool ConjugateRhs,
int Version=Specialized>
47 inline T operator()(
const T& x)
const {
return numext::conj(x); }
49 inline T pconj(
const T& x)
const {
return internal::pconj(x); }
54 inline const T& operator()(
const T& x)
const {
return x; }
56 inline const T& pconj(
const T& x)
const {
return x; }
60 template<
typename LhsScalar,
typename RhsScalar,
bool ConjLhs,
bool ConjRhs>
65 EIGEN_STRONG_INLINE Scalar pmadd(
const LhsScalar& x,
const RhsScalar& y,
const Scalar& c)
const 66 {
return padd(c, pmul(x,y)); }
68 EIGEN_STRONG_INLINE Scalar pmul(
const LhsScalar& x,
const RhsScalar& y)
const 72 template<
typename Scalar>
struct conj_helper<Scalar,Scalar,false,false>
74 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const {
return internal::pmadd(x,y,c); }
75 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const {
return internal::pmul(x,y); }
78 template<
typename RealScalar>
struct conj_helper<
std::
complex<RealScalar>, std::complex<RealScalar>, false,true>
80 typedef std::complex<RealScalar> Scalar;
81 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const 82 {
return c + pmul(x,y); }
84 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const 85 {
return Scalar(numext::real(x)*numext::real(y) + numext::imag(x)*numext::imag(y), numext::imag(x)*numext::real(y) - numext::real(x)*numext::imag(y)); }
88 template<
typename RealScalar>
struct conj_helper<
std::
complex<RealScalar>, std::complex<RealScalar>, true,false>
90 typedef std::complex<RealScalar> Scalar;
91 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const 92 {
return c + pmul(x,y); }
94 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const 95 {
return Scalar(numext::real(x)*numext::real(y) + numext::imag(x)*numext::imag(y), numext::real(x)*numext::imag(y) - numext::imag(x)*numext::real(y)); }
100 typedef std::complex<RealScalar> Scalar;
101 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const 102 {
return c + pmul(x,y); }
104 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const 105 {
return Scalar(numext::real(x)*numext::real(y) - numext::imag(x)*numext::imag(y), - numext::real(x)*numext::imag(y) - numext::imag(x)*numext::real(y)); }
110 typedef std::complex<RealScalar> Scalar;
111 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const RealScalar& y,
const Scalar& c)
const 112 {
return padd(c, pmul(x,y)); }
113 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const RealScalar& y)
const 119 typedef std::complex<RealScalar> Scalar;
120 EIGEN_STRONG_INLINE Scalar pmadd(
const RealScalar& x,
const Scalar& y,
const Scalar& c)
const 121 {
return padd(c, pmul(x,y)); }
122 EIGEN_STRONG_INLINE Scalar pmul(
const RealScalar& x,
const Scalar& y)
const 127 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE To run(
const From& x) {
return To(x); }
136 template<
typename Scalar,
typename Index>
139 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
BlasVectorMapper(Scalar *data) : m_data(data) {}
141 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(
Index i)
const {
144 template <
typename Packet,
int AlignmentType>
145 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
Packet load(
Index i)
const {
146 return ploadt<Packet, AlignmentType>(m_data + i);
149 template <
typename Packet>
150 EIGEN_DEVICE_FUNC
bool aligned(
Index i)
const {
151 return (UIntPtr(m_data+i)%
sizeof(
Packet))==0;
158 template<
typename Scalar,
typename Index,
int AlignmentType>
164 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
BlasLinearMapper(Scalar *data) : m_data(data) {}
166 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void prefetch(
int i)
const {
167 internal::prefetch(&
operator()(i));
170 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(
Index i)
const {
174 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet loadPacket(
Index i)
const {
175 return ploadt<Packet, AlignmentType>(m_data + i);
178 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE HalfPacket loadHalfPacket(
Index i)
const {
179 return ploadt<HalfPacket, AlignmentType>(m_data + i);
182 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void storePacket(
Index i,
const Packet &p)
const {
183 pstoret<Scalar, Packet, AlignmentType>(m_data + i, p);
191 template<
typename Scalar,
typename Index,
int StorageOrder,
int AlignmentType = Unaligned>
200 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
blas_data_mapper(Scalar* data,
Index stride) : m_data(data), m_stride(stride) {}
207 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(
Index i,
Index j)
const {
208 return LinearMapper(&
operator()(i, j));
211 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE VectorMapper getVectorMapper(
Index i,
Index j)
const {
212 return VectorMapper(&
operator()(i, j));
217 EIGEN_ALWAYS_INLINE Scalar& operator()(
Index i,
Index j)
const {
218 return m_data[StorageOrder==
RowMajor ? j + i*m_stride : i + j*m_stride];
221 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet loadPacket(
Index i,
Index j)
const {
222 return ploadt<Packet, AlignmentType>(&operator()(i, j));
225 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE HalfPacket loadHalfPacket(
Index i,
Index j)
const {
226 return ploadt<HalfPacket, AlignmentType>(&operator()(i, j));
229 template<
typename SubPacket>
230 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void scatterPacket(
Index i,
Index j,
const SubPacket &p)
const {
231 pscatter<Scalar, SubPacket>(&operator()(i, j), p, m_stride);
234 template<
typename SubPacket>
235 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE SubPacket gatherPacket(
Index i,
Index j)
const {
236 return pgather<Scalar, SubPacket>(&operator()(i, j), m_stride);
239 EIGEN_DEVICE_FUNC
const Index stride()
const {
return m_stride; }
240 EIGEN_DEVICE_FUNC
const Scalar* data()
const {
return m_data; }
242 EIGEN_DEVICE_FUNC
Index firstAligned(
Index size)
const {
243 if (UIntPtr(m_data)%
sizeof(Scalar)) {
246 return internal::first_default_aligned(m_data, size);
250 Scalar* EIGEN_RESTRICT m_data;
251 const Index m_stride;
255 template<
typename Scalar,
typename Index,
int StorageOrder>
272 typedef const XprType& ExtractType;
273 typedef XprType _ExtractType;
276 IsTransposed =
false,
277 NeedToConjugate =
false,
279 && (
bool(XprType::IsVectorAtCompileTime)
283 typedef typename conditional<bool(HasUsableDirectAccess),
285 typename _ExtractType::PlainObject
287 static inline ExtractType extract(
const XprType& x) {
return x; }
288 static inline const Scalar extractScalarFactor(
const XprType&) {
return Scalar(1); }
292 template<
typename Scalar,
typename NestedXpr>
298 typedef typename Base::ExtractType ExtractType;
302 NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex
304 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.
nestedExpression()); }
305 static inline Scalar extractScalarFactor(
const XprType& x) {
return conj(Base::extractScalarFactor(x.
nestedExpression())); }
309 template<
typename Scalar,
typename NestedXpr,
typename Plain>
315 typedef typename Base::ExtractType ExtractType;
316 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.
rhs()); }
317 static inline Scalar extractScalarFactor(
const XprType& x)
318 {
return x.
lhs().functor().m_other * Base::extractScalarFactor(x.
rhs()); }
320 template<
typename Scalar,
typename NestedXpr,
typename Plain>
326 typedef typename Base::ExtractType ExtractType;
327 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.
lhs()); }
328 static inline Scalar extractScalarFactor(
const XprType& x)
329 {
return Base::extractScalarFactor(x.
lhs()) * x.
rhs().functor().m_other; }
331 template<
typename Scalar,
typename Plain1,
typename Plain2>
334 :
blas_traits<CwiseNullaryOp<scalar_constant_op<Scalar>,Plain1> >
338 template<
typename Scalar,
typename NestedXpr>
344 typedef typename Base::ExtractType ExtractType;
345 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.
nestedExpression()); }
346 static inline Scalar extractScalarFactor(
const XprType& x)
351 template<
typename NestedXpr>
355 typedef typename NestedXpr::Scalar Scalar;
360 typedef typename conditional<bool(Base::HasUsableDirectAccess),
362 typename ExtractType::PlainObject
365 IsTransposed = Base::IsTransposed ? 0 : 1
367 static inline ExtractType extract(
const XprType& x) {
return ExtractType(Base::extract(x.
nestedExpression())); }
368 static inline Scalar extractScalarFactor(
const XprType& x) {
return Base::extractScalarFactor(x.
nestedExpression()); }
376 template<typename T, bool HasUsableDirectAccess=blas_traits<T>::HasUsableDirectAccess>
378 static const typename T::Scalar* run(
const T& m)
386 static typename T::Scalar* run(
const T&) {
return 0; }
389 template<
typename T>
const typename T::Scalar* extract_data(
const T& m)
398 #endif // EIGEN_BLASUTIL_H Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:60
Definition: DenseCoeffsBase.h:654
Definition: UnaryFunctors.h:109
Definition: BlasUtil.h:269
Definition: BlasUtil.h:28
Definition: BlasUtil.h:61
Expression of the transpose of a matrix.
Definition: Transpose.h:52
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array...
Definition: Constants.h:150
Definition: BlasUtil.h:126
Definition: UnaryFunctors.h:22
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
EIGEN_DEVICE_FUNC const _RhsNested & rhs() const
Definition: CwiseBinaryOp.h:135
EIGEN_DEVICE_FUNC const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: Transpose.h:74
Definition: BlasUtil.h:35
Definition: GenericPacketMath.h:96
Definition: BinaryFunctors.h:76
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
Definition: BlasUtil.h:43
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: BlasUtil.h:159
Definition: BlasUtil.h:137
Definition: BlasUtil.h:256
Definition: BlasUtil.h:40
Definition: BlasUtil.h:192
Definition: PacketMath.h:48
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:322
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:757
Definition: datatypes.h:12
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all< XprTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryOp.h:80
Definition: ForwardDeclarations.h:17
EIGEN_DEVICE_FUNC const _LhsNested & lhs() const
Definition: CwiseBinaryOp.h:132
Definition: BlasUtil.h:25
Definition: NullaryFunctors.h:18