10 #ifndef EIGEN_NULLARY_FUNCTORS_H 11 #define EIGEN_NULLARY_FUNCTORS_H 17 template<
typename Scalar>
18 struct scalar_constant_op {
19 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(
const scalar_constant_op& other) : m_other(other.m_other) { }
20 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(
const Scalar& other) : m_other(other) { }
21 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() ()
const {
return m_other; }
22 template<
typename PacketType>
23 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const PacketType packetOp()
const {
return internal::pset1<PacketType>(m_other); }
26 template<
typename Scalar>
27 struct functor_traits<scalar_constant_op<Scalar> >
29 PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable =
true }; };
31 template<
typename Scalar>
struct scalar_identity_op {
32 EIGEN_EMPTY_STRUCT_CTOR(scalar_identity_op)
33 template<
typename IndexType>
34 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (IndexType row, IndexType col)
const {
return row==col ? Scalar(1) : Scalar(0); }
36 template<
typename Scalar>
37 struct functor_traits<scalar_identity_op<Scalar> >
38 {
enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess =
false, IsRepeatable =
true }; };
40 template <
typename Scalar,
typename Packet,
bool IsInteger>
struct linspaced_op_impl;
42 template <
typename Scalar,
typename Packet>
43 struct linspaced_op_impl<Scalar,Packet,false>
45 linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
46 m_low(low), m_high(high), m_size1(num_steps==1 ? 1 : num_steps-1), m_step(num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1)),
47 m_flip(numext::
abs(high)<numext::
abs(low))
50 template<
typename IndexType>
51 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (IndexType i)
const {
52 typedef typename NumTraits<Scalar>::Real RealScalar;
54 return (i==0)? m_low : (m_high - RealScalar(m_size1-i)*m_step);
56 return (i==m_size1)? m_high : (m_low + RealScalar(i)*m_step);
59 template<
typename IndexType>
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(IndexType i)
const 66 Packet pi = plset<Packet>(Scalar(i-m_size1));
67 Packet res = padd(pset1<Packet>(m_high), pmul(pset1<Packet>(m_step), pi));
69 res = pinsertfirst(res, m_low);
74 Packet pi = plset<Packet>(Scalar(i));
75 Packet res = padd(pset1<Packet>(m_low), pmul(pset1<Packet>(m_step), pi));
76 if(i==m_size1-unpacket_traits<Packet>::size+1)
77 res = pinsertlast(res, m_high);
89 template <
typename Scalar,
typename Packet>
90 struct linspaced_op_impl<Scalar,Packet,true>
92 linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
94 m_multiplier((high-low)/convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)),
95 m_divisor(convert_index<Scalar>((high>=low?num_steps:-num_steps)+(high-low))/((numext::
abs(high-low)+1)==0?1:(numext::
abs(high-low)+1))),
96 m_use_divisor(num_steps>1 && (numext::
abs(high-low)+1)<num_steps)
99 template<
typename IndexType>
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
101 const Scalar operator() (IndexType i)
const 103 if(m_use_divisor)
return m_low + convert_index<Scalar>(i)/m_divisor;
104 else return m_low + convert_index<Scalar>(i)*m_multiplier;
108 const Scalar m_multiplier;
109 const Scalar m_divisor;
110 const bool m_use_divisor;
118 template <
typename Scalar,
typename PacketType>
struct linspaced_op;
119 template <
typename Scalar,
typename PacketType>
struct functor_traits< linspaced_op<Scalar,PacketType> >
124 PacketAccess = (!NumTraits<Scalar>::IsInteger) && packet_traits<Scalar>::HasSetLinear && packet_traits<Scalar>::HasBlend,
129 template <
typename Scalar,
typename PacketType>
struct linspaced_op
131 linspaced_op(
const Scalar& low,
const Scalar& high,
Index num_steps)
132 : impl((num_steps==1 ? high : low),high,num_steps)
135 template<
typename IndexType>
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (IndexType i)
const {
return impl(i); }
138 template<
typename Packet,
typename IndexType>
139 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(IndexType i)
const {
return impl.packetOp(i); }
143 const linspaced_op_impl<Scalar,PacketType,NumTraits<Scalar>::IsInteger> impl;
150 template<
typename Functor>
struct functor_has_linear_access {
enum { ret = !has_binary_operator<Functor>::value }; };
154 #if !( (EIGEN_COMP_MSVC>1600) || (EIGEN_GNUC_AT_LEAST(4,8)) || (EIGEN_COMP_ICC>=1600)) 155 template<
typename Scalar,
typename IndexType>
156 struct has_nullary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 1}; };
157 template<
typename Scalar,
typename IndexType>
158 struct has_unary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 0}; };
159 template<
typename Scalar,
typename IndexType>
160 struct has_binary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 0}; };
162 template<
typename Scalar,
typename IndexType>
163 struct has_nullary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 0}; };
164 template<
typename Scalar,
typename IndexType>
165 struct has_unary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 0}; };
166 template<
typename Scalar,
typename IndexType>
167 struct has_binary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 1}; };
169 template<
typename Scalar,
typename PacketType,
typename IndexType>
170 struct has_nullary_operator<linspaced_op<Scalar,PacketType>,IndexType> {
enum { value = 0}; };
171 template<
typename Scalar,
typename PacketType,
typename IndexType>
172 struct has_unary_operator<linspaced_op<Scalar,PacketType>,IndexType> {
enum { value = 1}; };
173 template<
typename Scalar,
typename PacketType,
typename IndexType>
174 struct has_binary_operator<linspaced_op<Scalar,PacketType>,IndexType> {
enum { value = 0}; };
176 template<
typename Scalar,
typename IndexType>
177 struct has_nullary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 1}; };
178 template<
typename Scalar,
typename IndexType>
179 struct has_unary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 0}; };
180 template<
typename Scalar,
typename IndexType>
181 struct has_binary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 0}; };
188 #endif // EIGEN_NULLARY_FUNCTORS_H Namespace containing all symbols from the Eigen library.
Definition: Core:287
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
Definition: Eigen_Colamd.h:50