10 #ifndef EIGEN_NULLARY_FUNCTORS_H
11 #define EIGEN_NULLARY_FUNCTORS_H
13 #include "../InternalHeaderCheck.h"
19 template<
typename Scalar>
20 struct scalar_constant_op {
21 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(
const scalar_constant_op& other) : m_other(other.m_other) { }
22 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_constant_op(
const Scalar& other) : m_other(other) { }
24 template<
typename PacketType>
25 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const PacketType packetOp()
const {
return internal::pset1<PacketType>(m_other); }
28 template<
typename Scalar>
29 struct functor_traits<scalar_constant_op<Scalar> >
31 PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable =
true }; };
33 template<
typename Scalar>
struct scalar_identity_op {
34 template<
typename IndexType>
37 template<
typename Scalar>
38 struct functor_traits<scalar_identity_op<Scalar> >
41 template <
typename Scalar,
bool IsInteger>
struct linspaced_op_impl;
43 template <
typename Scalar>
44 struct linspaced_op_impl<Scalar,false>
49 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))),
50 m_flip(numext::
abs(high)<numext::
abs(low))
53 template<
typename IndexType>
56 return (
i==0)? m_low : Scalar(m_high - RealScalar(m_size1-
i)*m_step);
58 return (
i==m_size1)? m_high : Scalar(m_low + RealScalar(
i)*m_step);
61 template<
typename Packet,
typename IndexType>
68 Packet pi = plset<Packet>(Scalar(
i-m_size1));
69 Packet
res =
padd(pset1<Packet>(m_high),
pmul(pset1<Packet>(m_step), pi));
71 Packet mask =
pcmp_lt(pset1<Packet>(0), plset<Packet>(0));
72 return pselect<Packet>(mask,
res, pset1<Packet>(m_low));
76 Packet pi = plset<Packet>(Scalar(
i));
77 Packet
res =
padd(pset1<Packet>(m_low),
pmul(pset1<Packet>(m_step), pi));
80 return pselect<Packet>(mask,
res, pset1<Packet>(m_high));
91 template <
typename Scalar>
92 struct linspaced_op_impl<Scalar,true>
96 m_multiplier((high-low)/
convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)),
97 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))),
98 m_use_divisor(num_steps>1 && (numext::
abs(high-low)+1)<num_steps)
101 template<
typename IndexType>
105 if(m_use_divisor)
return m_low + convert_index<Scalar>(
i)/m_divisor;
106 else return m_low + convert_index<Scalar>(
i)*m_multiplier;
110 const Scalar m_multiplier;
111 const Scalar m_divisor;
112 const bool m_use_divisor;
120 template <
typename Scalar>
struct linspaced_op;
121 template <
typename Scalar>
struct functor_traits< linspaced_op<Scalar> >
131 template <
typename Scalar>
struct linspaced_op
134 : impl((num_steps==1 ? high : low),high,num_steps)
137 template<
typename IndexType>
140 template<
typename Packet,
typename IndexType>
141 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Packet packetOp(IndexType
i)
const {
return impl.template packetOp<Packet>(
i); }
145 const linspaced_op_impl<Scalar,NumTraits<Scalar>::IsInteger> impl;
148 template <
typename Scalar>
149 struct equalspaced_op {
152 EIGEN_DEVICE_FUNC equalspaced_op(
const Scalar& start,
const Scalar& step) : m_start(start), m_step(step) {}
153 template <
typename IndexType>
155 return m_start + m_step *
static_cast<Scalar
>(
i);
157 template <
typename Packet,
typename IndexType>
159 const Packet cst_start = pset1<Packet>(m_start);
160 const Packet cst_step = pset1<Packet>(m_step);
161 const Packet cst_lin0 = plset<Packet>(Scalar(0));
162 const Packet cst_offset =
pmadd(cst_lin0, cst_step, cst_start);
164 Packet i_packet = pset1<Packet>(
static_cast<Scalar
>(
i));
165 return pmadd(i_packet, cst_step, cst_offset);
167 const Scalar m_start;
171 template <
typename Scalar>
172 struct functor_traits<equalspaced_op<Scalar> > {
176 packet_traits<Scalar>::HasSetLinear && packet_traits<Scalar>::HasMul && packet_traits<Scalar>::HasAdd,
185 template<
typename Functor>
struct functor_has_linear_access {
enum { ret = !has_binary_operator<Functor>::value }; };
189 #if !( EIGEN_COMP_MSVC || EIGEN_COMP_GNUC || (EIGEN_COMP_ICC>=1600))
190 template<
typename Scalar,
typename IndexType>
191 struct has_nullary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 1}; };
192 template<
typename Scalar,
typename IndexType>
193 struct has_unary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 0}; };
194 template<
typename Scalar,
typename IndexType>
195 struct has_binary_operator<scalar_constant_op<Scalar>,IndexType> {
enum { value = 0}; };
197 template<
typename Scalar,
typename IndexType>
198 struct has_nullary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 0}; };
199 template<
typename Scalar,
typename IndexType>
200 struct has_unary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 0}; };
201 template<
typename Scalar,
typename IndexType>
202 struct has_binary_operator<scalar_identity_op<Scalar>,IndexType> {
enum { value = 1}; };
204 template<
typename Scalar,
typename IndexType>
205 struct has_nullary_operator<linspaced_op<Scalar>,IndexType> {
enum { value = 0}; };
206 template<
typename Scalar,
typename IndexType>
207 struct has_unary_operator<linspaced_op<Scalar>,IndexType> {
enum { value = 1}; };
208 template<
typename Scalar,
typename IndexType>
209 struct has_binary_operator<linspaced_op<Scalar>,IndexType> {
enum { value = 0}; };
211 template<
typename Scalar,
typename IndexType>
212 struct has_nullary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 1}; };
213 template<
typename Scalar,
typename IndexType>
214 struct has_unary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 0}; };
215 template<
typename Scalar,
typename IndexType>
216 struct has_binary_operator<scalar_random_op<Scalar>,IndexType> {
enum { value = 0}; };
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
#define EIGEN_PREDICT_TRUE(x)
#define EIGEN_DEVICE_FUNC
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Packet padd(const Packet &a, const Packet &b)
Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Packet pmul(const Packet &a, const Packet &b)
IndexDest convert_index(const IndexSrc &idx)
Packet4i pcmp_lt(const Packet4i &a, const Packet4i &b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)