10#ifndef EIGEN_NULLARY_FUNCTORS_H
11#define EIGEN_NULLARY_FUNCTORS_H
17template<
typename Scalar>
18struct 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); }
26template<
typename Scalar>
27struct functor_traits<scalar_constant_op<Scalar> >
29 PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable =
true }; };
31template<
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); }
36template<
typename Scalar>
37struct functor_traits<scalar_identity_op<Scalar> >
38{
enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess =
false, IsRepeatable =
true }; };
40template <
typename Scalar,
bool IsInteger>
struct linspaced_op_impl;
42template <
typename Scalar>
43struct linspaced_op_impl<Scalar,false>
45 typedef typename NumTraits<Scalar>::Real RealScalar;
47 EIGEN_DEVICE_FUNC linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
48 m_low(low), m_high(high), m_size1(num_steps==1 ? 1 : num_steps-1), m_step(num_steps==1 ? Scalar() : Scalar((high-low)/RealScalar(num_steps-1))),
49 m_flip(numext::abs(high)<numext::abs(low))
52 template<
typename IndexType>
53 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (IndexType i)
const {
55 return (i==0)? m_low : Scalar(m_high - RealScalar(m_size1-i)*m_step);
57 return (i==m_size1)? m_high : Scalar(m_low + RealScalar(i)*m_step);
60 template<
typename Packet,
typename IndexType>
61 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(IndexType i)
const
67 Packet pi = plset<Packet>(Scalar(i-m_size1));
68 Packet res = padd(pset1<Packet>(m_high), pmul(pset1<Packet>(m_step), pi));
69 if (EIGEN_PREDICT_TRUE(i != 0))
return res;
70 Packet mask = pcmp_lt(pset1<Packet>(0), plset<Packet>(0));
71 return pselect<Packet>(mask, res, pset1<Packet>(m_low));
75 Packet pi = plset<Packet>(Scalar(i));
76 Packet res = padd(pset1<Packet>(m_low), pmul(pset1<Packet>(m_step), pi));
77 if(EIGEN_PREDICT_TRUE(i != m_size1-unpacket_traits<Packet>::size+1))
return res;
78 Packet mask = pcmp_lt(plset<Packet>(0), pset1<Packet>(unpacket_traits<Packet>::size-1));
79 return pselect<Packet>(mask, res, pset1<Packet>(m_high));
90template <
typename Scalar>
91struct linspaced_op_impl<Scalar,true>
93 EIGEN_DEVICE_FUNC linspaced_op_impl(
const Scalar& low,
const Scalar& high,
Index num_steps) :
95 m_multiplier((high-low)/convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)),
96 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))),
97 m_use_divisor(num_steps>1 && (numext::abs(high-low)+1)<num_steps)
100 template<
typename IndexType>
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
102 const Scalar operator() (IndexType i)
const
104 if(m_use_divisor)
return m_low + convert_index<Scalar>(i)/m_divisor;
105 else return m_low + convert_index<Scalar>(i)*m_multiplier;
109 const Scalar m_multiplier;
110 const Scalar m_divisor;
111 const bool m_use_divisor;
119template <
typename Scalar>
struct linspaced_op;
120template <
typename Scalar>
struct functor_traits< linspaced_op<Scalar> >
125 PacketAccess = (!NumTraits<Scalar>::IsInteger) && packet_traits<Scalar>::HasSetLinear && packet_traits<Scalar>::HasBlend,
130template <
typename Scalar>
struct linspaced_op
132 EIGEN_DEVICE_FUNC linspaced_op(
const Scalar& low,
const Scalar& high,
Index num_steps)
133 : impl((num_steps==1 ? high : low),high,num_steps)
136 template<
typename IndexType>
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar operator() (IndexType i)
const {
return impl(i); }
139 template<
typename Packet,
typename IndexType>
140 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(IndexType i)
const {
return impl.template packetOp<Packet>(i); }
144 const linspaced_op_impl<Scalar,NumTraits<Scalar>::IsInteger> impl;
151template<
typename Functor>
struct functor_has_linear_access {
enum { ret = !has_binary_operator<Functor>::value }; };
155#if !( (EIGEN_COMP_MSVC>1600) || (EIGEN_GNUC_AT_LEAST(4,8)) || (EIGEN_COMP_ICC>=1600))
156template<
typename Scalar,
typename IndexType>
157struct has_nullary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 1}; };
158template<
typename Scalar,
typename IndexType>
159struct has_unary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 0}; };
160template<
typename Scalar,
typename IndexType>
161struct has_binary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 0}; };
163template<
typename Scalar,
typename IndexType>
164struct has_nullary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 0}; };
165template<
typename Scalar,
typename IndexType>
166struct has_unary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 0}; };
167template<
typename Scalar,
typename IndexType>
168struct has_binary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 1}; };
170template<
typename Scalar,
typename IndexType>
171struct has_nullary_operator<linspaced_op<Scalar>,IndexType> {
enum { value = 0}; };
172template<
typename Scalar,
typename IndexType>
173struct has_unary_operator<linspaced_op<Scalar>,IndexType> {
enum { value = 1}; };
174template<
typename Scalar,
typename IndexType>
175struct has_binary_operator<linspaced_op<Scalar>,IndexType> {
enum { value = 0}; };
177template<
typename Scalar,
typename IndexType>
178struct has_nullary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 1}; };
179template<
typename Scalar,
typename IndexType>
180struct has_unary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 0}; };
181template<
typename Scalar,
typename IndexType>
182struct has_binary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 0}; };
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74