11 #ifndef EIGEN_CXX11_TENSOR_TENSOR_REVERSE_H 12 #define EIGEN_CXX11_TENSOR_TENSOR_REVERSE_H 22 template<
typename ReverseDimensions,
typename XprType>
24 XprType> > :
public traits<XprType>
30 typedef typename XprType::Nested
Nested;
32 static const int NumDimensions = XprTraits::NumDimensions;
33 static const int Layout = XprTraits::Layout;
36 template<
typename ReverseDimensions,
typename XprType>
42 template<
typename ReverseDimensions,
typename XprType>
51 template<
typename ReverseDimensions,
typename XprType>
53 XprType>, WriteAccessors>
65 const XprType& expr,
const ReverseDimensions& reverse_dims)
66 : m_xpr(expr), m_reverse_dims(reverse_dims) { }
69 const ReverseDimensions&
reverse()
const {
return m_reverse_dims; }
79 Assign assign(*
this, other);
84 template<
typename OtherDerived>
89 Assign assign(*
this, other);
100 template<
typename ReverseDimensions,
typename ArgType,
typename Device>
121 const Device& device)
122 : m_impl(op.expression(), device), m_reverse(op.
reverse())
128 m_dimensions = m_impl.dimensions();
129 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
131 for (
int i = 1;
i < NumDims; ++
i) {
132 m_strides[
i] = m_strides[
i-1] * m_dimensions[
i-1];
135 m_strides[NumDims-1] = 1;
136 for (
int i = NumDims - 2;
i >= 0; --
i) {
137 m_strides[
i] = m_strides[
i+1] * m_dimensions[
i+1];
143 const Dimensions&
dimensions()
const {
return m_dimensions; }
146 m_impl.evalSubExprsIfNeeded(
NULL);
156 Index inputIndex = 0;
157 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
158 for (
int i = NumDims - 1;
i > 0; --
i) {
159 Index idx = index / m_strides[
i];
160 index -= idx * m_strides[
i];
162 idx = m_dimensions[
i] - idx - 1;
164 inputIndex += idx * m_strides[
i] ;
167 inputIndex += (m_dimensions[0] - index - 1);
172 for (
int i = 0;
i < NumDims - 1; ++
i) {
173 Index idx = index / m_strides[
i];
174 index -= idx * m_strides[
i];
176 idx = m_dimensions[
i] - idx - 1;
178 inputIndex += idx * m_strides[
i] ;
180 if (m_reverse[NumDims-1]) {
181 inputIndex += (m_dimensions[NumDims-1] - index - 1);
191 return m_impl.coeff(reverseIndex(index));
194 template<
int LoadMode>
196 PacketReturnType
packet(Index index)
const 205 for (
int i = 0;
i < PacketSize; ++
i) {
206 values[
i] = coeff(index+
i);
208 PacketReturnType rslt = internal::pload<PacketReturnType>(
values);
213 double compute_cost = NumDims * (2 * TensorOpCost::AddCost<Index>() +
214 2 * TensorOpCost::MulCost<Index>() +
215 TensorOpCost::DivCost<Index>());
216 for (
int i = 0;
i < NumDims; ++
i) {
218 compute_cost += 2 * TensorOpCost::AddCost<Index>();
221 return m_impl.costPerCoeff(vectorized) +
225 EIGEN_DEVICE_FUNC Scalar*
data()
const {
return NULL; }
236 template <
typename ReverseDimensions,
typename ArgType,
typename Device>
238 :
public TensorEvaluator<const TensorReverseOp<ReverseDimensions, ArgType>,
255 const Device& device)
256 : Base(op, device) {}
264 const Dimensions&
dimensions()
const {
return this->m_dimensions; }
267 return this->m_impl.coeffRef(this->reverseIndex(index));
277 internal::pstore<CoeffReturnType, PacketReturnType>(
values,
x);
278 for (
int i = 0;
i < PacketSize; ++
i) {
279 this->coeffRef(index+
i) = values[
i];
288 #endif // EIGEN_CXX11_TENSOR_TENSOR_REVERSE_H EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
#define EIGEN_STRONG_INLINE
XprType::CoeffReturnType CoeffReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index reverseIndex(Index index) const
EIGEN_DEVICE_FUNC const ReverseDimensions & reverse() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
TensorReverseOp< ReverseDimensions, ArgType > XprType
Namespace containing all symbols from the Eigen library.
const ReverseDimensions m_reverse_dims
A cost model used to limit the number of threads used for evaluating tensor expression.
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
traits< XprType > XprTraits
vector< size_t > dimensions(L.begin(), L.end())
const TensorReverseOp< ReverseDimensions, XprType > & type
Eigen::internal::traits< TensorReverseOp >::StorageKind StorageKind
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar *)
PacketType< CoeffReturnType, Device >::type PacketReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
TensorReverseOp< ReverseDimensions, ArgType > XprType
array< Index, NumDims > m_strides
Eigen::NumTraits< Scalar >::Real RealScalar
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
DSizes< Index, NumDims > Dimensions
DSizes< Index, NumDims > Dimensions
Eigen::internal::traits< TensorReverseOp >::Index Index
TensorEvaluator< const TensorReverseOp< ReverseDimensions, ArgType >, Device > Base
static EIGEN_DEVICE_FUNC void run(const Expression &expr, const Device &device=Device())
EIGEN_DEVICE_FUNC Scalar * data() const
XprType::CoeffReturnType CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorReverseOp(const XprType &expr, const ReverseDimensions &reverse_dims)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x)
Eigen::internal::traits< TensorReverseOp >::Scalar Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
void reverse(const MatrixType &m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
TensorEvaluator< ArgType, Device > m_impl
ReverseDimensions m_reverse
Eigen::internal::nested< TensorReverseOp >::type Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
remove_reference< Nested >::type _Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
XprTraits::StorageKind StorageKind
TensorReverseOp< ReverseDimensions, XprType > type