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)
79 Assign assign(*
this, other);
84 template<
typename OtherDerived>
89 Assign assign(*
this, other);
100 template<
typename ReverseDimensions,
typename ArgType,
typename Device>
122 :
m_impl(op.expression(),
device), m_reverse(op.reverse())
128 m_dimensions =
m_impl.dimensions();
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];
146 m_impl.evalSubExprsIfNeeded(NULL);
156 Index inputIndex = 0;
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>
205 for (
int i = 0; i < PacketSize; ++i) {
206 values[i] =
coeff(index+i);
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) +
236 template <
typename ReverseDimensions,
typename ArgType,
typename Device>
238 :
public TensorEvaluator<const TensorReverseOp<ReverseDimensions, ArgType>,
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