10 #ifndef EIGEN_BLASUTIL_H
11 #define EIGEN_BLASUTIL_H
21 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjugateLhs=false,
bool ConjugateRhs=false>
24 template<
typename Scalar,
typename Index,
int nr,
int StorageOrder,
bool Conjugate = false,
bool PanelMode=false>
27 template<
typename Scalar,
typename Index,
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,
35 struct general_matrix_matrix_product;
37 template<
typename Index,
typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
typename RhsScalar,
bool ConjugateRhs,
int Version=Specialized>
38 struct general_matrix_vector_product;
41 template<
bool Conjugate>
struct conj_if;
43 template<>
struct conj_if<true> {
45 inline T operator()(
const T& x) {
return numext::conj(x); }
47 inline T pconj(
const T& x) {
return internal::pconj(x); }
50 template<>
struct conj_if<false> {
52 inline const T& operator()(
const T& x) {
return x; }
54 inline const T& pconj(
const T& x) {
return x; }
57 template<
typename Scalar>
struct conj_helper<Scalar,Scalar,false,false>
59 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const {
return internal::pmadd(x,y,c); }
60 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const {
return internal::pmul(x,y); }
63 template<
typename RealScalar>
struct conj_helper<std::complex<RealScalar>, std::complex<RealScalar>, false,true>
65 typedef std::complex<RealScalar> Scalar;
66 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const
67 {
return c + pmul(x,y); }
69 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const
70 {
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)); }
73 template<
typename RealScalar>
struct conj_helper<std::complex<RealScalar>, std::complex<RealScalar>, true,false>
75 typedef std::complex<RealScalar> Scalar;
76 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const
77 {
return c + pmul(x,y); }
79 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const
80 {
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)); }
83 template<
typename RealScalar>
struct conj_helper<std::complex<RealScalar>, std::complex<RealScalar>, true,true>
85 typedef std::complex<RealScalar> Scalar;
86 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const Scalar& y,
const Scalar& c)
const
87 {
return c + pmul(x,y); }
89 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const Scalar& y)
const
90 {
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)); }
93 template<
typename RealScalar,
bool Conj>
struct conj_helper<std::complex<RealScalar>, RealScalar, Conj,false>
95 typedef std::complex<RealScalar> Scalar;
96 EIGEN_STRONG_INLINE Scalar pmadd(
const Scalar& x,
const RealScalar& y,
const Scalar& c)
const
97 {
return padd(c, pmul(x,y)); }
98 EIGEN_STRONG_INLINE Scalar pmul(
const Scalar& x,
const RealScalar& y)
const
99 {
return conj_if<Conj>()(x)*y; }
102 template<
typename RealScalar,
bool Conj>
struct conj_helper<RealScalar, std::complex<RealScalar>, false,Conj>
104 typedef std::complex<RealScalar> Scalar;
105 EIGEN_STRONG_INLINE Scalar pmadd(
const RealScalar& x,
const Scalar& y,
const Scalar& c)
const
106 {
return padd(c, pmul(x,y)); }
107 EIGEN_STRONG_INLINE Scalar pmul(
const RealScalar& x,
const Scalar& y)
const
108 {
return x*conj_if<Conj>()(y); }
111 template<
typename From,
typename To>
struct get_factor {
112 static EIGEN_STRONG_INLINE To run(
const From& x) {
return x; }
115 template<
typename Scalar>
struct get_factor<Scalar,typename NumTraits<Scalar>::Real> {
116 static EIGEN_STRONG_INLINE
typename NumTraits<Scalar>::Real run(
const Scalar& x) {
return numext::real(x); }
122 template<
typename Scalar,
typename Index,
int StorageOrder>
123 class blas_data_mapper
126 blas_data_mapper(Scalar* data, Index stride) : m_data(data), m_stride(stride) {}
127 EIGEN_STRONG_INLINE Scalar& operator()(Index i, Index j)
128 {
return m_data[StorageOrder==
RowMajor ? j + i*m_stride : i + j*m_stride]; }
130 Scalar* EIGEN_RESTRICT m_data;
135 template<
typename Scalar,
typename Index,
int StorageOrder>
136 class const_blas_data_mapper
139 const_blas_data_mapper(
const Scalar* data, Index stride) : m_data(data), m_stride(stride) {}
140 EIGEN_STRONG_INLINE
const Scalar& operator()(Index i, Index j)
const
141 {
return m_data[StorageOrder==
RowMajor ? j + i*m_stride : i + j*m_stride]; }
143 const Scalar* EIGEN_RESTRICT m_data;
151 template<
typename XprType>
struct blas_traits
153 typedef typename traits<XprType>::Scalar Scalar;
154 typedef const XprType& ExtractType;
155 typedef XprType _ExtractType;
157 IsComplex = NumTraits<Scalar>::IsComplex,
158 IsTransposed =
false,
159 NeedToConjugate =
false,
161 && (
bool(XprType::IsVectorAtCompileTime)
162 || int(inner_stride_at_compile_time<XprType>::ret) == 1)
165 typedef typename conditional<bool(HasUsableDirectAccess),
167 typename _ExtractType::PlainObject
168 >::type DirectLinearAccessType;
169 static inline ExtractType extract(
const XprType& x) {
return x; }
170 static inline const Scalar extractScalarFactor(
const XprType&) {
return Scalar(1); }
174 template<
typename Scalar,
typename Xpr>
175 struct blas_traits<CwiseUnaryOp<scalar_conjugate_op<Scalar>, Xpr> >
176 : blas_traits<typename internal::remove_all<typename Xpr::Nested>::type>
178 typedef typename internal::remove_all<typename Xpr::Nested>::type NestedXpr;
179 typedef blas_traits<NestedXpr> Base;
180 typedef CwiseUnaryOp<scalar_conjugate_op<Scalar>, Xpr> XprType;
181 typedef typename Base::ExtractType ExtractType;
184 IsComplex = NumTraits<Scalar>::IsComplex,
185 NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex
187 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.nestedExpression()); }
188 static inline Scalar extractScalarFactor(
const XprType& x) {
return conj(Base::extractScalarFactor(x.nestedExpression())); }
192 template<
typename Scalar,
typename Xpr>
193 struct blas_traits<CwiseUnaryOp<scalar_multiple_op<Scalar>, Xpr> >
194 : blas_traits<typename internal::remove_all<typename Xpr::Nested>::type>
196 typedef typename internal::remove_all<typename Xpr::Nested>::type NestedXpr;
197 typedef blas_traits<NestedXpr> Base;
198 typedef CwiseUnaryOp<scalar_multiple_op<Scalar>, Xpr> XprType;
199 typedef typename Base::ExtractType ExtractType;
200 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.nestedExpression()); }
201 static inline Scalar extractScalarFactor(
const XprType& x)
202 {
return x.functor().m_other * Base::extractScalarFactor(x.nestedExpression()); }
206 template<
typename Scalar,
typename Xpr>
207 struct blas_traits<CwiseUnaryOp<scalar_opposite_op<Scalar>, Xpr> >
208 : blas_traits<typename internal::remove_all<typename Xpr::Nested>::type>
210 typedef typename internal::remove_all<typename Xpr::Nested>::type NestedXpr;
211 typedef blas_traits<NestedXpr> Base;
212 typedef CwiseUnaryOp<scalar_opposite_op<Scalar>, Xpr> XprType;
213 typedef typename Base::ExtractType ExtractType;
214 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.nestedExpression()); }
215 static inline Scalar extractScalarFactor(
const XprType& x)
216 {
return - Base::extractScalarFactor(x.nestedExpression()); }
220 template<
typename Xpr>
221 struct blas_traits<Transpose<Xpr> >
222 : blas_traits<typename internal::remove_all<typename Xpr::Nested>::type>
224 typedef typename internal::remove_all<typename Xpr::Nested>::type NestedXpr;
225 typedef typename NestedXpr::Scalar Scalar;
226 typedef blas_traits<NestedXpr> Base;
227 typedef Transpose<Xpr> XprType;
228 typedef Transpose<const typename Base::_ExtractType> ExtractType;
229 typedef Transpose<const typename Base::_ExtractType> _ExtractType;
230 typedef typename conditional<bool(Base::HasUsableDirectAccess),
232 typename ExtractType::PlainObject
233 >::type DirectLinearAccessType;
235 IsTransposed = Base::IsTransposed ? 0 : 1
237 static inline ExtractType extract(
const XprType& x) {
return Base::extract(x.nestedExpression()); }
238 static inline Scalar extractScalarFactor(
const XprType& x) {
return Base::extractScalarFactor(x.nestedExpression()); }
242 struct blas_traits<const T>
246 template<typename T, bool HasUsableDirectAccess=blas_traits<T>::HasUsableDirectAccess>
247 struct extract_data_selector {
248 static const typename T::Scalar* run(
const T& m)
250 return blas_traits<T>::extract(m).data();
255 struct extract_data_selector<T,false> {
256 static typename T::Scalar* run(
const T&) {
return 0; }
259 template<
typename T>
const typename T::Scalar* extract_data(
const T& m)
261 return extract_data_selector<T>::run(m);
268 #endif // EIGEN_BLASUTIL_H
Definition: Constants.h:266
const unsigned int DirectAccessBit
Definition: Constants.h:142