11 #ifndef EIGEN_CXX11_TENSOR_TENSOR_ARG_MAX_H 12 #define EIGEN_CXX11_TENSOR_TENSOR_ARG_MAX_H 24 template<
typename XprType>
31 typedef typename XprType::Nested
Nested;
33 static const int NumDimensions = XprTraits::NumDimensions;
34 static const int Layout = XprTraits::Layout;
37 template<
typename XprType>
43 template<
typename XprType>
52 template<
typename XprType>
75 template<
typename ArgType,
typename Device>
103 : m_impl(op.expression(), device) { }
106 return m_impl.dimensions();
110 m_impl.evalSubExprsIfNeeded(
NULL);
119 return CoeffReturnType(index, m_impl.coeff(index));
124 return m_impl.costPerCoeff(vectorized) +
TensorOpCost(0, 0, 1);
129 #ifdef EIGEN_USE_SYCL 147 template<
typename ReduceOp,
typename Dims,
typename XprType>
157 static const int Layout = XprTraits::Layout;
160 template<
typename ReduceOp,
typename Dims,
typename XprType>
166 template<
typename ReduceOp,
typename Dims,
typename XprType>
175 template<
typename ReduceOp,
typename Dims,
typename XprType>
187 const ReduceOp& reduce_op,
188 const Index return_dim,
189 const Dims& reduce_dims)
190 : m_xpr(expr), m_reduce_op(reduce_op), m_return_dim(return_dim), m_reduce_dims(reduce_dims) {}
197 const ReduceOp&
reduce_op()
const {
return m_reduce_op; }
213 template<
typename ReduceOp,
typename Dims,
typename ArgType,
typename Device>
231 PacketAccess =
false,
234 Layout = TensorEvaluator<const TensorReductionOp<ReduceOp, Dims, const TensorIndexTupleOp<ArgType> >, Device>::Layout,
244 : m_orig_impl(op.expression(), device),
245 m_impl(op.expression().index_tuples().reduce(op.reduce_dims(), op.reduce_op()), device),
246 m_return_dim(op.return_dim())
248 gen_strides(m_orig_impl.dimensions(), m_strides);
249 if (Layout == static_cast<int>(
ColMajor)) {
251 m_stride_mod = (m_return_dim < NumDims - 1) ? m_strides[m_return_dim + 1] : total_size;
254 m_stride_mod = (m_return_dim > 0) ? m_strides[m_return_dim - 1] : total_size;
257 m_stride_div = ((m_return_dim >= 0) &&
258 (m_return_dim < static_cast<Index>(m_strides.size())))
259 ? m_strides[m_return_dim] : 1;
263 return m_impl.dimensions();
267 m_impl.evalSubExprsIfNeeded(
NULL);
275 const TupleType
v = m_impl.coeff(index);
276 return (m_return_dim < 0) ? v.first : (v.first % m_stride_mod) / m_stride_div;
280 #ifdef EIGEN_USE_SYCL 283 m_orig_impl.bind(cgh);
289 const double compute_cost = 1.0 +
290 (m_return_dim < 0 ? 0.0 : (TensorOpCost::ModCost<Index>() + TensorOpCost::DivCost<Index>()));
291 return m_orig_impl.costPerCoeff(vectorized) +
292 m_impl.costPerCoeff(vectorized) +
TensorOpCost(0, 0, compute_cost);
297 if (m_return_dim < 0) {
301 "Asking to convert index to a dimension outside of the rank");
305 if (Layout == static_cast<int>(
ColMajor)) {
307 for (
int i = 1;
i < NumDims; ++
i) {
308 strides[
i] = strides[
i-1] * dims[
i-1];
311 strides[NumDims-1] = 1;
312 for (
int i = NumDims - 2;
i >= 0; --
i) {
313 strides[
i] = strides[
i+1] * dims[
i+1];
319 TensorEvaluator<const TensorIndexTupleOp<ArgType>, Device>
m_orig_impl;
320 TensorEvaluator<const TensorReductionOp<ReduceOp, Dims, const TensorIndexTupleOp<ArgType> >, Device>
m_impl;
329 #endif // EIGEN_CXX11_TENSOR_TENSOR_ARG_MAX_H TensorEvaluator< ArgType, Device > m_impl
Eigen::NumTraits< Scalar >::Real RealScalar
std::vector< Eigen::Index > Dims
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
#define EIGEN_STRONG_INLINE
StorageMemory< CoeffReturnType, Device > Storage
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
const TensorTupleReducerOp< ReduceOp, Dims, XprType > EIGEN_DEVICE_REF type
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
TensorEvaluator< const TensorIndexTupleOp< ArgType >, Device > m_orig_impl
const ReduceOp m_reduce_op
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
Namespace containing all symbols from the Eigen library.
TensorTupleReducerOp< ReduceOp, Dims, ArgType > XprType
TensorIndexTupleOp< ArgType > XprType
TensorEvaluator< const TensorReductionOp< ReduceOp, Dims, const TensorIndexTupleOp< ArgType > >, Device >::Dimensions Dimensions
A cost model used to limit the number of threads used for evaluating tensor expression.
remove_reference< Nested >::type _Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
array< Index, NumDims > StrideDims
StorageMemory< TupleType, Device > TupleStorageMem
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
traits< XprType > XprTraits
Eigen::internal::traits< TensorTupleReducerOp >::StorageKind StorageKind
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
Eigen::internal::traits< TensorTupleReducerOp >::Index Index
Generic expression where a coefficient-wise binary operator is applied to two expressions.
EIGEN_DEVICE_FUNC const ReduceOp & reduce_op() const
TensorEvaluator< const TensorIndexTupleOp< ArgType >, Device >::Dimensions InputDimensions
TensorTupleReducerOp< ReduceOp, Dims, XprType > type
TensorEvaluator< const TensorReductionOp< ReduceOp, Dims, const TensorIndexTupleOp< ArgType > >, Device > m_impl
Eigen::internal::nested< TensorTupleReducerOp >::type Nested
XprTraits::StorageKind StorageKind
Tuple< Index, typename XprType::CoeffReturnType > CoeffReturnType
Eigen::NumTraits< Scalar >::Real RealScalar
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorIndexTupleOp(const XprType &expr)
Array< int, Dynamic, 1 > v
Tuple< Index, typename XprTraits::Scalar > Scalar
internal::TensorBlockNotImplemented TensorBlock
const TensorIndexTupleOp< XprType > EIGEN_DEVICE_REF type
TensorIndexTupleOp< ArgType >::CoeffReturnType TupleType
remove_reference< Nested >::type _Nested
EIGEN_DEVICE_FUNC Index return_dim() const
TensorIndexTupleOp< XprType > type
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
#define EIGEN_DEVICE_FUNC
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorTupleReducerOp(const XprType &expr, const ReduceOp &reduce_op, const Index return_dim, const Dims &reduce_dims)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
traits< XprType > XprTraits
Eigen::internal::traits< TensorIndexTupleOp >::StorageKind StorageKind
internal::TensorBlockNotImplemented TensorBlock
Eigen::internal::traits< TensorTupleReducerOp >::Scalar Scalar
XprTraits::StorageKind StorageKind
Eigen::internal::nested< TensorIndexTupleOp >::type Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Eigen::internal::traits< TensorIndexTupleOp >::Scalar Scalar
EIGEN_DEVICE_FUNC void gen_strides(const InputDimensions &dims, StrideDims &strides)
Storage::Type EvaluatorPointerType
EIGEN_DEVICE_FUNC const Dims & reduce_dims() const
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Generic expression where a coefficient-wise unary operator is applied to an expression.
Storage::Type EvaluatorPointerType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Eigen::internal::traits< TensorIndexTupleOp >::Index Index
EIGEN_STRONG_INLINE void cleanup()
XprType::CoeffReturnType CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
EIGEN_STRONG_INLINE void cleanup()
StorageMemory< CoeffReturnType, Device > Storage