4 #ifndef EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
5 #define EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H
26 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
33 typedef typename XprType::Nested
Nested;
35 static const int NumDimensions = XprTraits::NumDimensions + 1;
36 static const int Layout = XprTraits::Layout;
41 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
47 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
55 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename XprType>
168 template<DenseIndex Planes, DenseIndex Rows, DenseIndex Cols,
typename ArgType,
typename Device>
174 static const int NumDims = NumInputDims + 1;
198 m_impl(op.expression(), device)
208 m_inputDepth = input_dims[0];
209 m_inputPlanes = input_dims[1];
210 m_inputRows = input_dims[2];
211 m_inputCols = input_dims[3];
213 m_inputDepth = input_dims[NumInputDims-1];
214 m_inputPlanes = input_dims[NumInputDims-2];
215 m_inputRows = input_dims[NumInputDims-3];
216 m_inputCols = input_dims[NumInputDims-4];
232 m_input_planes_eff = (m_inputPlanes - 1) * m_plane_inflate_strides + 1;
233 m_input_rows_eff = (m_inputRows - 1) * m_row_inflate_strides + 1;
234 m_input_cols_eff = (m_inputCols - 1) * m_col_inflate_strides + 1;
250 m_outputPlanes =
numext::ceil((m_input_planes_eff - m_patch_planes_eff + 1.
f) /
static_cast<float>(m_plane_strides));
251 m_outputRows =
numext::ceil((m_input_rows_eff - m_patch_rows_eff + 1.
f) /
static_cast<float>(m_row_strides));
252 m_outputCols =
numext::ceil((m_input_cols_eff - m_patch_cols_eff + 1.
f) /
static_cast<float>(m_col_strides));
253 m_planePaddingTop = 0;
255 m_colPaddingLeft = 0;
258 m_outputPlanes =
numext::ceil(m_input_planes_eff /
static_cast<float>(m_plane_strides));
259 m_outputRows =
numext::ceil(m_input_rows_eff /
static_cast<float>(m_row_strides));
260 m_outputCols =
numext::ceil(m_input_cols_eff /
static_cast<float>(m_col_strides));
261 const Index dz = (m_outputPlanes - 1) * m_plane_strides + m_patch_planes_eff - m_input_planes_eff;
262 const Index dy = (m_outputRows - 1) * m_row_strides + m_patch_rows_eff - m_input_rows_eff;
263 const Index dx = (m_outputCols - 1) * m_col_strides + m_patch_cols_eff - m_input_cols_eff;
264 m_planePaddingTop = dz / 2;
265 m_rowPaddingTop = dy / 2;
266 m_colPaddingLeft = dx / 2;
286 m_dimensions[0] = input_dims[0];
290 m_dimensions[4] = m_outputPlanes * m_outputRows * m_outputCols;
291 for (
int i = 5;
i < NumDims; ++
i) {
292 m_dimensions[
i] = input_dims[
i-1];
302 m_dimensions[NumDims-1] = input_dims[NumInputDims-1];
306 m_dimensions[NumDims-5] = m_outputPlanes * m_outputRows * m_outputCols;
307 for (
int i = NumDims-6;
i >= 0; --
i) {
308 m_dimensions[
i] = input_dims[
i];
314 m_rowStride = m_dimensions[1];
315 m_colStride = m_dimensions[2] * m_rowStride;
316 m_patchStride = m_colStride * m_dimensions[3] * m_dimensions[0];
317 m_otherStride = m_patchStride * m_dimensions[4];
319 m_rowStride = m_dimensions[NumDims-2];
320 m_colStride = m_dimensions[NumDims-3] * m_rowStride;
321 m_patchStride = m_colStride * m_dimensions[NumDims-4] * m_dimensions[NumDims-1];
322 m_otherStride = m_patchStride * m_dimensions[NumDims-5];
326 m_planeInputStride = m_inputDepth;
327 m_rowInputStride = m_inputDepth * m_inputPlanes;
328 m_colInputStride = m_inputDepth * m_inputRows * m_inputPlanes;
329 m_otherInputStride = m_inputDepth * m_inputRows * m_inputCols * m_inputPlanes;
331 m_outputPlanesRows = m_outputPlanes * m_outputRows;
356 m_impl.evalSubExprsIfNeeded(
NULL);
367 const Index patchIndex = index / m_fastPatchStride;
371 const Index patchOffset = (index - patchIndex * m_patchStride) / m_fastOutputDepth;
374 const Index otherIndex = (NumDims == 5) ? 0 : index / m_fastOtherStride;
375 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (index - otherIndex * m_otherStride) / m_fastPatchStride;
378 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
379 const Index colOffset = patchOffset / m_fastColStride;
380 const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
381 const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
382 if (inputCol < 0 || inputCol >= m_input_cols_eff ||
383 ((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
384 return Scalar(m_paddingValue);
388 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
389 const Index rowOffset = (patchOffset - colOffset * m_colStride) / m_fastRowStride;
390 const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
391 const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
392 if (inputRow < 0 || inputRow >= m_input_rows_eff ||
393 ((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
394 return Scalar(m_paddingValue);
398 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
399 const Index planeOffset = patchOffset - colOffset * m_colStride - rowOffset * m_rowStride;
400 const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
401 const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
402 if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
403 ((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
404 return Scalar(m_paddingValue);
407 const int depth_index =
static_cast<int>(
Layout) ==
static_cast<int>(
ColMajor) ? 0 : NumDims - 1;
408 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
411 origInputRow * m_rowInputStride +
412 origInputCol * m_colInputStride +
413 origInputPlane * m_planeInputStride +
414 otherIndex * m_otherInputStride;
416 return m_impl.coeff(inputIndex);
419 template<
int LoadMode>
425 if (m_in_row_strides != 1 || m_in_col_strides != 1 || m_row_inflate_strides != 1 || m_col_inflate_strides != 1 ||
426 m_in_plane_strides != 1 || m_plane_inflate_strides != 1) {
427 return packetWithPossibleZero(index);
431 const Index patchIndex =
indices[0] / m_fastPatchStride;
432 if (patchIndex !=
indices[1] / m_fastPatchStride) {
433 return packetWithPossibleZero(index);
435 const Index otherIndex = (NumDims == 5) ? 0 :
indices[0] / m_fastOtherStride;
439 const Index patchOffsets[2] = {(
indices[0] - patchIndex * m_patchStride) / m_fastOutputDepth,
440 (
indices[1] - patchIndex * m_patchStride) / m_fastOutputDepth};
442 const Index patch3DIndex = (NumDims == 5) ? patchIndex : (
indices[0] - otherIndex * m_otherStride) / m_fastPatchStride;
443 eigen_assert(patch3DIndex == (
indices[1] - otherIndex * m_otherStride) / m_fastPatchStride);
445 const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
446 const Index colOffsets[2] = {
447 patchOffsets[0] / m_fastColStride,
448 patchOffsets[1] / m_fastColStride};
451 const Index inputCols[2] = {
452 colIndex * m_col_strides + colOffsets[0] - m_colPaddingLeft,
453 colIndex * m_col_strides + colOffsets[1] - m_colPaddingLeft};
454 if (inputCols[1] < 0 || inputCols[0] >= m_inputCols) {
455 return internal::pset1<PacketReturnType>(
Scalar(m_paddingValue));
458 if (inputCols[0] != inputCols[1]) {
459 return packetWithPossibleZero(index);
462 const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
463 const Index rowOffsets[2] = {
464 (patchOffsets[0] - colOffsets[0] * m_colStride) / m_fastRowStride,
465 (patchOffsets[1] - colOffsets[1] * m_colStride) / m_fastRowStride};
468 const Index inputRows[2] = {
469 rowIndex * m_row_strides + rowOffsets[0] - m_rowPaddingTop,
470 rowIndex * m_row_strides + rowOffsets[1] - m_rowPaddingTop};
472 if (inputRows[1] < 0 || inputRows[0] >= m_inputRows) {
473 return internal::pset1<PacketReturnType>(
Scalar(m_paddingValue));
476 if (inputRows[0] != inputRows[1]) {
477 return packetWithPossibleZero(index);
480 const Index planeIndex = (patch3DIndex - m_outputPlanes * (colIndex * m_outputRows + rowIndex));
481 const Index planeOffsets[2] = {
482 patchOffsets[0] - colOffsets[0] * m_colStride - rowOffsets[0] * m_rowStride,
483 patchOffsets[1] - colOffsets[1] * m_colStride - rowOffsets[1] * m_rowStride};
485 const Index inputPlanes[2] = {
486 planeIndex * m_plane_strides + planeOffsets[0] - m_planePaddingTop,
487 planeIndex * m_plane_strides + planeOffsets[1] - m_planePaddingTop};
489 if (inputPlanes[1] < 0 || inputPlanes[0] >= m_inputPlanes) {
490 return internal::pset1<PacketReturnType>(
Scalar(m_paddingValue));
493 if (inputPlanes[0] >= 0 && inputPlanes[1] < m_inputPlanes) {
495 const int depth_index =
static_cast<int>(
Layout) ==
static_cast<int>(
ColMajor) ? 0 : NumDims - 1;
496 const Index depth = index - (index / m_fastOutputDepth) * m_dimensions[depth_index];
498 inputRows[0] * m_rowInputStride +
499 inputCols[0] * m_colInputStride +
500 m_planeInputStride * inputPlanes[0] +
501 otherIndex * m_otherInputStride;
502 return m_impl.template packet<Unaligned>(inputIndex);
505 return packetWithPossibleZero(index);
510 const double compute_cost =
511 10 * TensorOpCost::DivCost<Index>() + 21 * TensorOpCost::MulCost<Index>() +
512 8 * TensorOpCost::AddCost<Index>();
537 #ifdef EIGEN_USE_SYCL
629 #endif // EIGEN_CXX11_TENSOR_TENSOR_VOLUME_PATCH_H