4 #ifndef EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H 5 #define EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H 25 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
32 typedef typename XprType::Nested
Nested;
34 static const int NumDimensions = XprTraits::NumDimensions + 1;
35 static const int Layout = XprTraits::Layout;
38 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
44 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
52 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
68 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
69 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
70 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
71 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
72 m_padding_explicit(false), m_padding_top_z(0), m_padding_bottom_z(0), m_padding_top(0), m_padding_bottom(0), m_padding_left(0), m_padding_right(0),
73 m_padding_type(padding_type), m_padding_value(padding_value) {}
83 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
84 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
85 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
86 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
87 m_padding_explicit(true), m_padding_top_z(padding_top_z), m_padding_bottom_z(padding_bottom_z), m_padding_top(padding_top), m_padding_bottom(padding_bottom),
88 m_padding_left(padding_left), m_padding_right(padding_right),
89 m_padding_type(
PADDING_VALID), m_padding_value(padding_value) {}
165 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename ArgType,
typename Device>
171 static const int NumDims = NumInputDims + 1;
188 : m_impl(op.expression(), device)
197 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
198 m_inputDepth = input_dims[0];
199 m_inputPlanes = input_dims[1];
200 m_inputRows = input_dims[2];
201 m_inputCols = input_dims[3];
203 m_inputDepth = input_dims[NumInputDims-1];
204 m_inputPlanes = input_dims[NumInputDims-2];
205 m_inputRows = input_dims[NumInputDims-3];
206 m_inputCols = input_dims[NumInputDims-4];
222 m_input_planes_eff = (m_inputPlanes - 1) * m_plane_inflate_strides + 1;
223 m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1;
224 m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1;
240 m_outputPlanes =
numext::ceil((m_input_planes_eff - m_patch_planes_eff + 1.
f) / static_cast<float>(m_plane_strides));
241 m_outputRows =
numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.
f) / static_cast<float>(m_row_strides));
242 m_outputCols =
numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.
f) / static_cast<float>(m_col_strides));
243 m_planePaddingTop = 0;
245 m_colPaddingLeft = 0;
248 m_outputPlanes =
numext::ceil(m_input_planes_eff / static_cast<float>(m_plane_strides));
249 m_outputRows =
numext::ceil(m_input_rows_eff / static_cast<float>(m_row_strides));
250 m_outputCols =
numext::ceil(m_input_cols_eff / static_cast<float>(m_col_strides));
251 const Index dz = m_outputPlanes * m_plane_strides + m_patch_planes_eff - 1 - m_input_planes_eff;
252 const Index dy = m_outputRows * m_row_strides + m_patch_rows_eff - 1 - m_input_rows_eff;
253 const Index dx = m_outputCols * m_col_strides + m_patch_cols_eff - 1 - m_input_cols_eff;
254 m_planePaddingTop = dz - dz / 2;
255 m_rowPaddingTop = dy - dy / 2;
256 m_colPaddingLeft = dx - dx / 2;
268 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
276 m_dimensions[0] = input_dims[0];
280 m_dimensions[4] = m_outputPlanes * m_outputRows * m_outputCols;
281 for (
int i = 5; i < NumDims; ++i) {
282 m_dimensions[i] = input_dims[i-1];
292 m_dimensions[NumDims-1] = input_dims[NumInputDims-1];
296 m_dimensions[NumDims-5] = m_outputPlanes * m_outputRows * m_outputCols;
297 for (
int i = NumDims-6; i >= 0; --i) {
298 m_dimensions[i] = input_dims[i];
303 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
304 m_rowStride = m_dimensions[1];
305 m_colStride = m_dimensions[2] * m_rowStride;
306 m_patchStride = m_colStride * m_dimensions[3] * m_dimensions[0];
307 m_otherStride = m_patchStride * m_dimensions[4];
309 m_rowStride = m_dimensions[NumDims-2];
310 m_colStride = m_dimensions[NumDims-3] * m_rowStride;
311 m_patchStride = m_colStride * m_dimensions[NumDims-4] * m_dimensions[NumDims-1];
312 m_otherStride = m_patchStride * m_dimensions[NumDims-5];
316 m_planeInputStride = m_inputDepth;
317 m_rowInputStride = m_inputDepth * m_inputPlanes;
318 m_colInputStride = m_inputDepth * m_inputRows * m_inputPlanes;
319 m_otherInputStride = m_inputDepth * m_inputRows * m_inputCols * m_inputPlanes;
321 m_outputPlanesRows = m_outputPlanes * m_outputRows;
335 if (static_cast<int>(Layout) ==
static_cast<int>(
ColMajor)) {
345 m_impl.evalSubExprsIfNeeded(NULL);
356 const Index patchIndex = index / m_fastPatchStride;
360 const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth;
363 const Index otherIndex = (NumDims == 5) ? 0 : index / m_fastOtherStride;
364 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride;
367 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
368 const Index colOffset = patchOffset / m_fastColStride;
369 const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
370 const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
371 if (inputCol < 0 || inputCol >= m_input_cols_eff ||
372 ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
373 return Scalar(m_paddingValue);
377 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
378 const Index rowOffset = (patchOffset - colOffset * m_colStride) / m_fastRowStride;
379 const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
380 const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
381 if (inputRow < 0 || inputRow >= m_input_rows_eff ||
382 ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
383 return Scalar(m_paddingValue);
387 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
388 const Index planeOffset = patchOffset - colOffset * m_colStride - rowOffset * m_rowStride;
389 const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
390 const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
391 if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
392 ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
393 return Scalar(m_paddingValue);
396 const int depth_index =
static_cast<int>(Layout) == static_cast<int>(
ColMajor) ? 0 : NumDims - 1;
397 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
399 const Index inputIndex = depth +
400 origInputRow * m_rowInputStride +
401 origInputCol * m_colInputStride +
402 origInputPlane * m_planeInputStride +
403 otherIndex * m_otherInputStride;
405 return m_impl.coeff(inputIndex);
408 template<
int LoadMode>
412 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
414 if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1 ||
415 m_in_plane_strides != 1 || m_plane_inflate_strides != 1) {
416 return packetWithPossibleZero(index);
419 const Index indices[2] = {index, index + PacketSize - 1};
420 const Index patchIndex = indices[0] / m_fastPatchStride;
421 if (patchIndex != indices[1] / m_fastPatchStride) {
422 return packetWithPossibleZero(index);
424 const Index otherIndex = (NumDims == 5) ? 0 : indices[0] / m_fastOtherStride;
425 eigen_assert(otherIndex == indices[1] / m_fastOtherStride);
428 const Index patchOffsets[2] = {(indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth,
429 (indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth};
431 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (indices[0] - otherIndex * m_otherStride) / m_fastPatchStride;
432 eigen_assert(patch3DIndex == (indices[1] - otherIndex * m_otherStride) / m_fastPatchStride);
434 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
435 const Index colOffsets[2] = {
436 patchOffsets[0] / m_fastColStride,
437 patchOffsets[1] / m_fastColStride};
440 const Index inputCols[2] = {
441 colIndex * m_col_strides + colOffsets[0] - m_colPaddingLeft,
442 colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft};
443 if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) {
444 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
447 if (inputCols[0] != inputCols[1]) {
448 return packetWithPossibleZero(index);
451 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
452 const Index rowOffsets[2] = {
453 (patchOffsets[0] - colOffsets[0] * m_colStride) / m_fastRowStride,
454 (patchOffsets[1] - colOffsets[1] * m_colStride) / m_fastRowStride};
457 const Index inputRows[2] = {
458 rowIndex * m_row_strides + rowOffsets[0] - m_rowPaddingTop,
459 rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop};
461 if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) {
462 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
465 if (inputRows[0] != inputRows[1]) {
466 return packetWithPossibleZero(index);
469 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
470 const Index planeOffsets[2] = {
471 patchOffsets[0] - colOffsets[0] * m_colStride - rowOffsets[0] * m_rowStride,
472 patchOffsets[1] - colOffsets[1] * m_colStride - rowOffsets[1] * m_rowStride};
474 const Index inputPlanes[2] = {
475 planeIndex * m_plane_strides + planeOffsets[0] - m_planePaddingTop,
476 planeIndex * m_plane_strides + planeOffsets[1] - m_planePaddingTop};
478 if (inputPlanes[1] < 0 || inputPlanes[0] >= m_inputPlanes) {
479 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
482 if (inputPlanes[0] >= 0 && inputPlanes[1] < m_inputPlanes) {
484 const int depth_index =
static_cast<int>(Layout) == static_cast<int>(
ColMajor) ? 0 : NumDims - 1;
485 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
486 const Index inputIndex = depth +
487 inputRows[0] * m_rowInputStride +
488 inputCols[0] * m_colInputStride +
489 m_planeInputStride * inputPlanes[0] +
490 otherIndex * m_otherInputStride;
491 return m_impl.template packet<Unaligned>(inputIndex);
494 return packetWithPossibleZero(index);
499 const double compute_cost =
500 10 * TensorOpCost::DivCost<Index>() + 21 * TensorOpCost::MulCost<Index>() +
501 8 * TensorOpCost::AddCost<Index>();
502 return TensorOpCost(0, 0, compute_cost, vectorized, PacketSize);
505 EIGEN_DEVICE_FUNC Scalar*
data()
const {
return NULL; }
529 for (
int i = 0; i < PacketSize; ++i) {
530 values[i] = coeff(index+i);
532 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
608 #endif // EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H internal::TensorIntDivisor< Index > m_fastColStride
EIGEN_DEVICE_FUNC DenseIndex padding_top_z() const
Index userRowStride() const
Index rowPaddingTop() const
Index m_col_inflate_strides
traits< XprType > XprTraits
internal::TensorIntDivisor< Index > m_fastInputRowStride
#define EIGEN_STRONG_INLINE
internal::TensorIntDivisor< Index > m_fastOtherStride
internal::TensorIntDivisor< Index > m_fastInputColStride
internal::TensorIntDivisor< Index > m_fastInputPlaneStride
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEVICE_FUNC DenseIndex in_col_strides() const
const DenseIndex m_row_strides
Index m_row_inflate_strides
std::vector< double > values
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
internal::TensorIntDivisor< Index > m_fastInputColsEff
XprTraits::StorageKind StorageKind
EIGEN_DEVICE_FUNC Scalar * data() const
EIGEN_DEVICE_FUNC DenseIndex padding_bottom() const
const TensorVolumePatchOp< Planes, Rows, Cols, XprType > & type
const DenseIndex m_padding_top
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC DenseIndex col_strides() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType &expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols, DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides, DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides, DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides, PaddingType padding_type, Scalar padding_value)
A cost model used to limit the number of threads used for evaluating tensor expression.
EIGEN_DEVICE_FUNC DenseIndex patch_cols() const
Index m_plane_inflate_strides
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Index userColStride() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
const DenseIndex m_padding_top_z
const DenseIndex m_col_strides
internal::TensorIntDivisor< Index > m_fastOutputPlanes
EIGEN_DEVICE_FUNC DenseIndex col_inflate_strides() const
const DenseIndex m_patch_planes
EIGEN_DEVICE_FUNC bool padding_explicit() const
Index planePaddingTop() const
TensorVolumePatchOp< Planes, Rows, Cols, ArgType > XprType
EIGEN_DEVICE_FUNC const CeilReturnType ceil() const
EIGEN_DEVICE_FUNC DenseIndex row_strides() const
Index colPaddingLeft() const
TensorVolumePatchOp< Planes, Rows, Cols, XprType > type
const DenseIndex m_patch_cols
EIGEN_DEVICE_FUNC DenseIndex padding_bottom_z() const
internal::remove_const< typename XprType::Scalar >::type Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const
TensorEvaluator< ArgType, Device > m_impl
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
const DenseIndex m_padding_bottom_z
Eigen::internal::traits< TensorVolumePatchOp >::StorageKind StorageKind
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const DenseIndex m_in_row_strides
Index colInflateStride() const
Eigen::internal::traits< TensorVolumePatchOp >::Index Index
const DenseIndex m_plane_strides
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEVICE_FUNC DenseIndex padding_right() const
EIGEN_DEVICE_FUNC DenseIndex plane_inflate_strides() const
const DenseIndex m_plane_inflate_strides
Index userInRowStride() const
Index outputPlanes() const
const TensorEvaluator< ArgType, Device > & impl() const
const DenseIndex m_padding_right
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
const DenseIndex m_in_plane_strides
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
internal::TensorIntDivisor< Index > m_fastOutputDepth
EIGEN_DEVICE_FUNC DenseIndex in_row_strides() const
const Scalar m_padding_value
remove_reference< Nested >::type _Nested
DSizes< Index, NumDims > Dimensions
EIGEN_DEVICE_FUNC DenseIndex plane_strides() const
const DenseIndex m_padding_bottom
const DenseIndex m_padding_left
Index userPlaneStride() const
Eigen::NumTraits< Scalar >::Real RealScalar
PacketType< CoeffReturnType, Device >::type PacketReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Index userInPlaneStride() const
const PaddingType m_padding_type
internal::TensorIntDivisor< Index > m_fastRowStride
Index userInColStride() const
XprType::CoeffReturnType CoeffReturnType
const DenseIndex m_row_inflate_strides
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
EIGEN_DEVICE_FUNC DenseIndex in_plane_strides() const
Index planeInflateStride() const
const DenseIndex m_col_inflate_strides
EIGEN_DEVICE_FUNC PaddingType padding_type() const
Eigen::internal::traits< TensorVolumePatchOp >::Scalar Scalar
internal::remove_const< typename XprType::Scalar >::type Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType &expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols, DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides, DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides, DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides, DenseIndex padding_top_z, DenseIndex padding_bottom_z, DenseIndex padding_top, DenseIndex padding_bottom, DenseIndex padding_left, DenseIndex padding_right, Scalar padding_value)
Eigen::internal::nested< TensorVolumePatchOp >::type Nested
const DenseIndex m_patch_rows
const bool m_padding_explicit
EIGEN_DEVICE_FUNC DenseIndex patch_rows() const
EIGEN_DEVICE_FUNC DenseIndex patch_planes() const
EIGEN_DEVICE_FUNC Scalar padding_value() const
EIGEN_DEVICE_FUNC DenseIndex padding_top() const
internal::packet_traits< Scalar >::type type
const DenseIndex m_in_col_strides
EIGEN_DEVICE_FUNC DenseIndex padding_left() const
internal::TensorIntDivisor< Index > m_fastOutputPlanesRows
EIGEN_DEVICE_FUNC DenseIndex row_inflate_strides() const
internal::TensorIntDivisor< Index > m_fastPatchStride
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar *)
Index rowInflateStride() const