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_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 {
enum { Cost = 1, 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>
struct linspaced_op_impl;
51 template <
typename Scalar,
typename Packet>
52 struct linspaced_op_impl<Scalar,Packet,false>
54 linspaced_op_impl(
const Scalar& low,
const Scalar& step) :
55 m_low(low), m_step(step),
56 m_packetStep(pset1<Packet>(unpacket_traits<Packet>::size*step)),
57 m_base(padd(pset1<Packet>(low), pmul(pset1<Packet>(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_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>
81 linspaced_op_impl(
const Scalar& low,
const Scalar& step) :
82 m_low(low), m_step(step),
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_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;
104 template <
typename Scalar,
typename PacketType,
bool RandomAccess = true>
struct linspaced_op;
105 template <
typename Scalar,
typename PacketType,
bool RandomAccess>
struct functor_traits< linspaced_op<Scalar,PacketType,RandomAccess> >
106 {
enum { Cost = 1, PacketAccess = packet_traits<Scalar>::HasSetLinear, IsRepeatable =
true }; };
107 template <
typename Scalar,
typename PacketType,
bool RandomAccess>
struct linspaced_op
109 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))) {}
111 template<
typename Index>
112 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const {
return impl(i); }
116 template<
typename Index>
117 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (Index row, Index col)
const
119 eigen_assert(col==0 || row==0);
120 return impl(col + row);
123 template<
typename Index,
typename Packet>
124 EIGEN_STRONG_INLINE
const Packet packetOp(Index i)
const {
return impl.packetOp(i); }
128 template<
typename Index,
typename Packet>
129 EIGEN_STRONG_INLINE
const Packet packetOp(Index row, Index col)
const
131 eigen_assert(col==0 || row==0);
132 return impl.packetOp(col + row);
139 const linspaced_op_impl<Scalar,PacketType,RandomAccess> impl;
146 template<
typename Functor>
struct functor_has_linear_access {
enum { ret = 1 }; };
147 template<
typename Scalar>
struct functor_has_linear_access<scalar_identity_op<Scalar> > {
enum { ret = 0 }; };
153 #endif // EIGEN_NULLARY_FUNCTORS_H
Definition: Eigen_Colamd.h:54