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 template<
typename Index>
22 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (
Index,
Index = 0)
const {
return m_other; }
23 template<
typename Index,
typename PacketType>
24 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const PacketType packetOp(
Index,
Index = 0)
const {
return internal::pset1<PacketType>(m_other); }
27 template<
typename Scalar>
28 struct functor_traits<scalar_constant_op<Scalar> >
30 PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable =
true }; };
32 template<
typename Scalar>
struct scalar_identity_op {
33 EIGEN_EMPTY_STRUCT_CTOR(scalar_identity_op)
34 template<typename
Index>
35 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (
Index row,
Index col)
const {
return row==col ? Scalar(1) : Scalar(0); }
37 template<
typename Scalar>
38 struct functor_traits<scalar_identity_op<Scalar> >
39 {
enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess =
false, IsRepeatable =
true }; };
41 template <
typename Scalar,
typename Packet,
bool RandomAccess,
bool IsInteger>
struct linspaced_op_impl;
51 template <
typename Scalar,
typename Packet>
52 struct linspaced_op_impl<Scalar,Packet,false,false>
54 linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
55 m_low(low), m_step(num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1)),
56 m_packetStep(pset1<Packet>(unpacket_traits<Packet>::size*m_step)),
57 m_base(padd(pset1<Packet>(low), pmul(pset1<Packet>(m_step),plset<Packet>(-unpacket_traits<Packet>::size)))) {}
59 template<
typename Index>
60 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (
Index i)
const 62 m_base = padd(m_base, pset1<Packet>(m_step));
63 return m_low+Scalar(i)*m_step;
66 template<
typename Index>
67 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(
Index)
const {
return m_base = padd(m_base,m_packetStep); }
71 const Packet m_packetStep;
72 mutable Packet m_base;
78 template <
typename Scalar,
typename Packet>
79 struct linspaced_op_impl<Scalar,Packet,true,false>
81 linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
82 m_low(low), m_step(num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1)),
83 m_lowPacket(pset1<Packet>(m_low)), m_stepPacket(pset1<Packet>(m_step)), m_interPacket(plset<Packet>(0)) {}
85 template<
typename Index>
86 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (
Index i)
const {
return m_low+i*m_step; }
88 template<
typename Index>
89 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(
Index i)
const 90 {
return internal::padd(m_lowPacket, pmul(m_stepPacket, padd(pset1<Packet>(Scalar(i)),m_interPacket))); }
94 const Packet m_lowPacket;
95 const Packet m_stepPacket;
96 const Packet m_interPacket;
99 template <
typename Scalar,
typename Packet>
100 struct linspaced_op_impl<Scalar,Packet,true,true>
102 linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
103 m_low(low), m_length(high-low), m_divisor(convert_index<Scalar>(num_steps==1?1:num_steps-1)), m_interPacket(plset<Packet>(0))
106 template<
typename Index>
107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
108 const Scalar operator() (
Index i)
const {
109 return m_low + (m_length*Scalar(i))/m_divisor;
112 template<
typename Index>
113 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
114 const Packet packetOp(
Index i)
const {
115 return internal::padd(pset1<Packet>(m_low), pdiv(pmul(pset1<Packet>(m_length), padd(pset1<Packet>(Scalar(i)),m_interPacket)),
116 pset1<Packet>(m_divisor))); }
119 const Scalar m_length;
120 const Scalar m_divisor;
121 const Packet m_interPacket;
129 template <
typename Scalar,
typename PacketType,
bool RandomAccess = true>
struct linspaced_op;
130 template <
typename Scalar,
typename PacketType,
bool RandomAccess>
struct functor_traits< linspaced_op<Scalar,PacketType,RandomAccess> >
135 PacketAccess = packet_traits<Scalar>::HasSetLinear
136 && ((!NumTraits<Scalar>::IsInteger) || packet_traits<Scalar>::HasDiv),
140 template <
typename Scalar,
typename PacketType,
bool RandomAccess>
struct linspaced_op
142 linspaced_op(
const Scalar& low,
const Scalar& high,
Index num_steps)
143 : impl((num_steps==1 ? high : low),high,num_steps)
146 template<
typename Index>
147 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (
Index i)
const {
return impl(i); }
151 template<
typename Index>
152 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (
Index row,
Index col)
const 154 eigen_assert(col==0 || row==0);
155 return impl(col + row);
158 template<
typename Index,
typename Packet>
159 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(
Index i)
const {
return impl.packetOp(i); }
163 template<
typename Index,
typename Packet>
164 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(
Index row,
Index col)
const 166 eigen_assert(col==0 || row==0);
167 return impl.packetOp(col + row);
175 const linspaced_op_impl<Scalar,PacketType,(NumTraits<Scalar>::IsInteger?
true:RandomAccess),NumTraits<Scalar>::IsInteger> impl;
181 template<
typename Functor>
struct functor_has_linear_access {
enum { ret = 1 }; };
182 template<
typename Scalar>
struct functor_has_linear_access<scalar_identity_op<Scalar> > {
enum { ret = 0 }; };
188 #endif // EIGEN_NULLARY_FUNCTORS_H Namespace containing all symbols from the Eigen library.
Definition: Core:271
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
Definition: Eigen_Colamd.h:50