10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H
24 template<DenseIndex DimId,
typename XprType>
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>
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;
162 for (
int i = 0; i < NumInputDims; ++i) {
163 if (i != m_dim.actualDim()) {
164 m_dimensions[j] = input_dims[i];
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>
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;
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);
248 m_dim.actualDim() == 0) ||
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) ||
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) +
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) {
384 #endif // EIGEN_CXX11_TENSOR_TENSOR_CHIPPING_H