Warning, file /include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorVolumePatch.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
0005 #define EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
0006
0007 namespace Eigen {
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 namespace internal {
0025
0026 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
0027 struct traits<TensorVolumePatchOp<Planes, Rows, Cols, XprType> > : public traits<XprType>
0028 {
0029 typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar;
0030 typedef traits<XprType> XprTraits;
0031 typedef typename XprTraits::StorageKind StorageKind;
0032 typedef typename XprTraits::Index Index;
0033 typedef typename XprType::Nested Nested;
0034 typedef typename remove_reference<Nested>::type _Nested;
0035 static const int NumDimensions = XprTraits::NumDimensions + 1;
0036 static const int Layout = XprTraits::Layout;
0037 typedef typename XprTraits::PointerType PointerType;
0038
0039 };
0040
0041 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
0042 struct eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, Eigen::Dense>
0043 {
0044 typedef const TensorVolumePatchOp<Planes, Rows, Cols, XprType>& type;
0045 };
0046
0047 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
0048 struct nested<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, 1, typename eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType> >::type>
0049 {
0050 typedef TensorVolumePatchOp<Planes, Rows, Cols, XprType> type;
0051 };
0052
0053 }
0054
0055 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
0056 class TensorVolumePatchOp : public TensorBase<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, ReadOnlyAccessors>
0057 {
0058 public:
0059 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Scalar Scalar;
0060 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
0061 typedef typename XprType::CoeffReturnType CoeffReturnType;
0062 typedef typename Eigen::internal::nested<TensorVolumePatchOp>::type Nested;
0063 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::StorageKind StorageKind;
0064 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Index Index;
0065
0066 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols,
0067 DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides,
0068 DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides,
0069 DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides,
0070 PaddingType padding_type, Scalar padding_value)
0071 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
0072 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
0073 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
0074 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
0075 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),
0076 m_padding_type(padding_type), m_padding_value(padding_value) {}
0077
0078 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols,
0079 DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides,
0080 DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides,
0081 DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides,
0082 DenseIndex padding_top_z, DenseIndex padding_bottom_z,
0083 DenseIndex padding_top, DenseIndex padding_bottom,
0084 DenseIndex padding_left, DenseIndex padding_right,
0085 Scalar padding_value)
0086 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
0087 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
0088 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
0089 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
0090 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),
0091 m_padding_left(padding_left), m_padding_right(padding_right),
0092 m_padding_type(PADDING_VALID), m_padding_value(padding_value) {}
0093
0094 EIGEN_DEVICE_FUNC
0095 DenseIndex patch_planes() const { return m_patch_planes; }
0096 EIGEN_DEVICE_FUNC
0097 DenseIndex patch_rows() const { return m_patch_rows; }
0098 EIGEN_DEVICE_FUNC
0099 DenseIndex patch_cols() const { return m_patch_cols; }
0100 EIGEN_DEVICE_FUNC
0101 DenseIndex plane_strides() const { return m_plane_strides; }
0102 EIGEN_DEVICE_FUNC
0103 DenseIndex row_strides() const { return m_row_strides; }
0104 EIGEN_DEVICE_FUNC
0105 DenseIndex col_strides() const { return m_col_strides; }
0106 EIGEN_DEVICE_FUNC
0107 DenseIndex in_plane_strides() const { return m_in_plane_strides; }
0108 EIGEN_DEVICE_FUNC
0109 DenseIndex in_row_strides() const { return m_in_row_strides; }
0110 EIGEN_DEVICE_FUNC
0111 DenseIndex in_col_strides() const { return m_in_col_strides; }
0112 EIGEN_DEVICE_FUNC
0113 DenseIndex plane_inflate_strides() const { return m_plane_inflate_strides; }
0114 EIGEN_DEVICE_FUNC
0115 DenseIndex row_inflate_strides() const { return m_row_inflate_strides; }
0116 EIGEN_DEVICE_FUNC
0117 DenseIndex col_inflate_strides() const { return m_col_inflate_strides; }
0118 EIGEN_DEVICE_FUNC
0119 bool padding_explicit() const { return m_padding_explicit; }
0120 EIGEN_DEVICE_FUNC
0121 DenseIndex padding_top_z() const { return m_padding_top_z; }
0122 EIGEN_DEVICE_FUNC
0123 DenseIndex padding_bottom_z() const { return m_padding_bottom_z; }
0124 EIGEN_DEVICE_FUNC
0125 DenseIndex padding_top() const { return m_padding_top; }
0126 EIGEN_DEVICE_FUNC
0127 DenseIndex padding_bottom() const { return m_padding_bottom; }
0128 EIGEN_DEVICE_FUNC
0129 DenseIndex padding_left() const { return m_padding_left; }
0130 EIGEN_DEVICE_FUNC
0131 DenseIndex padding_right() const { return m_padding_right; }
0132 EIGEN_DEVICE_FUNC
0133 PaddingType padding_type() const { return m_padding_type; }
0134 EIGEN_DEVICE_FUNC
0135 Scalar padding_value() const { return m_padding_value; }
0136
0137 EIGEN_DEVICE_FUNC
0138 const typename internal::remove_all<typename XprType::Nested>::type&
0139 expression() const { return m_xpr; }
0140
0141 protected:
0142 typename XprType::Nested m_xpr;
0143 const DenseIndex m_patch_planes;
0144 const DenseIndex m_patch_rows;
0145 const DenseIndex m_patch_cols;
0146 const DenseIndex m_plane_strides;
0147 const DenseIndex m_row_strides;
0148 const DenseIndex m_col_strides;
0149 const DenseIndex m_in_plane_strides;
0150 const DenseIndex m_in_row_strides;
0151 const DenseIndex m_in_col_strides;
0152 const DenseIndex m_plane_inflate_strides;
0153 const DenseIndex m_row_inflate_strides;
0154 const DenseIndex m_col_inflate_strides;
0155 const bool m_padding_explicit;
0156 const DenseIndex m_padding_top_z;
0157 const DenseIndex m_padding_bottom_z;
0158 const DenseIndex m_padding_top;
0159 const DenseIndex m_padding_bottom;
0160 const DenseIndex m_padding_left;
0161 const DenseIndex m_padding_right;
0162 const PaddingType m_padding_type;
0163 const Scalar m_padding_value;
0164 };
0165
0166
0167
0168 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename ArgType, typename Device>
0169 struct TensorEvaluator<const TensorVolumePatchOp<Planes, Rows, Cols, ArgType>, Device>
0170 {
0171 typedef TensorVolumePatchOp<Planes, Rows, Cols, ArgType> XprType;
0172 typedef typename XprType::Index Index;
0173 static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
0174 static const int NumDims = NumInputDims + 1;
0175 typedef DSizes<Index, NumDims> Dimensions;
0176 typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar;
0177 typedef typename XprType::CoeffReturnType CoeffReturnType;
0178 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
0179 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
0180 typedef StorageMemory<CoeffReturnType, Device> Storage;
0181 typedef typename Storage::Type EvaluatorPointerType;
0182
0183 enum {
0184 IsAligned = false,
0185 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
0186 BlockAccess = false,
0187 PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess,
0188 Layout = TensorEvaluator<ArgType, Device>::Layout,
0189 CoordAccess = false,
0190 RawAccess = false
0191 };
0192
0193
0194 typedef internal::TensorBlockNotImplemented TensorBlock;
0195
0196
0197 EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) :
0198 m_impl(op.expression(), device)
0199 {
0200 EIGEN_STATIC_ASSERT((NumDims >= 5), YOU_MADE_A_PROGRAMMING_MISTAKE);
0201
0202 m_paddingValue = op.padding_value();
0203
0204 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
0205
0206
0207 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
0208 m_inputDepth = input_dims[0];
0209 m_inputPlanes = input_dims[1];
0210 m_inputRows = input_dims[2];
0211 m_inputCols = input_dims[3];
0212 } else {
0213 m_inputDepth = input_dims[NumInputDims-1];
0214 m_inputPlanes = input_dims[NumInputDims-2];
0215 m_inputRows = input_dims[NumInputDims-3];
0216 m_inputCols = input_dims[NumInputDims-4];
0217 }
0218
0219 m_plane_strides = op.plane_strides();
0220 m_row_strides = op.row_strides();
0221 m_col_strides = op.col_strides();
0222
0223
0224 m_in_plane_strides = op.in_plane_strides();
0225 m_in_row_strides = op.in_row_strides();
0226 m_in_col_strides = op.in_col_strides();
0227 m_plane_inflate_strides = op.plane_inflate_strides();
0228 m_row_inflate_strides = op.row_inflate_strides();
0229 m_col_inflate_strides = op.col_inflate_strides();
0230
0231
0232 m_input_planes_eff = (m_inputPlanes - 1) * m_plane_inflate_strides + 1;
0233 m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1;
0234 m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1;
0235 m_patch_planes_eff = op.patch_planes() + (op.patch_planes() - 1) * (m_in_plane_strides - 1);
0236 m_patch_rows_eff = op.patch_rows() + (op.patch_rows() - 1) * (m_in_row_strides - 1);
0237 m_patch_cols_eff = op.patch_cols() + (op.patch_cols() - 1) * (m_in_col_strides - 1);
0238
0239 if (op.padding_explicit()) {
0240 m_outputPlanes = numext::ceil((m_input_planes_eff + op.padding_top_z() + op.padding_bottom_z() - m_patch_planes_eff + 1.f) / static_cast<float>(m_plane_strides));
0241 m_outputRows = numext::ceil((m_input_rows_eff + op.padding_top() + op.padding_bottom() - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides));
0242 m_outputCols = numext::ceil((m_input_cols_eff + op.padding_left() + op.padding_right() - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides));
0243 m_planePaddingTop = op.padding_top_z();
0244 m_rowPaddingTop = op.padding_top();
0245 m_colPaddingLeft = op.padding_left();
0246 } else {
0247
0248 switch (op.padding_type()) {
0249 case PADDING_VALID:
0250 m_outputPlanes = numext::ceil((m_input_planes_eff - m_patch_planes_eff + 1.f) / static_cast<float>(m_plane_strides));
0251 m_outputRows = numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides));
0252 m_outputCols = numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides));
0253 m_planePaddingTop = 0;
0254 m_rowPaddingTop = 0;
0255 m_colPaddingLeft = 0;
0256 break;
0257 case PADDING_SAME: {
0258 m_outputPlanes = numext::ceil(m_input_planes_eff / static_cast<float>(m_plane_strides));
0259 m_outputRows = numext::ceil(m_input_rows_eff / static_cast<float>(m_row_strides));
0260 m_outputCols = numext::ceil(m_input_cols_eff / static_cast<float>(m_col_strides));
0261 const Index dz = (m_outputPlanes - 1) * m_plane_strides + m_patch_planes_eff - m_input_planes_eff;
0262 const Index dy = (m_outputRows - 1) * m_row_strides + m_patch_rows_eff - m_input_rows_eff;
0263 const Index dx = (m_outputCols - 1) * m_col_strides + m_patch_cols_eff - m_input_cols_eff;
0264 m_planePaddingTop = dz / 2;
0265 m_rowPaddingTop = dy / 2;
0266 m_colPaddingLeft = dx / 2;
0267 break;
0268 }
0269 default:
0270 eigen_assert(false && "unexpected padding");
0271 }
0272 }
0273 eigen_assert(m_outputRows > 0);
0274 eigen_assert(m_outputCols > 0);
0275 eigen_assert(m_outputPlanes > 0);
0276
0277
0278 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
0279
0280
0281
0282
0283
0284
0285
0286 m_dimensions[0] = input_dims[0];
0287 m_dimensions[1] = op.patch_planes();
0288 m_dimensions[2] = op.patch_rows();
0289 m_dimensions[3] = op.patch_cols();
0290 m_dimensions[4] = m_outputPlanes * m_outputRows * m_outputCols;
0291 for (int i = 5; i < NumDims; ++i) {
0292 m_dimensions[i] = input_dims[i-1];
0293 }
0294 } else {
0295
0296
0297
0298
0299
0300
0301
0302 m_dimensions[NumDims-1] = input_dims[NumInputDims-1];
0303 m_dimensions[NumDims-2] = op.patch_planes();
0304 m_dimensions[NumDims-3] = op.patch_rows();
0305 m_dimensions[NumDims-4] = op.patch_cols();
0306 m_dimensions[NumDims-5] = m_outputPlanes * m_outputRows * m_outputCols;
0307 for (int i = NumDims-6; i >= 0; --i) {
0308 m_dimensions[i] = input_dims[i];
0309 }
0310 }
0311
0312
0313 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
0314 m_rowStride = m_dimensions[1];
0315 m_colStride = m_dimensions[2] * m_rowStride;
0316 m_patchStride = m_colStride * m_dimensions[3] * m_dimensions[0];
0317 m_otherStride = m_patchStride * m_dimensions[4];
0318 } else {
0319 m_rowStride = m_dimensions[NumDims-2];
0320 m_colStride = m_dimensions[NumDims-3] * m_rowStride;
0321 m_patchStride = m_colStride * m_dimensions[NumDims-4] * m_dimensions[NumDims-1];
0322 m_otherStride = m_patchStride * m_dimensions[NumDims-5];
0323 }
0324
0325
0326 m_planeInputStride = m_inputDepth;
0327 m_rowInputStride = m_inputDepth * m_inputPlanes;
0328 m_colInputStride = m_inputDepth * m_inputRows * m_inputPlanes;
0329 m_otherInputStride = m_inputDepth * m_inputRows * m_inputCols * m_inputPlanes;
0330
0331 m_outputPlanesRows = m_outputPlanes * m_outputRows;
0332
0333
0334 m_fastOtherStride = internal::TensorIntDivisor<Index>(m_otherStride);
0335
0336 m_fastPatchStride = internal::TensorIntDivisor<Index>(m_patchStride);
0337 m_fastColStride = internal::TensorIntDivisor<Index>(m_colStride);
0338 m_fastRowStride = internal::TensorIntDivisor<Index>(m_rowStride);
0339 m_fastInputRowStride = internal::TensorIntDivisor<Index>(m_row_inflate_strides);
0340 m_fastInputColStride = internal::TensorIntDivisor<Index>(m_col_inflate_strides);
0341 m_fastInputPlaneStride = internal::TensorIntDivisor<Index>(m_plane_inflate_strides);
0342 m_fastInputColsEff = internal::TensorIntDivisor<Index>(m_input_cols_eff);
0343 m_fastOutputPlanes = internal::TensorIntDivisor<Index>(m_outputPlanes);
0344 m_fastOutputPlanesRows = internal::TensorIntDivisor<Index>(m_outputPlanesRows);
0345
0346 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
0347 m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[0]);
0348 } else {
0349 m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[NumDims-1]);
0350 }
0351 }
0352
0353 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; }
0354
0355 EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType ) {
0356 m_impl.evalSubExprsIfNeeded(NULL);
0357 return true;
0358 }
0359
0360 EIGEN_STRONG_INLINE void cleanup() {
0361 m_impl.cleanup();
0362 }
0363
0364 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
0365 {
0366
0367 const Index patchIndex = index / m_fastPatchStride;
0368
0369
0370
0371 const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth;
0372
0373
0374 const Index otherIndex = (NumDims == 5) ? 0 : index / m_fastOtherStride;
0375 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride;
0376
0377
0378 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
0379 const Index colOffset = patchOffset / m_fastColStride;
0380 const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
0381 const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
0382 if (inputCol < 0 || inputCol >= m_input_cols_eff ||
0383 ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
0384 return Scalar(m_paddingValue);
0385 }
0386
0387
0388 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
0389 const Index rowOffset = (patchOffset - colOffset * m_colStride) / m_fastRowStride;
0390 const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
0391 const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
0392 if (inputRow < 0 || inputRow >= m_input_rows_eff ||
0393 ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
0394 return Scalar(m_paddingValue);
0395 }
0396
0397
0398 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
0399 const Index planeOffset = patchOffset - colOffset * m_colStride - rowOffset * m_rowStride;
0400 const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
0401 const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
0402 if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
0403 ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
0404 return Scalar(m_paddingValue);
0405 }
0406
0407 const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
0408 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
0409
0410 const Index inputIndex = depth +
0411 origInputRow * m_rowInputStride +
0412 origInputCol * m_colInputStride +
0413 origInputPlane * m_planeInputStride +
0414 otherIndex * m_otherInputStride;
0415
0416 return m_impl.coeff(inputIndex);
0417 }
0418
0419 template<int LoadMode>
0420 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
0421 {
0422 EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
0423 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
0424
0425 if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1 ||
0426 m_in_plane_strides != 1 || m_plane_inflate_strides != 1) {
0427 return packetWithPossibleZero(index);
0428 }
0429
0430 const Index indices[2] = {index, index + PacketSize - 1};
0431 const Index patchIndex = indices[0] / m_fastPatchStride;
0432 if (patchIndex != indices[1] / m_fastPatchStride) {
0433 return packetWithPossibleZero(index);
0434 }
0435 const Index otherIndex = (NumDims == 5) ? 0 : indices[0] / m_fastOtherStride;
0436 eigen_assert(otherIndex == indices[1] / m_fastOtherStride);
0437
0438
0439 const Index patchOffsets[2] = {(indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth,
0440 (indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth};
0441
0442 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (indices[0] - otherIndex * m_otherStride) / m_fastPatchStride;
0443 eigen_assert(patch3DIndex == (indices[1] - otherIndex * m_otherStride) / m_fastPatchStride);
0444
0445 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
0446 const Index colOffsets[2] = {
0447 patchOffsets[0] / m_fastColStride,
0448 patchOffsets[1] / m_fastColStride};
0449
0450
0451 const Index inputCols[2] = {
0452 colIndex * m_col_strides + colOffsets[0] - m_colPaddingLeft,
0453 colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft};
0454 if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) {
0455 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
0456 }
0457
0458 if (inputCols[0] != inputCols[1]) {
0459 return packetWithPossibleZero(index);
0460 }
0461
0462 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
0463 const Index rowOffsets[2] = {
0464 (patchOffsets[0] - colOffsets[0] * m_colStride) / m_fastRowStride,
0465 (patchOffsets[1] - colOffsets[1] * m_colStride) / m_fastRowStride};
0466 eigen_assert(rowOffsets[0] <= rowOffsets[1]);
0467
0468 const Index inputRows[2] = {
0469 rowIndex * m_row_strides + rowOffsets[0] - m_rowPaddingTop,
0470 rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop};
0471
0472 if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) {
0473 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
0474 }
0475
0476 if (inputRows[0] != inputRows[1]) {
0477 return packetWithPossibleZero(index);
0478 }
0479
0480 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
0481 const Index planeOffsets[2] = {
0482 patchOffsets[0] - colOffsets[0] * m_colStride - rowOffsets[0] * m_rowStride,
0483 patchOffsets[1] - colOffsets[1] * m_colStride - rowOffsets[1] * m_rowStride};
0484 eigen_assert(planeOffsets[0] <= planeOffsets[1]);
0485 const Index inputPlanes[2] = {
0486 planeIndex * m_plane_strides + planeOffsets[0] - m_planePaddingTop,
0487 planeIndex * m_plane_strides + planeOffsets[1] - m_planePaddingTop};
0488
0489 if (inputPlanes[1] < 0 || inputPlanes[0] >= m_inputPlanes) {
0490 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
0491 }
0492
0493 if (inputPlanes[0] >= 0 && inputPlanes[1] < m_inputPlanes) {
0494
0495 const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
0496 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
0497 const Index inputIndex = depth +
0498 inputRows[0] * m_rowInputStride +
0499 inputCols[0] * m_colInputStride +
0500 m_planeInputStride * inputPlanes[0] +
0501 otherIndex * m_otherInputStride;
0502 return m_impl.template packet<Unaligned>(inputIndex);
0503 }
0504
0505 return packetWithPossibleZero(index);
0506 }
0507
0508 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost
0509 costPerCoeff(bool vectorized) const {
0510 const double compute_cost =
0511 10 * TensorOpCost::DivCost<Index>() + 21 * TensorOpCost::MulCost<Index>() +
0512 8 * TensorOpCost::AddCost<Index>();
0513 return TensorOpCost(0, 0, compute_cost, vectorized, PacketSize);
0514 }
0515
0516 EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; }
0517
0518 const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
0519
0520
0521 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index planePaddingTop() const { return m_planePaddingTop; }
0522 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowPaddingTop() const { return m_rowPaddingTop; }
0523 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colPaddingLeft() const { return m_colPaddingLeft; }
0524 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outputPlanes() const { return m_outputPlanes; }
0525 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outputRows() const { return m_outputRows; }
0526 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outputCols() const { return m_outputCols; }
0527 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userPlaneStride() const { return m_plane_strides; }
0528 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userRowStride() const { return m_row_strides; }
0529 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userColStride() const { return m_col_strides; }
0530 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userInPlaneStride() const { return m_in_plane_strides; }
0531 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userInRowStride() const { return m_in_row_strides; }
0532 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userInColStride() const { return m_in_col_strides; }
0533 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index planeInflateStride() const { return m_plane_inflate_strides; }
0534 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowInflateStride() const { return m_row_inflate_strides; }
0535 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colInflateStride() const { return m_col_inflate_strides; }
0536
0537 #ifdef EIGEN_USE_SYCL
0538
0539 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
0540 m_impl.bind(cgh);
0541 }
0542 #endif
0543 protected:
0544 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const
0545 {
0546 EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize];
0547 EIGEN_UNROLL_LOOP
0548 for (int i = 0; i < PacketSize; ++i) {
0549 values[i] = coeff(index+i);
0550 }
0551 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
0552 return rslt;
0553 }
0554
0555 Dimensions m_dimensions;
0556
0557
0558 Index m_plane_strides;
0559 Index m_row_strides;
0560 Index m_col_strides;
0561
0562 Index m_outputPlanes;
0563 Index m_outputRows;
0564 Index m_outputCols;
0565
0566 Index m_planePaddingTop;
0567 Index m_rowPaddingTop;
0568 Index m_colPaddingLeft;
0569
0570 Index m_in_plane_strides;
0571 Index m_in_row_strides;
0572 Index m_in_col_strides;
0573
0574 Index m_plane_inflate_strides;
0575 Index m_row_inflate_strides;
0576 Index m_col_inflate_strides;
0577
0578
0579 Index m_inputDepth;
0580 Index m_inputPlanes;
0581 Index m_inputRows;
0582 Index m_inputCols;
0583
0584
0585 Index m_outputPlanesRows;
0586
0587
0588 Index m_input_planes_eff;
0589 Index m_input_rows_eff;
0590 Index m_input_cols_eff;
0591 Index m_patch_planes_eff;
0592 Index m_patch_rows_eff;
0593 Index m_patch_cols_eff;
0594
0595
0596 Index m_otherStride;
0597 Index m_patchStride;
0598 Index m_rowStride;
0599 Index m_colStride;
0600
0601
0602 Index m_planeInputStride;
0603 Index m_rowInputStride;
0604 Index m_colInputStride;
0605 Index m_otherInputStride;
0606
0607 internal::TensorIntDivisor<Index> m_fastOtherStride;
0608 internal::TensorIntDivisor<Index> m_fastPatchStride;
0609 internal::TensorIntDivisor<Index> m_fastColStride;
0610 internal::TensorIntDivisor<Index> m_fastRowStride;
0611 internal::TensorIntDivisor<Index> m_fastInputPlaneStride;
0612 internal::TensorIntDivisor<Index> m_fastInputRowStride;
0613 internal::TensorIntDivisor<Index> m_fastInputColStride;
0614 internal::TensorIntDivisor<Index> m_fastInputColsEff;
0615 internal::TensorIntDivisor<Index> m_fastOutputPlanesRows;
0616 internal::TensorIntDivisor<Index> m_fastOutputPlanes;
0617 internal::TensorIntDivisor<Index> m_fastOutputDepth;
0618
0619 Scalar m_paddingValue;
0620
0621 TensorEvaluator<ArgType, Device> m_impl;
0622
0623
0624 };
0625
0626
0627 }
0628
0629 #endif