diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h b/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h index 78214df11..c3d6357fa 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorConcatenation.h @@ -135,19 +135,21 @@ struct TensorEvaluator 0); - eigen_assert(lhs_dims[i] == rhs_dims[i]); - m_dimensions[i] = lhs_dims[i]; - } - eigen_assert(lhs_dims[i] > 0); // Now i == m_axis. - eigen_assert(rhs_dims[i] > 0); - m_dimensions[i] = lhs_dims[i] + rhs_dims[i]; - for (++i; i < NumDims; ++i) { - eigen_assert(lhs_dims[i] > 0); - eigen_assert(lhs_dims[i] == rhs_dims[i]); - m_dimensions[i] = lhs_dims[i]; + { + int i = 0; + for (; i < m_axis; ++i) { + eigen_assert(lhs_dims[i] > 0); + eigen_assert(lhs_dims[i] == rhs_dims[i]); + m_dimensions[i] = lhs_dims[i]; + } + eigen_assert(lhs_dims[i] > 0); // Now i == m_axis. + eigen_assert(rhs_dims[i] > 0); + m_dimensions[i] = lhs_dims[i] + rhs_dims[i]; + for (++i; i < NumDims; ++i) { + eigen_assert(lhs_dims[i] > 0); + eigen_assert(lhs_dims[i] == rhs_dims[i]); + m_dimensions[i] = lhs_dims[i]; + } } if (static_cast(Layout) == static_cast(ColMajor)) { diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h b/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h index 2a7dd45c0..5a165dab0 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h @@ -185,11 +185,13 @@ struct TensorEvaluator, Device { Index inputIndex; if (static_cast(Layout) == static_cast(ColMajor)) { - const Index idx = coords[0]; - if (idx < m_padding[0].first || idx >= m_dimensions[0] - m_padding[0].second) { - return Scalar(0); + { + const Index idx = coords[0]; + if (idx < m_padding[0].first || idx >= m_dimensions[0] - m_padding[0].second) { + return Scalar(0); + } + inputIndex = idx - m_padding[0].first; } - inputIndex = idx - m_padding[0].first; for (int i = 1; i < NumDims; ++i) { const Index idx = coords[i]; if (idx < m_padding[i].first || idx >= m_dimensions[i] - m_padding[i].second) { @@ -198,11 +200,13 @@ struct TensorEvaluator, Device inputIndex += (idx - m_padding[i].first) * m_inputStrides[i]; } } else { - const Index idx = coords[NumDims-1]; - if (idx < m_padding[NumDims-1].first || idx >= m_dimensions[NumDims-1] - m_padding[NumDims-1].second) { - return Scalar(0); + { + const Index idx = coords[NumDims-1]; + if (idx < m_padding[NumDims-1].first || idx >= m_dimensions[NumDims-1] - m_padding[NumDims-1].second) { + return Scalar(0); + } + inputIndex = idx - m_padding[NumDims-1].first; } - inputIndex = idx - m_padding[NumDims-1].first; for (int i = NumDims - 2; i >= 0; --i) { const Index idx = coords[i]; if (idx < m_padding[i].first || idx >= m_dimensions[i] - m_padding[i].second) { diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h b/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h index fba7b20a9..6b25b2ba0 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorRef.h @@ -197,15 +197,15 @@ template class TensorRef : public TensorBase EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(Index firstIndex, IndexTypes... otherIndices) const { - const std::size_t NumIndices = (sizeof...(otherIndices) + 1); - const array indices{{firstIndex, otherIndices...}}; + const std::size_t num_indices = (sizeof...(otherIndices) + 1); + const array indices{{firstIndex, otherIndices...}}; return coeff(indices); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices) { - const std::size_t NumIndices = (sizeof...(otherIndices) + 1); - const array indices{{firstIndex, otherIndices...}}; + const std::size_t num_indices = (sizeof...(otherIndices) + 1); + const array indices{{firstIndex, otherIndices...}}; return coeffRef(indices); } #else diff --git a/unsupported/test/cxx11_tensor_reduction.cpp b/unsupported/test/cxx11_tensor_reduction.cpp index 0269853a9..b2c85a879 100644 --- a/unsupported/test/cxx11_tensor_reduction.cpp +++ b/unsupported/test/cxx11_tensor_reduction.cpp @@ -17,11 +17,11 @@ template static void test_simple_reductions() { Tensor tensor(2, 3, 5, 7); tensor.setRandom(); - array reduction_axis; - reduction_axis[0] = 1; - reduction_axis[1] = 3; + array reduction_axis2; + reduction_axis2[0] = 1; + reduction_axis2[1] = 3; - Tensor result = tensor.sum(reduction_axis); + Tensor result = tensor.sum(reduction_axis2); VERIFY_IS_EQUAL(result.dimension(0), 2); VERIFY_IS_EQUAL(result.dimension(1), 5); for (int i = 0; i < 2; ++i) { @@ -40,20 +40,20 @@ static void test_simple_reductions() { Tensor sum1 = tensor.sum(); VERIFY_IS_EQUAL(sum1.dimension(0), 1); - array reduction_axis; - reduction_axis[0] = 0; - reduction_axis[1] = 1; - reduction_axis[2] = 2; - reduction_axis[3] = 3; - Tensor sum2 = tensor.sum(reduction_axis); + array reduction_axis4; + reduction_axis4[0] = 0; + reduction_axis4[1] = 1; + reduction_axis4[2] = 2; + reduction_axis4[3] = 3; + Tensor sum2 = tensor.sum(reduction_axis4); VERIFY_IS_EQUAL(sum2.dimension(0), 1); VERIFY_IS_APPROX(sum1(0), sum2(0)); } - reduction_axis[0] = 0; - reduction_axis[1] = 2; - result = tensor.prod(reduction_axis); + reduction_axis2[0] = 0; + reduction_axis2[1] = 2; + result = tensor.prod(reduction_axis2); VERIFY_IS_EQUAL(result.dimension(0), 3); VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 3; ++i) { @@ -72,20 +72,20 @@ static void test_simple_reductions() { Tensor prod1 = tensor.prod(); VERIFY_IS_EQUAL(prod1.dimension(0), 1); - array reduction_axis; - reduction_axis[0] = 0; - reduction_axis[1] = 1; - reduction_axis[2] = 2; - reduction_axis[3] = 3; - Tensor prod2 = tensor.prod(reduction_axis); + array reduction_axis4; + reduction_axis4[0] = 0; + reduction_axis4[1] = 1; + reduction_axis4[2] = 2; + reduction_axis4[3] = 3; + Tensor prod2 = tensor.prod(reduction_axis4); VERIFY_IS_EQUAL(prod2.dimension(0), 1); VERIFY_IS_APPROX(prod1(0), prod2(0)); } - reduction_axis[0] = 0; - reduction_axis[1] = 2; - result = tensor.maximum(reduction_axis); + reduction_axis2[0] = 0; + reduction_axis2[1] = 2; + result = tensor.maximum(reduction_axis2); VERIFY_IS_EQUAL(result.dimension(0), 3); VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 3; ++i) { @@ -104,20 +104,20 @@ static void test_simple_reductions() { Tensor max1 = tensor.maximum(); VERIFY_IS_EQUAL(max1.dimension(0), 1); - array reduction_axis; - reduction_axis[0] = 0; - reduction_axis[1] = 1; - reduction_axis[2] = 2; - reduction_axis[3] = 3; - Tensor max2 = tensor.maximum(reduction_axis); + array reduction_axis4; + reduction_axis4[0] = 0; + reduction_axis4[1] = 1; + reduction_axis4[2] = 2; + reduction_axis4[3] = 3; + Tensor max2 = tensor.maximum(reduction_axis4); VERIFY_IS_EQUAL(max2.dimension(0), 1); VERIFY_IS_APPROX(max1(0), max2(0)); } - reduction_axis[0] = 0; - reduction_axis[1] = 1; - result = tensor.minimum(reduction_axis); + reduction_axis2[0] = 0; + reduction_axis2[1] = 1; + result = tensor.minimum(reduction_axis2); VERIFY_IS_EQUAL(result.dimension(0), 5); VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 5; ++i) { @@ -136,20 +136,20 @@ static void test_simple_reductions() { Tensor min1 = tensor.minimum(); VERIFY_IS_EQUAL(min1.dimension(0), 1); - array reduction_axis; - reduction_axis[0] = 0; - reduction_axis[1] = 1; - reduction_axis[2] = 2; - reduction_axis[3] = 3; - Tensor min2 = tensor.minimum(reduction_axis); + array reduction_axis4; + reduction_axis4[0] = 0; + reduction_axis4[1] = 1; + reduction_axis4[2] = 2; + reduction_axis4[3] = 3; + Tensor min2 = tensor.minimum(reduction_axis4); VERIFY_IS_EQUAL(min2.dimension(0), 1); VERIFY_IS_APPROX(min1(0), min2(0)); } - reduction_axis[0] = 0; - reduction_axis[1] = 1; - result = tensor.mean(reduction_axis); + reduction_axis2[0] = 0; + reduction_axis2[1] = 1; + result = tensor.mean(reduction_axis2); VERIFY_IS_EQUAL(result.dimension(0), 5); VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 5; ++i) { @@ -170,12 +170,12 @@ static void test_simple_reductions() { Tensor mean1 = tensor.mean(); VERIFY_IS_EQUAL(mean1.dimension(0), 1); - array reduction_axis; - reduction_axis[0] = 0; - reduction_axis[1] = 1; - reduction_axis[2] = 2; - reduction_axis[3] = 3; - Tensor mean2 = tensor.mean(reduction_axis); + array reduction_axis4; + reduction_axis4[0] = 0; + reduction_axis4[1] = 1; + reduction_axis4[2] = 2; + reduction_axis4[3] = 3; + Tensor mean2 = tensor.mean(reduction_axis4); VERIFY_IS_EQUAL(mean2.dimension(0), 1); VERIFY_IS_APPROX(mean1(0), mean2(0));