Deleted the coordinate based evaluation of tensor expressions, since it's hardly ever used and started to cause some issues with some versions of xcode.

This commit is contained in:
Benoit Steiner 2016-02-22 15:29:41 -08:00
parent 6270d851e3
commit 72d2cf642e
4 changed files with 5 additions and 199 deletions

View File

@ -167,7 +167,7 @@ struct TensorEvaluator<const TensorImagePatchOp<Rows, Cols, ArgType>, Device>
IsAligned = false,
PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
Layout = TensorEvaluator<ArgType, Device>::Layout,
CoordAccess = NumDims == 5,
CoordAccess = false,
RawAccess = false
};
@ -437,59 +437,6 @@ struct TensorEvaluator<const TensorImagePatchOp<Rows, Cols, ArgType>, Device>
Index rowInflateStride() const { return m_row_inflate_strides; }
Index colInflateStride() const { return m_col_inflate_strides; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(const array<Index, NumDims>& coords) const
{
// Location of the first element of the patch.
// ColMajor
// 0: d, 1: patch_rows, 2: patch_cols, 3: number of patches, 4: number of batches
// RowMajor
// 0: number of batches, 1: number of patches, 2: patch_cols , 3: patch_rows, 4: d
const Index patch2DIndex = coords[static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 3 : 1];
array<Index, NumDims-1> inputCoords;
Index input_col_idx = patch2DIndex / m_fastInputColsEff;
Index inputCol = input_col_idx + coords[1] * m_in_row_strides - m_rowPaddingTop;
Index inputRow = patch2DIndex - input_col_idx * m_input_cols_eff + coords[2] * m_in_col_strides - m_colPaddingLeft;
const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
inputCoords[0] = coords[0]; // depth
inputCoords[1] = origInputCol;
inputCoords[2] = origInputRow;
inputCoords[3] = coords[4]; // batch
} else {
inputCoords[3] = coords[4]; // depth
inputCoords[2] = origInputCol;
inputCoords[1] = origInputRow;
inputCoords[0] = coords[0]; // batch
}
// If the computed coordinates are outside the original image perimeter, return 0.
if (inputCol < 0 || inputCol >= m_input_cols_eff || inputRow < 0 || inputRow >= m_input_rows_eff ||
((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides)) ||
((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
return Scalar(m_paddingValue);
}
if (TensorEvaluator<ArgType, Device>::CoordAccess) {
return m_impl.coeff(inputCoords);
} else {
Index inputIndex;
if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
inputIndex =
inputCoords[3] * m_patchInputStride +
inputCoords[2] * m_colInputStride +
inputCoords[1] * m_rowInputStride +
inputCoords[0];
} else {
inputIndex =
inputCoords[1] * m_patchInputStride +
inputCoords[2] * m_colInputStride +
inputCoords[3] * m_rowInputStride +
inputCoords[4];
}
return m_impl.coeff(inputIndex);
}
}
protected:
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const
{

View File

@ -318,7 +318,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi
IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/false,
PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
Layout = TensorEvaluator<ArgType, Device>::Layout,
CoordAccess = TensorEvaluator<ArgType, Device>::CoordAccess,
CoordAccess = false,
RawAccess = false
};
@ -457,15 +457,6 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi
}
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(const array<Index, NumDims>& coords)
{
array<Index, NumDims> inputCoords;
for (int i = 0; i < NumDims; ++i) {
inputCoords = coords[i] + this->m_offsets[i];
}
return m_impl.coeff(inputCoords);
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar* data() const {
Scalar* result = m_impl.data();
if (result) {
@ -547,7 +538,7 @@ struct TensorEvaluator<TensorSlicingOp<StartIndices, Sizes, ArgType>, Device>
IsAligned = /*TensorEvaluator<ArgType, Device>::IsAligned*/false,
PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
Layout = TensorEvaluator<ArgType, Device>::Layout,
CoordAccess = TensorEvaluator<ArgType, Device>::CoordAccess,
CoordAccess = false,
RawAccess = false
};
@ -608,15 +599,6 @@ struct TensorEvaluator<TensorSlicingOp<StartIndices, Sizes, ArgType>, Device>
}
}
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(const array<Index, NumDims>& coords)
{
array<Index, NumDims> inputCoords;
for (int i = 0; i < NumDims; ++i) {
inputCoords = coords[i] + this->m_offsets[i];
}
return this->m_impl.coeffRef(inputCoords);
}
};

View File

@ -93,7 +93,7 @@ struct TensorEvaluator<const TensorPatchOp<PatchDim, ArgType>, Device>
IsAligned = false,
PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
Layout = TensorEvaluator<ArgType, Device>::Layout,
CoordAccess = true,
CoordAccess = false,
RawAccess = false
};
@ -248,56 +248,6 @@ struct TensorEvaluator<const TensorPatchOp<PatchDim, ArgType>, Device>
}
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(const array<Index, NumDims>& coords) const
{
Index patch_coord_idx = Layout == ColMajor ? NumDims - 1 : 0;
// Location of the first element of the patch.
const Index patchIndex = coords[patch_coord_idx];
if (TensorEvaluator<ArgType, Device>::CoordAccess) {
array<Index, NumDims-1> inputCoords;
if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
for (int i = NumDims - 2; i > 0; --i) {
const Index patchIdx = patchIndex / m_patchStrides[i];
patchIndex -= patchIdx * m_patchStrides[i];
const Index offsetIdx = coords[i];
inputCoords[i] = coords[i] + patchIdx;
}
} else {
for (int i = 0; i < NumDims - 2; ++i) {
const Index patchIdx = patchIndex / m_patchStrides[i];
patchIndex -= patchIdx * m_patchStrides[i];
const Index offsetIdx = coords[i+1];
inputCoords[i] = coords[i+1] + patchIdx;
}
}
Index coords_idx = Layout == ColMajor ? 0 : NumDims - 1;
inputCoords[0] = (patchIndex + coords[coords_idx]);
return m_impl.coeff(inputCoords);
}
else {
Index inputIndex = 0;
if (Layout == ColMajor) {
for (int i = NumDims - 2; i > 0; --i) {
const Index patchIdx = patchIndex / m_patchStrides[i];
patchIndex -= patchIdx * m_patchStrides[i];
const Index offsetIdx = coords[i];
inputIndex += (patchIdx + offsetIdx) * m_inputStrides[i];
}
} else {
for (int i = 0; i < NumDims - 2; ++i) {
const Index patchIdx = patchIndex / m_patchStrides[i];
patchIndex -= patchIdx * m_patchStrides[i];
const Index offsetIdx = coords[i+1];
inputIndex += (patchIdx + offsetIdx) * m_inputStrides[i];
}
}
Index coords_idx = Layout == ColMajor ? 0 : NumDims - 1;
inputIndex += (patchIndex + coords[coords_idx]);
return m_impl.coeff(inputIndex);
}
}
EIGEN_DEVICE_FUNC Scalar* data() const { return NULL; }
protected:

View File

@ -180,7 +180,7 @@ struct TensorEvaluator<const TensorVolumePatchOp<Planes, Rows, Cols, ArgType>, D
PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
BlockAccess = false,
Layout = TensorEvaluator<ArgType, Device>::Layout,
CoordAccess = NumDims == 6,
CoordAccess = false,
RawAccess = false
};
@ -518,79 +518,6 @@ struct TensorEvaluator<const TensorVolumePatchOp<Planes, Rows, Cols, ArgType>, D
Index rowInflateStride() const { return m_row_inflate_strides; }
Index colInflateStride() const { return m_col_inflate_strides; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(const array<Index, NumDims>& coords) const
{
// ColMajor
// 0: depth, 1: patch_planes, 2: patch_rows, 3: patch_cols, 4: number of patches, 5: batches
// RowMajor
// 0: batches, 1: number of patches, 2: patch_cols , 3: patch_rows, 4: patch_planes, 5: depth
const Index patch3DIndex = coords[static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 4 : 1];
const Index colOffset = coords[static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 3 : 2];
const Index rowOffset= coords[static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 2 : 3];
const Index planeOffset = coords[static_cast<int>(Layout) == static_cast<int>(ColMajor) ? 1 : 4];
array<Index, NumDims-1> inputCoords;
const Index colIndex = patch3DIndex / m_fastOutputPlanesRows;
const Index inputCol = colIndex * m_col_strides + colOffset * m_in_col_strides - m_colPaddingLeft;
const Index origInputCol = (m_col_inflate_strides == 1) ? inputCol : ((inputCol >= 0) ? (inputCol / m_fastInputColStride) : 0);
if (inputCol < 0 || inputCol >= m_input_cols_eff ||
((m_col_inflate_strides != 1) && (inputCol != origInputCol * m_col_inflate_strides))) {
return Scalar(m_paddingValue);
}
const Index rowIndex = (patch3DIndex - colIndex * m_outputPlanesRows) / m_fastOutputPlanes;
const Index inputRow = rowIndex * m_row_strides + rowOffset * m_in_row_strides - m_rowPaddingTop;
const Index origInputRow = (m_row_inflate_strides == 1) ? inputRow : ((inputRow >= 0) ? (inputRow / m_fastInputRowStride) : 0);
if (inputRow < 0 || inputRow >= m_input_rows_eff ||
((m_row_inflate_strides != 1) && (inputRow != origInputRow * m_row_inflate_strides))) {
return Scalar(m_paddingValue);
}
const Index planeIndex = patch3DIndex - colIndex * m_outputPlanesRows - rowIndex * m_outputRows;
const Index inputPlane = planeIndex * m_plane_strides + planeOffset * m_in_plane_strides - m_planePaddingTop;
const Index origInputPlane = (m_plane_inflate_strides == 1) ? inputPlane : ((inputPlane >= 0) ? (inputPlane / m_fastInputPlaneStride) : 0);
if (inputPlane < 0 || inputPlane >= m_input_planes_eff ||
((m_plane_inflate_strides != 1) && (inputPlane != origInputPlane * m_plane_inflate_strides))) {
return Scalar(m_paddingValue);
}
if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
inputCoords[0] = coords[0]; // depth
inputCoords[1] = origInputPlane;
inputCoords[2] = origInputRow;
inputCoords[3] = origInputCol;
inputCoords[4] = coords[5]; // batch
} else {
inputCoords[4] = coords[5]; // depth
inputCoords[3] = origInputPlane;
inputCoords[2] = origInputRow;
inputCoords[1] = origInputCol;
inputCoords[0] = coords[0]; // batch
}
if (TensorEvaluator<ArgType, Device>::CoordAccess) {
return m_impl.coeff(inputCoords);
} else {
Index inputIndex;
if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
inputIndex =
inputCoords[4] * m_otherInputStride +
inputCoords[3] * m_colInputStride +
inputCoords[2] * m_rowInputStride +
inputCoords[1] * m_planeInputStride +
inputCoords[0];
} else {
inputIndex =
inputCoords[0] * m_otherInputStride +
inputCoords[1] * m_colInputStride +
inputCoords[2] * m_rowInputStride +
inputCoords[3] * m_planeInputStride +
inputCoords[4];
}
return m_impl.coeff(inputIndex);
}
}
protected:
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packetWithPossibleZero(Index index) const
{