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>
26 struct traits<TensorVolumePatchOp<Planes, Rows, Cols, XprType> > :
public traits<XprType>
28 typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar;
29 typedef traits<XprType> XprTraits;
30 typedef typename packet_traits<Scalar>::type Packet;
31 typedef typename XprTraits::StorageKind StorageKind;
32 typedef typename XprTraits::Index Index;
33 typedef typename XprType::Nested Nested;
34 typedef typename remove_reference<Nested>::type _Nested;
35 static const int NumDimensions = XprTraits::NumDimensions + 1;
36 static const int Layout = XprTraits::Layout;
39 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
40 struct eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType>,
Eigen::Dense>
42 typedef const TensorVolumePatchOp<Planes, Rows, Cols, XprType>& type;
45 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
46 struct nested<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, 1, typename eval<TensorVolumePatchOp<Planes, Rows, Cols, XprType> >::type>
48 typedef TensorVolumePatchOp<Planes, Rows, Cols, XprType> type;
53 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
54 class TensorVolumePatchOp :
public TensorBase<TensorVolumePatchOp<Planes, Rows, Cols, XprType>, ReadOnlyAccessors>
57 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Scalar Scalar;
58 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Packet Packet;
59 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
60 typedef typename XprType::CoeffReturnType CoeffReturnType;
61 typedef typename XprType::PacketReturnType PacketReturnType;
62 typedef typename Eigen::internal::nested<TensorVolumePatchOp>::type Nested;
63 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::StorageKind StorageKind;
64 typedef typename Eigen::internal::traits<TensorVolumePatchOp>::Index Index;
66 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(
const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols,
67 DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides,
68 DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides,
69 DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides,
70 PaddingType padding_type, Scalar padding_value)
71 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
72 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
73 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
74 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
75 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),
76 m_padding_type(padding_type), m_padding_value(padding_value) {}
78 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorVolumePatchOp(
const XprType& expr, DenseIndex patch_planes, DenseIndex patch_rows, DenseIndex patch_cols,
79 DenseIndex plane_strides, DenseIndex row_strides, DenseIndex col_strides,
80 DenseIndex in_plane_strides, DenseIndex in_row_strides, DenseIndex in_col_strides,
81 DenseIndex plane_inflate_strides, DenseIndex row_inflate_strides, DenseIndex col_inflate_strides,
82 DenseIndex padding_top_z, DenseIndex padding_bottom_z,
83 DenseIndex padding_top, DenseIndex padding_bottom,
84 DenseIndex padding_left, DenseIndex padding_right,
86 : m_xpr(expr), m_patch_planes(patch_planes), m_patch_rows(patch_rows), m_patch_cols(patch_cols),
87 m_plane_strides(plane_strides), m_row_strides(row_strides), m_col_strides(col_strides),
88 m_in_plane_strides(in_plane_strides), m_in_row_strides(in_row_strides), m_in_col_strides(in_col_strides),
89 m_plane_inflate_strides(plane_inflate_strides), m_row_inflate_strides(row_inflate_strides), m_col_inflate_strides(col_inflate_strides),
90 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),
91 m_padding_left(padding_left), m_padding_right(padding_right),
92 m_padding_type(PADDING_VALID), m_padding_value(padding_value) {}
95 DenseIndex patch_planes()
const {
return m_patch_planes; }
97 DenseIndex patch_rows()
const {
return m_patch_rows; }
99 DenseIndex patch_cols()
const {
return m_patch_cols; }
101 DenseIndex plane_strides()
const {
return m_plane_strides; }
103 DenseIndex row_strides()
const {
return m_row_strides; }
105 DenseIndex col_strides()
const {
return m_col_strides; }
107 DenseIndex in_plane_strides()
const {
return m_in_plane_strides; }
109 DenseIndex in_row_strides()
const {
return m_in_row_strides; }
111 DenseIndex in_col_strides()
const {
return m_in_col_strides; }
113 DenseIndex plane_inflate_strides()
const {
return m_plane_inflate_strides; }
115 DenseIndex row_inflate_strides()
const {
return m_row_inflate_strides; }
117 DenseIndex col_inflate_strides()
const {
return m_col_inflate_strides; }
119 bool padding_explicit()
const {
return m_padding_explicit; }
121 DenseIndex padding_top_z()
const {
return m_padding_top_z; }
123 DenseIndex padding_bottom_z()
const {
return m_padding_bottom_z; }
125 DenseIndex padding_top()
const {
return m_padding_top; }
127 DenseIndex padding_bottom()
const {
return m_padding_bottom; }
129 DenseIndex padding_left()
const {
return m_padding_left; }
131 DenseIndex padding_right()
const {
return m_padding_right; }
133 PaddingType padding_type()
const {
return m_padding_type; }
135 Scalar padding_value()
const {
return m_padding_value; }
138 const typename internal::remove_all<typename XprType::Nested>::type&
139 expression()
const {
return m_xpr; }
142 typename XprType::Nested m_xpr;
143 const DenseIndex m_patch_planes;
144 const DenseIndex m_patch_rows;
145 const DenseIndex m_patch_cols;
146 const DenseIndex m_plane_strides;
147 const DenseIndex m_row_strides;
148 const DenseIndex m_col_strides;
149 const DenseIndex m_in_plane_strides;
150 const DenseIndex m_in_row_strides;
151 const DenseIndex m_in_col_strides;
152 const DenseIndex m_plane_inflate_strides;
153 const DenseIndex m_row_inflate_strides;
154 const DenseIndex m_col_inflate_strides;
155 const bool m_padding_explicit;
156 const DenseIndex m_padding_top_z;
157 const DenseIndex m_padding_bottom_z;
158 const DenseIndex m_padding_top;
159 const DenseIndex m_padding_bottom;
160 const DenseIndex m_padding_left;
161 const DenseIndex m_padding_right;
162 const PaddingType m_padding_type;
163 const Scalar m_padding_value;
168 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename ArgType,
typename Device>
169 struct TensorEvaluator<const TensorVolumePatchOp<Planes, Rows, Cols, ArgType>, Device>
171 typedef TensorVolumePatchOp<Planes, Rows, Cols, ArgType> XprType;
172 typedef typename XprType::Index Index;
173 static const int NumInputDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
174 static const int NumDims = NumInputDims + 1;
175 typedef DSizes<Index, NumDims> Dimensions;
176 typedef typename internal::remove_const<typename XprType::Scalar>::type Scalar;
180 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
182 Layout = TensorEvaluator<ArgType, Device>::Layout,
183 CoordAccess = NumDims == 6,
186 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(
const XprType& op,
const Device& device)
187 : m_impl(op.expression(), device)
189 EIGEN_STATIC_ASSERT(NumDims >= 5, YOU_MADE_A_PROGRAMMING_MISTAKE);
191 m_paddingValue = op.padding_value();
193 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
196 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
197 m_inputDepth = input_dims[0];
198 m_inputPlanes = input_dims[1];
199 m_inputRows = input_dims[2];
200 m_inputCols = input_dims[3];
202 m_inputDepth = input_dims[NumInputDims-1];
203 m_inputPlanes = input_dims[NumInputDims-2];
204 m_inputRows = input_dims[NumInputDims-3];
205 m_inputCols = input_dims[NumInputDims-4];
208 m_plane_strides = op.plane_strides();
209 m_row_strides = op.row_strides();
210 m_col_strides = op.col_strides();
213 m_in_plane_strides = op.in_plane_strides();
214 m_in_row_strides = op.in_row_strides();
215 m_in_col_strides = op.in_col_strides();
216 m_plane_inflate_strides = op.plane_inflate_strides();
217 m_row_inflate_strides = op.row_inflate_strides();
218 m_col_inflate_strides = op.col_inflate_strides();
221 m_input_planes_eff = (m_inputPlanes - 1) * m_plane_inflate_strides + 1;
222 m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1;
223 m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1;
224 m_patch_planes_eff = op.patch_planes() + (op.patch_planes() - 1) * (m_in_plane_strides - 1);
225 m_patch_rows_eff = op.patch_rows() + (op.patch_rows() - 1) * (m_in_row_strides - 1);
226 m_patch_cols_eff = op.patch_cols() + (op.patch_cols() - 1) * (m_in_col_strides - 1);
228 if (op.padding_explicit()) {
229 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));
230 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));
231 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));
232 m_planePaddingTop = op.padding_top_z();
233 m_rowPaddingTop = op.padding_top();
234 m_colPaddingLeft = op.padding_left();
237 switch (op.padding_type()) {
239 m_outputPlanes = numext::ceil((m_input_planes_eff - m_patch_planes_eff + 1.f) / static_cast<float>(m_plane_strides));
240 m_outputRows = numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.f) / static_cast<float>(m_row_strides));
241 m_outputCols = numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.f) / static_cast<float>(m_col_strides));
242 m_planePaddingTop = 0;
244 m_colPaddingLeft = 0;
247 m_outputPlanes = numext::ceil(m_input_planes_eff / static_cast<float>(m_plane_strides));
248 m_outputRows = numext::ceil(m_input_rows_eff / static_cast<float>(m_row_strides));
249 m_outputCols = numext::ceil(m_input_cols_eff / static_cast<float>(m_col_strides));
250 const Index dz = m_outputPlanes * m_plane_strides + m_patch_planes_eff - 1 - m_input_planes_eff;
251 const Index dy = m_outputRows * m_row_strides + m_patch_rows_eff - 1 - m_input_rows_eff;
252 const Index dx = m_outputCols * m_col_strides + m_patch_cols_eff - 1 - m_input_cols_eff;
253 m_planePaddingTop = dz - dz / 2;
254 m_rowPaddingTop = dy - dy / 2;
255 m_colPaddingLeft = dx - dx / 2;
259 eigen_assert(
false &&
"unexpected padding");
262 eigen_assert(m_outputRows > 0);
263 eigen_assert(m_outputCols > 0);
264 eigen_assert(m_outputPlanes > 0);
267 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
275 m_dimensions[0] = input_dims[0];
276 m_dimensions[1] = op.patch_planes();
277 m_dimensions[2] = op.patch_rows();
278 m_dimensions[3] = op.patch_cols();
279 m_dimensions[4] = m_outputPlanes * m_outputRows * m_outputCols;
280 for (
int i = 5; i < NumDims; ++i) {
281 m_dimensions[i] = input_dims[i-1];
291 m_dimensions[NumDims-1] = input_dims[NumInputDims-1];
292 m_dimensions[NumDims-2] = op.patch_planes();
293 m_dimensions[NumDims-3] = op.patch_rows();
294 m_dimensions[NumDims-4] = op.patch_cols();
295 m_dimensions[NumDims-5] = m_outputPlanes * m_outputRows * m_outputCols;
296 for (
int i = NumDims-6; i >= 0; --i) {
297 m_dimensions[i] = input_dims[i];
302 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
303 m_rowStride = m_dimensions[1];
304 m_colStride = m_dimensions[2] * m_rowStride;
305 m_patchStride = m_colStride * m_dimensions[3] * m_dimensions[0];
306 m_otherStride = m_patchStride * m_dimensions[4];
308 m_rowStride = m_dimensions[NumDims-2];
309 m_colStride = m_dimensions[NumDims-3] * m_rowStride;
310 m_patchStride = m_colStride * m_dimensions[NumDims-4] * m_dimensions[NumDims-1];
311 m_otherStride = m_patchStride * m_dimensions[NumDims-5];
315 m_planeInputStride = m_inputDepth;
316 m_rowInputStride = m_inputDepth * m_inputPlanes;
317 m_colInputStride = m_inputDepth * m_inputRows * m_inputPlanes;
318 m_otherInputStride = m_inputDepth * m_inputRows * m_inputCols * m_inputPlanes;
320 m_outputPlanesRows = m_outputPlanes * m_outputRows;
323 m_fastOtherStride = internal::TensorIntDivisor<Index>(m_otherStride);
324 m_fastPatchStride = internal::TensorIntDivisor<Index>(m_patchStride);
325 m_fastColStride = internal::TensorIntDivisor<Index>(m_colStride);
326 m_fastRowStride = internal::TensorIntDivisor<Index>(m_rowStride);
327 m_fastInputRowStride = internal::TensorIntDivisor<Index>(m_row_inflate_strides);
328 m_fastInputColStride = internal::TensorIntDivisor<Index>(m_col_inflate_strides);
329 m_fastInputPlaneStride = internal::TensorIntDivisor<Index>(m_plane_inflate_strides);
330 m_fastInputColsEff = internal::TensorIntDivisor<Index>(m_input_cols_eff);
331 m_fastOutputPlanes = internal::TensorIntDivisor<Index>(m_outputPlanes);
332 m_fastOutputPlanesRows = internal::TensorIntDivisor<Index>(m_outputPlanesRows);
334 if (static_cast<int>(Layout) ==
static_cast<int>(ColMajor)) {
335 m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[0]);
337 m_fastOutputDepth = internal::TensorIntDivisor<Index>(m_dimensions[NumDims-1]);
341 typedef typename XprType::CoeffReturnType CoeffReturnType;
342 typedef typename XprType::PacketReturnType PacketReturnType;
344 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
346 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(Scalar* ) {
347 m_impl.evalSubExprsIfNeeded(NULL);
351 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
355 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const
358 const Index patchIndex = index / m_fastPatchStride;
362 const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth;
365 const Index otherIndex = (NumDims == 5) ? 0 : index / m_fastOtherStride;
366 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride;
369 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
370 const Index colOffset = patchOffset / m_fastColStride;
371 const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
372 const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
373 if (inputCol < 0 || inputCol >= m_input_cols_eff ||
374 ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
375 return Scalar(m_paddingValue);
379 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
380 const Index rowOffset = (patchOffset - colOffset * m_colStride) / m_fastRowStride;
381 const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
382 const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
383 if (inputRow < 0 || inputRow >= m_input_rows_eff ||
384 ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
385 return Scalar(m_paddingValue);
389 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
390 const Index planeOffset = patchOffset - colOffset * m_colStride - rowOffset * m_rowStride;
391 const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
392 const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
393 if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
394 ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
395 return Scalar(m_paddingValue);
398 const int depth_index =
static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
399 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
401 const Index inputIndex = depth +
402 origInputRow * m_rowInputStride +
403 origInputCol * m_colInputStride +
404 origInputPlane * m_planeInputStride +
405 otherIndex * m_otherInputStride;
407 return m_impl.coeff(inputIndex);
410 template<
int LoadMode>
411 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
413 const Index packetSize = internal::unpacket_traits<PacketReturnType>::size;
414 EIGEN_STATIC_ASSERT(packetSize > 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
415 eigen_assert(index+packetSize-1 < dimensions().TotalSize());
417 if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1 ||
418 m_in_plane_strides != 1 || m_plane_inflate_strides != 1) {
419 return packetWithPossibleZero(index);
422 const Index indices[2] = {index, index + packetSize - 1};
423 const Index patchIndex = indices[0] / m_fastPatchStride;
424 if (patchIndex != indices[1] / m_fastPatchStride) {
425 return packetWithPossibleZero(index);
427 const Index otherIndex = (NumDims == 5) ? 0 : indices[0] / m_fastOtherStride;
428 eigen_assert(otherIndex == indices[1] / m_fastOtherStride);
431 const Index patchOffsets[2] = {(indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth,
432 (indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth};
434 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (indices[0] - otherIndex * m_otherStride) / m_fastPatchStride;
435 eigen_assert(patch3DIndex == (indices[1] - otherIndex * m_otherStride) / m_fastPatchStride);
437 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
438 const Index colOffsets[2] = {
439 patchOffsets[0] / m_fastColStride,
440 patchOffsets[1] / m_fastColStride};
443 const Index inputCols[2] = {
444 colIndex * m_col_strides + colOffsets[0] - m_colPaddingLeft,
445 colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft};
446 if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) {
447 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
450 if (inputCols[0] != inputCols[1]) {
451 return packetWithPossibleZero(index);
454 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
455 const Index rowOffsets[2] = {
456 (patchOffsets[0] - colOffsets[0] * m_colStride) / m_fastRowStride,
457 (patchOffsets[1] - colOffsets[1] * m_colStride) / m_fastRowStride};
458 eigen_assert(rowOffsets[0] <= rowOffsets[1]);
460 const Index inputRows[2] = {
461 rowIndex * m_row_strides + rowOffsets[0] - m_rowPaddingTop,
462 rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop};
464 if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) {
465 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
468 if (inputRows[0] != inputRows[1]) {
469 return packetWithPossibleZero(index);
472 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
473 const Index planeOffsets[2] = {
474 patchOffsets[0] - colOffsets[0] * m_colStride - rowOffsets[0] * m_rowStride,
475 patchOffsets[1] - colOffsets[1] * m_colStride - rowOffsets[1] * m_rowStride};
476 eigen_assert(planeOffsets[0] <= planeOffsets[1]);
477 const Index inputPlanes[2] = {
478 planeIndex * m_plane_strides + planeOffsets[0] - m_planePaddingTop,
479 planeIndex * m_plane_strides + planeOffsets[1] - m_planePaddingTop};
481 if (inputPlanes[1] < 0 || inputPlanes[0] >= m_inputPlanes) {
482 return internal::pset1<PacketReturnType>(Scalar(m_paddingValue));
485 if (inputPlanes[0] >= 0 && inputPlanes[1] < m_inputPlanes) {
487 const int depth_index =
static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
488 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
489 const Index inputIndex = depth +
490 inputRows[0] * m_rowInputStride +
491 inputCols[0] * m_colInputStride +
492 m_planeInputStride * inputPlanes[0] +
493 otherIndex * m_otherInputStride;
494 return m_impl.template packet<Unaligned>(inputIndex);
497 return packetWithPossibleZero(index);
500 EIGEN_DEVICE_FUNC Scalar* data()
const {
return NULL; }
502 const TensorEvaluator<ArgType, Device>& impl()
const {
return m_impl; }
504 Index planePaddingTop()
const {
return m_planePaddingTop; }
505 Index rowPaddingTop()
const {
return m_rowPaddingTop; }
506 Index colPaddingLeft()
const {
return m_colPaddingLeft; }
507 Index outputPlanes()
const {
return m_outputPlanes; }
508 Index outputRows()
const {
return m_outputRows; }
509 Index outputCols()
const {
return m_outputCols; }
510 Index userPlaneStride()
const {
return m_plane_strides; }
511 Index userRowStride()
const {
return m_row_strides; }
512 Index userColStride()
const {
return m_col_strides; }
513 Index userInPlaneStride()
const {
return m_in_plane_strides; }
514 Index userInRowStride()
const {
return m_in_row_strides; }
515 Index userInColStride()
const {
return m_in_col_strides; }
516 Index planeInflateStride()
const {
return m_plane_inflate_strides; }
517 Index rowInflateStride()
const {
return m_row_inflate_strides; }
518 Index colInflateStride()
const {
return m_col_inflate_strides; }
520 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(
const array<Index, NumDims>& coords)
const
526 const Index patch3DIndex = coords[
static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 4 : 1];
527 const Index colOffset = coords[
static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 3 : 2];
528 const Index rowOffset= coords[
static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 2 : 3];
529 const Index planeOffset = coords[
static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 1 : 4];
531 array<Index, NumDims-1> inputCoords;
533 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
534 const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
535 const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
536 if (inputCol < 0 || inputCol >= m_input_cols_eff ||
537 ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
538 return Scalar(m_paddingValue);
541 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
542 const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
543 const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
544 if (inputRow < 0 || inputRow >= m_input_rows_eff ||
545 ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
546 return Scalar(m_paddingValue);
549 const Index planeIndex = patch3DIndex - colIndex * m_outputPlanesRows - rowIndex * m_outputRows;
550 const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
551 const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
552 if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
553 ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
554 return Scalar(m_paddingValue);
557 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
558 inputCoords[0] = coords[0];
559 inputCoords[1] = origInputPlane;
560 inputCoords[2] = origInputRow;
561 inputCoords[3] = origInputCol;
562 inputCoords[4] = coords[5];
564 inputCoords[4] = coords[5];
565 inputCoords[3] = origInputPlane;
566 inputCoords[2] = origInputRow;
567 inputCoords[1] = origInputCol;
568 inputCoords[0] = coords[0];
570 if (TensorEvaluator<ArgType, Device>::CoordAccess) {
571 return m_impl.coeff(inputCoords);
574 if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
576 inputCoords[4] * m_otherInputStride +
577 inputCoords[3] * m_colInputStride +
578 inputCoords[2] * m_rowInputStride +
579 inputCoords[1] * m_planeInputStride +
583 inputCoords[0] * m_otherInputStride +
584 inputCoords[1] * m_colInputStride +
585 inputCoords[2] * m_rowInputStride +
586 inputCoords[3] * m_planeInputStride +
589 return m_impl.coeff(inputIndex);
594 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index)
const
596 const int packetSize = internal::unpacket_traits<PacketReturnType>::size;
597 EIGEN_ALIGN_MAX
typename internal::remove_const<CoeffReturnType>::type values[packetSize];
598 for (
int i = 0; i < packetSize; ++i) {
599 values[i] = coeff(index+i);
601 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
605 Dimensions m_dimensions;
608 Index m_plane_strides;
612 Index m_outputPlanes;
616 Index m_planePaddingTop;
617 Index m_rowPaddingTop;
618 Index m_colPaddingLeft;
620 Index m_in_plane_strides;
621 Index m_in_row_strides;
622 Index m_in_col_strides;
624 Index m_plane_inflate_strides;
625 Index m_row_inflate_strides;
626 Index m_col_inflate_strides;
635 Index m_outputPlanesRows;
638 Index m_input_planes_eff;
639 Index m_input_rows_eff;
640 Index m_input_cols_eff;
641 Index m_patch_planes_eff;
642 Index m_patch_rows_eff;
643 Index m_patch_cols_eff;
652 Index m_planeInputStride;
653 Index m_rowInputStride;
654 Index m_colInputStride;
655 Index m_otherInputStride;
657 internal::TensorIntDivisor<Index> m_fastOtherStride;
658 internal::TensorIntDivisor<Index> m_fastPatchStride;
659 internal::TensorIntDivisor<Index> m_fastColStride;
660 internal::TensorIntDivisor<Index> m_fastRowStride;
661 internal::TensorIntDivisor<Index> m_fastInputPlaneStride;
662 internal::TensorIntDivisor<Index> m_fastInputRowStride;
663 internal::TensorIntDivisor<Index> m_fastInputColStride;
664 internal::TensorIntDivisor<Index> m_fastInputColsEff;
665 internal::TensorIntDivisor<Index> m_fastOutputPlanesRows;
666 internal::TensorIntDivisor<Index> m_fastOutputPlanes;
667 internal::TensorIntDivisor<Index> m_fastOutputDepth;
669 Scalar m_paddingValue;
671 TensorEvaluator<ArgType, Device> m_impl;
677 #endif // EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13