10#ifndef EIGEN_BLASUTIL_H
11#define EIGEN_BLASUTIL_H
21template<
typename LhsScalar,
typename RhsScalar,
typename Index,
typename DataMapper,
int mr,
int nr,
bool ConjugateLhs=false,
bool ConjugateRhs=false>
24template<
typename Scalar,
typename Index,
typename DataMapper,
int nr,
int StorageOrder,
bool Conjugate = false,
bool PanelMode=false>
27template<
typename Scalar,
typename Index,
typename DataMapper,
int Pack1,
int Pack2,
typename Packet,
int StorageOrder,
bool Conjugate = false,
bool PanelMode = false>
37template<
typename Index,
43 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE
To run(
const From& x) {
return To(x); }
52template<
typename Scalar,
typename Index>
55 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
BlasVectorMapper(Scalar *data) : m_data(data) {}
57 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(
Index i)
const {
60 template <
typename Packet,
int AlignmentType>
61 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
Packet load(
Index i)
const {
65 template <
typename Packet>
66 EIGEN_DEVICE_FUNC
bool aligned(
Index i)
const {
67 return (UIntPtr(m_data+i)%
sizeof(
Packet))==0;
74template<
typename Scalar,
typename Index,
int AlignmentType,
int Incr=1>
77template<
typename Scalar,
typename Index,
int AlignmentType>
84 EIGEN_ONLY_USED_FOR_DEBUG(
incr);
85 eigen_assert(
incr==1);
88 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void prefetch(
int i)
const {
89 internal::prefetch(&
operator()(i));
92 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(
Index i)
const {
96 template<
typename PacketType>
97 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(
Index i)
const {
101 template<
typename PacketType>
102 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void storePacket(
Index i,
const PacketType &p)
const {
111template<
typename Scalar,
typename Index,
int StorageOrder,
int AlignmentType = Unaligned,
int Incr = 1>
118template<
typename Index,
typename Scalar,
typename Packet,
int n,
int idx,
int StorageOrder>
123 pbm.store(to, stride, i, j, block);
129template<
typename Index,
typename Scalar,
typename Packet,
int n,
int idx>
134 pbm.store(to, stride, i, j, block);
139template<
typename Index,
typename Scalar,
typename Packet,
int n,
int StorageOrder>
143 EIGEN_UNUSED_VARIABLE(to);
144 EIGEN_UNUSED_VARIABLE(stride);
145 EIGEN_UNUSED_VARIABLE(i);
146 EIGEN_UNUSED_VARIABLE(j);
147 EIGEN_UNUSED_VARIABLE(block);
151template<
typename Index,
typename Scalar,
typename Packet,
int n>
155 EIGEN_UNUSED_VARIABLE(to);
156 EIGEN_UNUSED_VARIABLE(stride);
157 EIGEN_UNUSED_VARIABLE(i);
158 EIGEN_UNUSED_VARIABLE(j);
159 EIGEN_UNUSED_VARIABLE(block);
163template<
typename Scalar,
typename Index,
int StorageOrder,
int AlignmentType>
171 : m_data(data), m_stride(stride)
173 EIGEN_ONLY_USED_FOR_DEBUG(
incr);
174 eigen_assert(
incr==1);
192 EIGEN_ALWAYS_INLINE Scalar& operator()(
Index i,
Index j)
const {
193 return m_data[StorageOrder==
RowMajor ? j + i*m_stride : i + j*m_stride];
196 template<
typename PacketType>
197 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(
Index i,
Index j)
const {
201 template <
typename PacketT,
int AlignmentT>
206 template<
typename SubPacket>
207 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void scatterPacket(
Index i,
Index j,
const SubPacket &p)
const {
211 template<
typename SubPacket>
216 EIGEN_DEVICE_FUNC
const Index stride()
const {
return m_stride; }
217 EIGEN_DEVICE_FUNC
const Scalar* data()
const {
return m_data; }
219 EIGEN_DEVICE_FUNC
Index firstAligned(
Index size)
const {
220 if (UIntPtr(m_data)%
sizeof(Scalar)) {
223 return internal::first_default_aligned(m_data, size);
226 template<
typename SubPacket,
int n>
229 pbm.store(m_data, m_stride, i, j, block);
232 Scalar* EIGEN_RESTRICT m_data;
233 const Index m_stride;
239template<
typename Scalar,
typename Index,
int AlignmentType,
int Incr>
245 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void prefetch(
int i)
const {
246 internal::prefetch(&
operator()(i));
249 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar& operator()(
Index i)
const {
250 return m_data[i*m_incr.
value()];
253 template<
typename PacketType>
254 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(
Index i)
const {
258 template<
typename PacketType>
259 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void storePacket(
Index i,
const PacketType &p)
const {
268template<
typename Scalar,
typename Index,
int StorageOrder,
int AlignmentType,
int Incr>
286 EIGEN_ALWAYS_INLINE Scalar& operator()(
Index i,
Index j)
const {
287 return m_data[StorageOrder==
RowMajor ? j*m_incr.
value() + i*m_stride : i*m_incr.
value() + j*m_stride];
290 template<
typename PacketType>
291 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketType loadPacket(
Index i,
Index j)
const {
295 template <
typename PacketT,
int AlignmentT>
300 template<
typename SubPacket>
301 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void scatterPacket(
Index i,
Index j,
const SubPacket &p)
const {
305 template<
typename SubPacket>
311 template<
typename SubPacket,
typename ScalarT,
int n,
int idx>
316 spbh.store(
sup, i,j,block);
320 *v = block.packet[idx][l];
325 template<
typename SubPacket,
int n,
int idx>
330 spbh.store(
sup,i,j,block);
333 std::complex<float> *v = &
sup->operator()(i+l, j+idx);
334 v->real(block.packet[idx].v[2*l+0]);
335 v->imag(block.packet[idx].v[2*l+1]);
340 template<
typename SubPacket,
int n,
int idx>
345 spbh.store(
sup,i,j,block);
348 std::complex<double> *v = &
sup->operator()(i+l, j+idx);
349 v->real(block.packet[idx].v[2*l+0]);
350 v->imag(block.packet[idx].v[2*l+1]);
355 template<
typename SubPacket,
typename ScalarT,
int n>
362 template<
typename SubPacket,
int n>
369 template<
typename SubPacket,
int n>
376 template<
typename SubPacket,
int n>
379 spb.store(
this, i,j,block);
382 Scalar* EIGEN_RESTRICT m_data;
383 const Index m_stride;
388template<
typename Scalar,
typename Index,
int StorageOrder>
405 typedef const XprType& ExtractType;
406 typedef XprType _ExtractType;
409 IsTransposed =
false,
410 NeedToConjugate =
false,
412 && (
bool(XprType::IsVectorAtCompileTime)
415 HasScalarFactor =
false
417 typedef typename conditional<bool(HasUsableDirectAccess),
419 typename _ExtractType::PlainObject
421 static inline EIGEN_DEVICE_FUNC ExtractType extract(
const XprType& x) {
return x; }
422 static inline EIGEN_DEVICE_FUNC
const Scalar extractScalarFactor(
const XprType&) {
return Scalar(1); }
426template<
typename Scalar,
typename NestedXpr>
436 NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex
438 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.nestedExpression()); }
439 static inline Scalar extractScalarFactor(
const XprType& x) {
return conj(Base::extractScalarFactor(x.nestedExpression())); }
443template<
typename Scalar,
typename NestedXpr,
typename Plain>
448 HasScalarFactor =
true
453 static inline EIGEN_DEVICE_FUNC
ExtractType extract(
const XprType& x) {
return Base::extract(x.rhs()); }
454 static inline EIGEN_DEVICE_FUNC Scalar extractScalarFactor(
const XprType& x)
455 {
return x.lhs().functor().m_other * Base::extractScalarFactor(x.rhs()); }
457template<
typename Scalar,
typename NestedXpr,
typename Plain>
462 HasScalarFactor =
true
467 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.lhs()); }
468 static inline Scalar extractScalarFactor(
const XprType& x)
469 {
return Base::extractScalarFactor(x.lhs()) * x.rhs().functor().m_other; }
471template<
typename Scalar,
typename Plain1,
typename Plain2>
474 :
blas_traits<CwiseNullaryOp<scalar_constant_op<Scalar>,Plain1> >
478template<
typename Scalar,
typename NestedXpr>
483 HasScalarFactor =
true
488 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.nestedExpression()); }
489 static inline Scalar extractScalarFactor(
const XprType& x)
490 {
return - Base::extractScalarFactor(x.nestedExpression()); }
494template<
typename NestedXpr>
498 typedef typename NestedXpr::Scalar Scalar;
503 typedef typename conditional<bool(Base::HasUsableDirectAccess),
508 IsTransposed = Base::IsTransposed ? 0 : 1
511 static inline Scalar extractScalarFactor(
const XprType& x) {
return Base::extractScalarFactor(x.nestedExpression()); }
521 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
static const typename T::Scalar* run(
const T& m)
529 static typename T::Scalar* run(
const T&) {
return 0; }
533EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const typename T::Scalar* extract_data(
const T& m)
542template<
typename ResScalar,
typename Lhs,
typename Rhs>
545 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
static ResScalar run(
const Lhs& lhs,
const Rhs& rhs)
549 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
static ResScalar run(
const ResScalar& alpha,
const Lhs& lhs,
const Rhs& rhs)
554template<
typename Lhs,
typename Rhs>
557 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
static bool run(
const Lhs& lhs,
const Rhs& rhs)
561 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
static bool run(
const bool& alpha,
const Lhs& lhs,
const Rhs& rhs)
567template<
typename ResScalar,
typename Lhs,
typename Rhs>
568EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(
const ResScalar& alpha,
const Lhs& lhs,
const Rhs& rhs)
572template<
typename ResScalar,
typename Lhs,
typename Rhs>
573EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(
const Lhs& lhs,
const Rhs& rhs)
575 return combine_scalar_factors_impl<ResScalar,Lhs,Rhs>::run(lhs, rhs);
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:84
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:61
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:56
EIGEN_DEVICE_FUNC CoeffReturnType value() const
Definition DenseBase.h:526
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Expression of the transpose of a matrix.
Definition Transpose.h:54
Definition BlasUtil.h:241
Definition BlasUtil.h:270
Definition BlasUtil.h:389
Definition XprHelper.h:130
AlignmentType
Enum for indicating whether a buffer is aligned or not.
Definition Constants.h:232
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:321
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition Constants.h:155
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Holds information about the various numeric (i.e.
Definition NumTraits.h:236
Definition BlasUtil.h:120
Definition BlasUtil.h:313
Definition BlasUtil.h:403
combine_scalar_factors extracts and multiplies factors from GEMM and GEMV products.
Definition BlasUtil.h:544
Definition DenseCoeffsBase.h:659
Definition UnaryFunctors.h:109
Definition NullaryFunctors.h:18
Definition UnaryFunctors.h:22
Definition BinaryFunctors.h:71
Definition ForwardDeclarations.h:17
Definition PacketMath.h:47