10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H 24 template<DenseIndex DimId,
typename XprType>
27 typedef typename XprType::Scalar
Scalar;
31 typedef typename XprType::Nested
Nested;
33 static const int NumDimensions = XprTraits::NumDimensions - 1;
34 static const int Layout = XprTraits::Layout;
37 template<DenseIndex DimId,
typename XprType>
43 template<DenseIndex DimId,
typename XprType>
49 template <DenseIndex DimId>
77 template<DenseIndex DimId,
typename XprType>
89 : m_xpr(expr), m_offset(offset), m_dim(dim) {
93 const Index
offset()
const {
return m_offset; }
95 const Index
dim()
const {
return m_dim.actualDim(); }
105 Assign assign(*
this, other);
110 template<
typename OtherDerived>
115 Assign assign(*
this, other);
128 template<DenseIndex DimId,
typename ArgType,
typename Device>
133 static const int NumDims = NumInputDims-1;
153 : m_impl(op.expression(), device), m_dim(op.
dim()), m_device(device)
162 for (
int i = 0; i < NumInputDims; ++i) {
163 if (i != m_dim.actualDim()) {
164 m_dimensions[j] = input_dims[i];
171 if (static_cast<int>(Layout) ==
static_cast<int>(
ColMajor)) {
172 for (
int i = 0; i < m_dim.actualDim(); ++i) {
173 m_stride *= input_dims[i];
174 m_inputStride *= input_dims[i];
177 for (
int i = NumInputDims-1; i > m_dim.actualDim(); --i) {
178 m_stride *= input_dims[i];
179 m_inputStride *= input_dims[i];
182 m_inputStride *= input_dims[m_dim.actualDim()];
183 m_inputOffset = m_stride * op.
offset();
189 m_impl.evalSubExprsIfNeeded(NULL);
199 return m_impl.coeff(srcCoeff(index));
202 template<
int LoadMode>
206 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
208 if ((static_cast<int>(Layout) == static_cast<int>(
ColMajor) && m_dim.actualDim() == 0) ||
209 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) && m_dim.actualDim() == NumInputDims-1)) {
212 Index inputIndex = index * m_inputStride + m_inputOffset;
214 for (
int i = 0; i < PacketSize; ++i) {
215 values[i] = m_impl.coeff(inputIndex);
216 inputIndex += m_inputStride;
218 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
220 }
else if ((static_cast<int>(Layout) == static_cast<int>(
ColMajor) && m_dim.actualDim() == NumInputDims - 1) ||
221 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) && m_dim.actualDim() == 0)) {
224 return m_impl.template packet<LoadMode>(index + m_inputOffset);
226 const Index idx = index / m_stride;
227 const Index
rem = index - idx * m_stride;
228 if (rem + PacketSize <= m_stride) {
229 Index inputIndex = idx * m_inputStride + m_inputOffset +
rem;
230 return m_impl.template packet<LoadMode>(inputIndex);
234 for (
int i = 0; i < PacketSize; ++i) {
235 values[i] = coeff(index);
238 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
247 if ((static_cast<int>(Layout) == static_cast<int>(
ColMajor) &&
248 m_dim.actualDim() == 0) ||
249 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) &&
250 m_dim.actualDim() == NumInputDims - 1)) {
251 cost += TensorOpCost::MulCost<Index>() + TensorOpCost::AddCost<Index>();
252 }
else if ((static_cast<int>(Layout) == static_cast<int>(
ColMajor) &&
253 m_dim.actualDim() == NumInputDims - 1) ||
254 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) &&
255 m_dim.actualDim() == 0)) {
256 cost += TensorOpCost::AddCost<Index>();
258 cost += 3 * TensorOpCost::MulCost<Index>() + TensorOpCost::DivCost<Index>() +
259 3 * TensorOpCost::AddCost<Index>();
262 return m_impl.costPerCoeff(vectorized) +
267 CoeffReturnType* result =
const_cast<CoeffReturnType*
>(m_impl.data());
268 if (((static_cast<int>(Layout) == static_cast<int>(
ColMajor) && m_dim.actualDim() == NumDims) ||
269 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) && m_dim.actualDim() == 0)) &&
271 return result + m_inputOffset;
281 if ((static_cast<int>(Layout) == static_cast<int>(
ColMajor) && m_dim.actualDim() == 0) ||
282 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) && m_dim.actualDim() == NumInputDims-1)) {
285 inputIndex = index * m_inputStride + m_inputOffset;
286 }
else if ((static_cast<int>(Layout) == static_cast<int>(
ColMajor) && m_dim.actualDim() == NumInputDims-1) ||
287 (static_cast<int>(Layout) ==
static_cast<int>(
RowMajor) && m_dim.actualDim() == 0)) {
290 inputIndex = index + m_inputOffset;
292 const Index idx = index / m_stride;
293 inputIndex = idx * m_inputStride + m_inputOffset;
294 index -= idx * m_stride;
311 template<DenseIndex DimId,
typename ArgType,
typename Device>
313 :
public TensorEvaluator<const TensorChippingOp<DimId, ArgType>, Device>
318 static const int NumDims = NumInputDims-1;
338 return this->m_impl.coeffRef(this->srcCoeff(index));
346 if ((static_cast<int>(this->Layout) == static_cast<int>(
ColMajor) && this->m_dim.actualDim() == 0) ||
347 (static_cast<int>(this->Layout) ==
static_cast<int>(
RowMajor) && this->m_dim.actualDim() == NumInputDims-1)) {
351 internal::pstore<CoeffReturnType, PacketReturnType>(values, x);
352 Index inputIndex = index * this->m_inputStride + this->m_inputOffset;
353 for (
int i = 0; i < PacketSize; ++i) {
354 this->m_impl.coeffRef(inputIndex) = values[i];
355 inputIndex += this->m_inputStride;
357 }
else if ((static_cast<int>(this->Layout) == static_cast<int>(
ColMajor) && this->m_dim.actualDim() == NumInputDims-1) ||
358 (static_cast<int>(this->Layout) ==
static_cast<int>(
RowMajor) && this->m_dim.actualDim() == 0)) {
361 this->m_impl.template writePacket<StoreMode>(index + this->m_inputOffset, x);
363 const Index idx = index / this->m_stride;
364 const Index
rem = index - idx * this->m_stride;
365 if (rem + PacketSize <= this->m_stride) {
366 const Index inputIndex = idx * this->m_inputStride + this->m_inputOffset +
rem;
367 this->m_impl.template writePacket<StoreMode>(inputIndex, x);
371 internal::pstore<CoeffReturnType, PacketReturnType>(values, x);
372 for (
int i = 0; i < PacketSize; ++i) {
373 this->coeffRef(index) = values[i];
384 #endif // EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H const internal::DimensionId< DimId > m_dim
XprType::CoeffReturnType CoeffReturnType
#define EIGEN_STRONG_INLINE
TensorChippingOp< DimId, ArgType > XprType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Eigen::NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
DSizes< Index, NumDims > Dimensions
std::vector< double > values
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DimensionId(DenseIndex dim)
Eigen::internal::traits< TensorChippingOp >::StorageKind StorageKind
XprTraits::StorageKind StorageKind
A cost model used to limit the number of threads used for evaluating tensor expression.
const mpreal rem(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
remove_reference< Nested >::type _Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
DSizes< Index, NumDims > Dimensions
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex actualDim() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
const internal::DimensionId< DimId > m_dim
TensorEvaluator< ArgType, Device > m_impl
traits< XprType > XprTraits
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex actualDim() const
Eigen::internal::traits< TensorChippingOp >::Index Index
const DenseIndex actual_dim
static EIGEN_DEVICE_FUNC void run(const Expression &expr, const Device &device=Device())
TensorEvaluator< const TensorChippingOp< DimId, ArgType >, Device > Base
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x)
TensorChippingOp< DimId, ArgType > XprType
PacketType< CoeffReturnType, Device >::type PacketReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType * data() const
PacketType< CoeffReturnType, Device >::type PacketReturnType
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index srcCoeff(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorChippingOp(const XprType &expr, const Index offset, const Index dim)
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Eigen::internal::nested< TensorChippingOp >::type Nested
TensorChippingOp< DimId, XprType > type
EIGEN_DEVICE_FUNC const Index dim() const
EIGEN_DEVICE_FUNC const Index offset() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DimensionId(DenseIndex dim)
Eigen::internal::traits< TensorChippingOp >::Scalar Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType & coeffRef(Index index)
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar *)
const TensorChippingOp< DimId, XprType > & type
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
internal::packet_traits< Scalar >::type type