Eigen-unsupported  3.4.1 (git rev 28ded8800c26864e537852658428ab44c8399e87)
 
Loading...
Searching...
No Matches
TensorVolumePatch.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3
4#ifndef EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
5#define EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
6
7namespace Eigen {
8
9namespace internal {
10
11template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
12struct traits<TensorVolumePatchOp<Planes, Rows, Cols, XprType> > : public traits<XprType>
13{
14 typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar;
15 typedef traits<XprType> XprTraits;
16 typedef typename XprTraits::StorageKind StorageKind;
17 typedef typename XprTraits::Index Index;
18 typedef typename XprType::Nested Nested;
19 typedef typename remove_reference<Nested>::type _Nested;
20 static const int NumDimensions = XprTraits::NumDimensions + 1;
21 static const int Layout = XprTraits::Layout;
22 typedef typename XprTraits::PointerType PointerType;
23
24};
25
26template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
27struct eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, Eigen::Dense>
28{
29 typedef const TensorVolumePatchOp<Planes, Rows, Cols, XprType>& type;
30};
31
32template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
33struct nested<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, 1, typename eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType> >::type>
34{
35 typedef TensorVolumePatchOp<Planes, Rows, Cols, XprType> type;
36};
37
38} // end namespace internal
39
55template <DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename XprType>
56class TensorVolumePatchOp : public TensorBase<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, ReadOnlyAccessors> {
57 public:
58 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Scalar Scalar;
59 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
60 typedef typename XprType::CoeffReturnType CoeffReturnType;
61 typedef typename Eigen::internal::nested<TensorVolumePatchOp>::type Nested;
62 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::StorageKind StorageKind;
63 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Index Index;
64
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols,
66 DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides,
67 DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides,
68 DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides,
69 PaddingType padding_type, Scalar padding_value)
70 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
71 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
72 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
73 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
74 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),
75 m_padding_type(padding_type), m_padding_value(padding_value) {}
76
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols,
78 DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides,
79 DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides,
80 DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides,
81 DenseIndex padding_top_z, DenseIndex padding_bottom_z,
82 DenseIndex padding_top, DenseIndex padding_bottom,
83 DenseIndex padding_left, DenseIndex padding_right,
84 Scalar padding_value)
85 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
86 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
87 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
88 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
89 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),
90 m_padding_left(padding_left), m_padding_right(padding_right),
91 m_padding_type(PADDING_VALID), m_padding_value(padding_value) {}
92
93 EIGEN_DEVICE_FUNC
94 DenseIndex patch_planes() const { return m_patch_planes; }
95 EIGEN_DEVICE_FUNC
96 DenseIndex patch_rows() const { return m_patch_rows; }
97 EIGEN_DEVICE_FUNC
98 DenseIndex patch_cols() const { return m_patch_cols; }
99 EIGEN_DEVICE_FUNC
100 DenseIndex plane_strides() const { return m_plane_strides; }
101 EIGEN_DEVICE_FUNC
102 DenseIndex row_strides() const { return m_row_strides; }
103 EIGEN_DEVICE_FUNC
104 DenseIndex col_strides() const { return m_col_strides; }
105 EIGEN_DEVICE_FUNC
106 DenseIndex in_plane_strides() const { return m_in_plane_strides; }
107 EIGEN_DEVICE_FUNC
108 DenseIndex in_row_strides() const { return m_in_row_strides; }
109 EIGEN_DEVICE_FUNC
110 DenseIndex in_col_strides() const { return m_in_col_strides; }
111 EIGEN_DEVICE_FUNC
112 DenseIndex plane_inflate_strides() const { return m_plane_inflate_strides; }
113 EIGEN_DEVICE_FUNC
114 DenseIndex row_inflate_strides() const { return m_row_inflate_strides; }
115 EIGEN_DEVICE_FUNC
116 DenseIndex col_inflate_strides() const { return m_col_inflate_strides; }
117 EIGEN_DEVICE_FUNC
118 bool padding_explicit() const { return m_padding_explicit; }
119 EIGEN_DEVICE_FUNC
120 DenseIndex padding_top_z() const { return m_padding_top_z; }
121 EIGEN_DEVICE_FUNC
122 DenseIndex padding_bottom_z() const { return m_padding_bottom_z; }
123 EIGEN_DEVICE_FUNC
124 DenseIndex padding_top() const { return m_padding_top; }
125 EIGEN_DEVICE_FUNC
126 DenseIndex padding_bottom() const { return m_padding_bottom; }
127 EIGEN_DEVICE_FUNC
128 DenseIndex padding_left() const { return m_padding_left; }
129 EIGEN_DEVICE_FUNC
130 DenseIndex padding_right() const { return m_padding_right; }
131 EIGEN_DEVICE_FUNC
132 PaddingType padding_type() const { return m_padding_type; }
133 EIGEN_DEVICE_FUNC
134 Scalar padding_value() const { return m_padding_value; }
135
136 EIGEN_DEVICE_FUNC
137 const typename internal::remove_all<typename XprType::Nested>::type&
138 expression() const { return m_xpr; }
139
140 protected:
141 typename XprType::Nested m_xpr;
142 const DenseIndex m_patch_planes;
143 const DenseIndex m_patch_rows;
144 const DenseIndex m_patch_cols;
145 const DenseIndex m_plane_strides;
146 const DenseIndex m_row_strides;
147 const DenseIndex m_col_strides;
148 const DenseIndex m_in_plane_strides;
149 const DenseIndex m_in_row_strides;
150 const DenseIndex m_in_col_strides;
151 const DenseIndex m_plane_inflate_strides;
152 const DenseIndex m_row_inflate_strides;
153 const DenseIndex m_col_inflate_strides;
154 const bool m_padding_explicit;
155 const DenseIndex m_padding_top_z;
156 const DenseIndex m_padding_bottom_z;
157 const DenseIndex m_padding_top;
158 const DenseIndex m_padding_bottom;
159 const DenseIndex m_padding_left;
160 const DenseIndex m_padding_right;
161 const PaddingType m_padding_type;
162 const Scalar m_padding_value;
163};
164
165
166// Eval as rvalue
167template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols, typename ArgType, typename Device>
168struct TensorEvaluator<const TensorVolumePatchOp<Planes, Rows, Cols, ArgType>, Device>
169{
171 typedef typename XprType::Index Index;
172 static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
173 static const int NumDims = NumInputDims + 1;
174 typedef DSizes<Index, NumDims> Dimensions;
175 typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar;
176 typedef typename XprType::CoeffReturnType CoeffReturnType;
177 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
178 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
179 typedef StorageMemory<CoeffReturnType, Device> Storage;
180 typedef typename Storage::Type EvaluatorPointerType;
181
182 enum {
183 IsAligned = false,
184 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
185 BlockAccess = false,
186 PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess,
187 Layout = TensorEvaluator<ArgType, Device>::Layout,
188 CoordAccess = false,
189 RawAccess = false
190 };
191
192 //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
193 typedef internal::TensorBlockNotImplemented TensorBlock;
194 //===--------------------------------------------------------------------===//
195
196 EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) :
197 m_impl(op.expression(), device)
198 {
199 EIGEN_STATIC_ASSERT((NumDims >= 5), YOU_MADE_A_PROGRAMMING_MISTAKE);
200
201 m_paddingValue = op.padding_value();
202
203 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
204
205 // Cache a few variables.
206 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
207 m_inputDepth = input_dims[0];
208 m_inputPlanes = input_dims[1];
209 m_inputRows = input_dims[2];
210 m_inputCols = input_dims[3];
211 } else {
212 m_inputDepth = input_dims[NumInputDims-1];
213 m_inputPlanes = input_dims[NumInputDims-2];
214 m_inputRows = input_dims[NumInputDims-3];
215 m_inputCols = input_dims[NumInputDims-4];
216 }
217
218 m_plane_strides = op.plane_strides();
219 m_row_strides = op.row_strides();
220 m_col_strides = op.col_strides();
221
222 // Input strides and effective input/patch size
223 m_in_plane_strides = op.in_plane_strides();
224 m_in_row_strides = op.in_row_strides();
225 m_in_col_strides = op.in_col_strides();
226 m_plane_inflate_strides = op.plane_inflate_strides();
227 m_row_inflate_strides = op.row_inflate_strides();
228 m_col_inflate_strides = op.col_inflate_strides();
229
230 // The "effective" spatial size after inflating data with zeros.
231 m_input_planes_eff = (m_inputPlanes - 1) * m_plane_inflate_strides + 1;
232 m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1;
233 m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1;
234 m_patch_planes_eff = op.patch_planes() + (op.patch_planes() - 1) * (m_in_plane_strides - 1);
235 m_patch_rows_eff = op.patch_rows() + (op.patch_rows() - 1) * (m_in_row_strides - 1);
236 m_patch_cols_eff = op.patch_cols() + (op.patch_cols() - 1) * (m_in_col_strides - 1);
237
238 if (op.padding_explicit()) {
239 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));
240 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));
241 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));
242 m_planePaddingTop = op.padding_top_z();
243 m_rowPaddingTop = op.padding_top();
244 m_colPaddingLeft = op.padding_left();
245 } else {
246 // Computing padding from the type
247 switch (op.padding_type()) {
248 case PADDING_VALID:
249 m_outputPlanes = numext::ceil((m_input_planes_eff - m_patch_planes_eff + 1.f) / static_cast<float>(m_plane_strides));
250 m_outputRows = numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides));
251 m_outputCols = numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides));
252 m_planePaddingTop = 0;
253 m_rowPaddingTop = 0;
254 m_colPaddingLeft = 0;
255 break;
256 case PADDING_SAME: {
257 m_outputPlanes = numext::ceil(m_input_planes_eff / static_cast<float>(m_plane_strides));
258 m_outputRows = numext::ceil(m_input_rows_eff / static_cast<float>(m_row_strides));
259 m_outputCols = numext::ceil(m_input_cols_eff / static_cast<float>(m_col_strides));
260 const Index dz = (m_outputPlanes - 1) * m_plane_strides + m_patch_planes_eff - m_input_planes_eff;
261 const Index dy = (m_outputRows - 1) * m_row_strides + m_patch_rows_eff - m_input_rows_eff;
262 const Index dx = (m_outputCols - 1) * m_col_strides + m_patch_cols_eff - m_input_cols_eff;
263 m_planePaddingTop = dz / 2;
264 m_rowPaddingTop = dy / 2;
265 m_colPaddingLeft = dx / 2;
266 break;
267 }
268 default:
269 eigen_assert(false && "unexpected padding");
270 }
271 }
272 eigen_assert(m_outputRows > 0);
273 eigen_assert(m_outputCols > 0);
274 eigen_assert(m_outputPlanes > 0);
275
276 // Dimensions for result of extraction.
277 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
278 // ColMajor
279 // 0: depth
280 // 1: patch_planes
281 // 2: patch_rows
282 // 3: patch_cols
283 // 4: number of patches
284 // 5 and beyond: anything else (such as batch).
285 m_dimensions[0] = input_dims[0];
286 m_dimensions[1] = op.patch_planes();
287 m_dimensions[2] = op.patch_rows();
288 m_dimensions[3] = op.patch_cols();
289 m_dimensions[4] = m_outputPlanes * m_outputRows * m_outputCols;
290 for (int i = 5; i < NumDims; ++i) {
291 m_dimensions[i] = input_dims[i-1];
292 }
293 } else {
294 // RowMajor
295 // NumDims-1: depth
296 // NumDims-2: patch_planes
297 // NumDims-3: patch_rows
298 // NumDims-4: patch_cols
299 // NumDims-5: number of patches
300 // NumDims-6 and beyond: anything else (such as batch).
301 m_dimensions[NumDims-1] = input_dims[NumInputDims-1];
302 m_dimensions[NumDims-2] = op.patch_planes();
303 m_dimensions[NumDims-3] = op.patch_rows();
304 m_dimensions[NumDims-4] = op.patch_cols();
305 m_dimensions[NumDims-5] = m_outputPlanes * m_outputRows * m_outputCols;
306 for (int i = NumDims-6; i >= 0; --i) {
307 m_dimensions[i] = input_dims[i];
308 }
309 }
310
311 // Strides for the output tensor.
312 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
313 m_rowStride = m_dimensions[1];
314 m_colStride = m_dimensions[2] * m_rowStride;
315 m_patchStride = m_colStride * m_dimensions[3] * m_dimensions[0];
316 m_otherStride = m_patchStride * m_dimensions[4];
317 } else {
318 m_rowStride = m_dimensions[NumDims-2];
319 m_colStride = m_dimensions[NumDims-3] * m_rowStride;
320 m_patchStride = m_colStride * m_dimensions[NumDims-4] * m_dimensions[NumDims-1];
321 m_otherStride = m_patchStride * m_dimensions[NumDims-5];
322 }
323
324 // Strides for navigating through the input tensor.
325 m_planeInputStride = m_inputDepth;
326 m_rowInputStride = m_inputDepth * m_inputPlanes;
327 m_colInputStride = m_inputDepth * m_inputRows * m_inputPlanes;
328 m_otherInputStride = m_inputDepth * m_inputRows * m_inputCols * m_inputPlanes;
329
330 m_outputPlanesRows = m_outputPlanes * m_outputRows;
331
332 // Fast representations of different variables.
333 m_fastOtherStride = internal::TensorIntDivisor<Index>(m_otherStride);
334
335 m_fastPatchStride = internal::TensorIntDivisor<Index>(m_patchStride);
336 m_fastColStride = internal::TensorIntDivisor<Index>(m_colStride);
337 m_fastRowStride = internal::TensorIntDivisor<Index>(m_rowStride);
338 m_fastInputRowStride = internal::TensorIntDivisor<Index>(m_row_inflate_strides);
339 m_fastInputColStride = internal::TensorIntDivisor<Index>(m_col_inflate_strides);
340 m_fastInputPlaneStride = internal::TensorIntDivisor<Index>(m_plane_inflate_strides);
341 m_fastInputColsEff = internal::TensorIntDivisor<Index>(m_input_cols_eff);
342 m_fastOutputPlanes = internal::TensorIntDivisor<Index>(m_outputPlanes);
343 m_fastOutputPlanesRows = internal::TensorIntDivisor<Index>(m_outputPlanesRows);
344
345 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
346 m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[0]);
347 } else {
348 m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[NumDims-1]);
349 }
350 }
351
352 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; }
353
354 EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType /*data*/) {
355 m_impl.evalSubExprsIfNeeded(NULL);
356 return true;
357 }
358
359 EIGEN_STRONG_INLINE void cleanup() {
360 m_impl.cleanup();
361 }
362
363 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
364 {
365 // Patch index corresponding to the passed in index.
366 const Index patchIndex = index / m_fastPatchStride;
367
368 // Spatial offset within the patch. This has to be translated into 3D
369 // coordinates within the patch.
370 const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth;
371
372 // Batch, etc.
373 const Index otherIndex = (NumDims == 5) ? 0 : index / m_fastOtherStride;
374 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride;
375
376 // Calculate column index in the input original tensor.
377 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
378 const Index colOffset = patchOffset / m_fastColStride;
379 const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
380 const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
381 if (inputCol < 0 || inputCol >= m_input_cols_eff ||
382 ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
383 return Scalar(m_paddingValue);
384 }
385
386 // Calculate row index in the original input tensor.
387 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
388 const Index rowOffset = (patchOffset - colOffset * m_colStride) / m_fastRowStride;
389 const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
390 const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
391 if (inputRow < 0 || inputRow >= m_input_rows_eff ||
392 ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
393 return Scalar(m_paddingValue);
394 }
395
396 // Calculate plane index in the original input tensor.
397 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
398 const Index planeOffset = patchOffset - colOffset * m_colStride - rowOffset * m_rowStride;
399 const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
400 const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
401 if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
402 ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
403 return Scalar(m_paddingValue);
404 }
405
406 const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
407 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
408
409 const Index inputIndex = depth +
410 origInputRow * m_rowInputStride +
411 origInputCol * m_colInputStride +
412 origInputPlane * m_planeInputStride +
413 otherIndex * m_otherInputStride;
414
415 return m_impl.coeff(inputIndex);
416 }
417
418 template<int LoadMode>
419 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
420 {
421 EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
422 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
423
424 if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1 ||
425 m_in_plane_strides != 1 || m_plane_inflate_strides != 1) {
426 return packetWithPossibleZero(index);
427 }
428
429 const Index indices[2] = {index, index + PacketSize - 1};
430 const Index patchIndex = indices[0] / m_fastPatchStride;
431 if (patchIndex != indices[1] / m_fastPatchStride) {
432 return packetWithPossibleZero(index);
433 }
434 const Index otherIndex = (NumDims == 5) ? 0 : indices[0] / m_fastOtherStride;
435 eigen_assert(otherIndex == indices[1] / m_fastOtherStride);
436
437 // Find the offset of the element wrt the location of the first element.
438 const Index patchOffsets[2] = {(indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth,
439 (indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth};
440
441 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (indices[0] - otherIndex * m_otherStride) / m_fastPatchStride;
442 eigen_assert(patch3DIndex == (indices[1] - otherIndex * m_otherStride) / m_fastPatchStride);
443
444 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
445 const Index colOffsets[2] = {
446 patchOffsets[0] / m_fastColStride,
447 patchOffsets[1] / m_fastColStride};
448
449 // Calculate col indices in the original input tensor.
450 const Index inputCols[2] = {
451 colIndex * m_col_strides + colOffsets[0] - m_colPaddingLeft,
452 colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft};
453 if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) {
454 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
455 }
456
457 if (inputCols[0] != inputCols[1]) {
458 return packetWithPossibleZero(index);
459 }
460
461 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
462 const Index rowOffsets[2] = {
463 (patchOffsets[0] - colOffsets[0] * m_colStride) / m_fastRowStride,
464 (patchOffsets[1] - colOffsets[1] * m_colStride) / m_fastRowStride};
465 eigen_assert(rowOffsets[0] <= rowOffsets[1]);
466 // Calculate col indices in the original input tensor.
467 const Index inputRows[2] = {
468 rowIndex * m_row_strides + rowOffsets[0] - m_rowPaddingTop,
469 rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop};
470
471 if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) {
472 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
473 }
474
475 if (inputRows[0] != inputRows[1]) {
476 return packetWithPossibleZero(index);
477 }
478
479 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
480 const Index planeOffsets[2] = {
481 patchOffsets[0] - colOffsets[0] * m_colStride - rowOffsets[0] * m_rowStride,
482 patchOffsets[1] - colOffsets[1] * m_colStride - rowOffsets[1] * m_rowStride};
483 eigen_assert(planeOffsets[0] <= planeOffsets[1]);
484 const Index inputPlanes[2] = {
485 planeIndex * m_plane_strides + planeOffsets[0] - m_planePaddingTop,
486 planeIndex * m_plane_strides + planeOffsets[1] - m_planePaddingTop};
487
488 if (inputPlanes[1] < 0 || inputPlanes[0] >= m_inputPlanes) {
489 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
490 }
491
492 if (inputPlanes[0] >= 0 && inputPlanes[1] < m_inputPlanes) {
493 // no padding
494 const int depth_index = static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
495 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
496 const Index inputIndex = depth +
497 inputRows[0] * m_rowInputStride +
498 inputCols[0] * m_colInputStride +
499 m_planeInputStride * inputPlanes[0] +
500 otherIndex * m_otherInputStride;
501 return m_impl.template packet<Unaligned>(inputIndex);
502 }
503
504 return packetWithPossibleZero(index);
505 }
506
507 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost
508 costPerCoeff(bool vectorized) const {
509 const double compute_cost =
510 10 * TensorOpCost::DivCost<Index>() + 21 * TensorOpCost::MulCost<Index>() +
511 8 * TensorOpCost::AddCost<Index>();
512 return TensorOpCost(0, 0, compute_cost, vectorized, PacketSize);
513 }
514
515 EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; }
516
517 const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
518
519
520 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index planePaddingTop() const { return m_planePaddingTop; }
521 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowPaddingTop() const { return m_rowPaddingTop; }
522 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colPaddingLeft() const { return m_colPaddingLeft; }
523 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outputPlanes() const { return m_outputPlanes; }
524 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outputRows() const { return m_outputRows; }
525 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outputCols() const { return m_outputCols; }
526 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userPlaneStride() const { return m_plane_strides; }
527 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userRowStride() const { return m_row_strides; }
528 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userColStride() const { return m_col_strides; }
529 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userInPlaneStride() const { return m_in_plane_strides; }
530 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userInRowStride() const { return m_in_row_strides; }
531 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index userInColStride() const { return m_in_col_strides; }
532 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index planeInflateStride() const { return m_plane_inflate_strides; }
533 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowInflateStride() const { return m_row_inflate_strides; }
534 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colInflateStride() const { return m_col_inflate_strides; }
535
536#ifdef EIGEN_USE_SYCL
537 // binding placeholder accessors to a command group handler for SYCL
538 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
539 m_impl.bind(cgh);
540 }
541#endif
542 protected:
543 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const
544 {
545 EIGEN_ALIGN_MAX typename internal::remove_const<CoeffReturnType>::type values[PacketSize];
546 EIGEN_UNROLL_LOOP
547 for (int i = 0; i < PacketSize; ++i) {
548 values[i] = coeff(index+i);
549 }
550 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
551 return rslt;
552 }
553
554 Dimensions m_dimensions;
555
556 // Parameters passed to the constructor.
557 Index m_plane_strides;
558 Index m_row_strides;
559 Index m_col_strides;
560
561 Index m_outputPlanes;
562 Index m_outputRows;
563 Index m_outputCols;
564
565 Index m_planePaddingTop;
566 Index m_rowPaddingTop;
567 Index m_colPaddingLeft;
568
569 Index m_in_plane_strides;
570 Index m_in_row_strides;
571 Index m_in_col_strides;
572
573 Index m_plane_inflate_strides;
574 Index m_row_inflate_strides;
575 Index m_col_inflate_strides;
576
577 // Cached input size.
578 Index m_inputDepth;
579 Index m_inputPlanes;
580 Index m_inputRows;
581 Index m_inputCols;
582
583 // Other cached variables.
584 Index m_outputPlanesRows;
585
586 // Effective input/patch post-inflation size.
587 Index m_input_planes_eff;
588 Index m_input_rows_eff;
589 Index m_input_cols_eff;
590 Index m_patch_planes_eff;
591 Index m_patch_rows_eff;
592 Index m_patch_cols_eff;
593
594 // Strides for the output tensor.
595 Index m_otherStride;
596 Index m_patchStride;
597 Index m_rowStride;
598 Index m_colStride;
599
600 // Strides for the input tensor.
601 Index m_planeInputStride;
602 Index m_rowInputStride;
603 Index m_colInputStride;
604 Index m_otherInputStride;
605
606 internal::TensorIntDivisor<Index> m_fastOtherStride;
607 internal::TensorIntDivisor<Index> m_fastPatchStride;
608 internal::TensorIntDivisor<Index> m_fastColStride;
609 internal::TensorIntDivisor<Index> m_fastRowStride;
610 internal::TensorIntDivisor<Index> m_fastInputPlaneStride;
611 internal::TensorIntDivisor<Index> m_fastInputRowStride;
612 internal::TensorIntDivisor<Index> m_fastInputColStride;
613 internal::TensorIntDivisor<Index> m_fastInputColsEff;
614 internal::TensorIntDivisor<Index> m_fastOutputPlanesRows;
615 internal::TensorIntDivisor<Index> m_fastOutputPlanes;
616 internal::TensorIntDivisor<Index> m_fastOutputDepth;
617
618 Scalar m_paddingValue;
619
620 TensorEvaluator<ArgType, Device> m_impl;
621
622
623};
624
625
626} // end namespace Eigen
627
628#endif // EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
The tensor base class.
Definition TensorForwardDeclarations.h:56
Patch extraction specialized for processing of volumetric data. This assumes that the input has a lea...
Definition TensorVolumePatch.h:56
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The tensor evaluator class.
Definition TensorEvaluator.h:27