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> >
29 {
enum { Cost = 1, 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 Index>
34 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index 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 RandomAccess>
struct linspaced_op_impl;
50 template <
typename Scalar,
typename Packet>
51 struct linspaced_op_impl<Scalar,Packet,false>
53 linspaced_op_impl(
const Scalar& low,
const Scalar& step) :
54 m_low(low), m_step(step),
55 m_packetStep(pset1<Packet>(unpacket_traits<Packet>::size*step)),
56 m_base(padd(pset1<Packet>(low), pmul(pset1<Packet>(step),plset<Packet>(-unpacket_traits<Packet>::size)))) {}
58 template<
typename Index>
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const
61 m_base = padd(m_base, pset1<Packet>(m_step));
62 return m_low+Scalar(i)*m_step;
65 template<
typename Index>
66 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Index)
const {
return m_base = padd(m_base,m_packetStep); }
70 const Packet m_packetStep;
71 mutable Packet m_base;
77 template <
typename Scalar,
typename Packet>
78 struct linspaced_op_impl<Scalar,Packet,true>
80 linspaced_op_impl(
const Scalar& low,
const Scalar& step) :
81 m_low(low), m_step(step),
82 m_lowPacket(pset1<Packet>(m_low)), m_stepPacket(pset1<Packet>(m_step)), m_interPacket(plset<Packet>(0)) {}
84 template<
typename Index>
85 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const {
return m_low+i*m_step; }
87 template<
typename Index>
88 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Index i)
const
89 {
return internal::padd(m_lowPacket, pmul(m_stepPacket, padd(pset1<Packet>(Scalar(i)),m_interPacket))); }
93 const Packet m_lowPacket;
94 const Packet m_stepPacket;
95 const Packet m_interPacket;
103 template <
typename Scalar,
typename PacketType,
bool RandomAccess = true>
struct linspaced_op;
104 template <
typename Scalar,
typename PacketType,
bool RandomAccess>
struct functor_traits< linspaced_op<Scalar,PacketType,RandomAccess> >
105 {
enum { Cost = 1, PacketAccess = packet_traits<Scalar>::HasSetLinear, IsRepeatable =
true }; };
106 template <
typename Scalar,
typename PacketType,
bool RandomAccess>
struct linspaced_op
108 linspaced_op(
const Scalar& low,
const Scalar& high, Index num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1))) {}
110 template<
typename Index>
111 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const {
return impl(i); }
115 template<
typename Index>
116 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (Index row, Index col)
const
118 eigen_assert(col==0 || row==0);
119 return impl(col + row);
122 template<
typename Index,
typename Packet>
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Index i)
const {
return impl.packetOp(i); }
127 template<
typename Index,
typename Packet>
128 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(Index row, Index col)
const
130 eigen_assert(col==0 || row==0);
131 return impl.packetOp(col + row);
137 const linspaced_op_impl<Scalar,PacketType,RandomAccess> impl;
143 template<
typename Functor>
struct functor_has_linear_access {
enum { ret = 1 }; };
144 template<
typename Scalar>
struct functor_has_linear_access<scalar_identity_op<Scalar> > {
enum { ret = 0 }; };
150 #endif // EIGEN_NULLARY_FUNCTORS_H
Definition: Eigen_Colamd.h:54