From 6bb3f1b43ecad440fb7ad172657f0f7a0c804d29 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 14 Aug 2018 14:26:59 -0700 Subject: Made the tensor_block_access test compile again --- unsupported/test/cxx11_tensor_block_access.cpp | 120 ++++++++++++------------- 1 file changed, 58 insertions(+), 62 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 6feeff231..2631767e2 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -10,6 +10,8 @@ #include "main.h" +#include +#include #include #include @@ -19,17 +21,16 @@ using Eigen::Index; using Eigen::RowMajor; using Eigen::ColMajor; -using internal::TensorBlockShapeType; template static const T& choose(int layout, const T& col, const T& row) { return layout == ColMajor ? col : row; } -static const TensorBlockShapeType RandomShape() { +static internal::TensorBlockShapeType RandomShape() { return internal::random() - ? internal::TensorBlockShapeType::kUniformAllDims - : internal::TensorBlockShapeType::kSkewedInnerDims; + ? internal::kUniformAllDims + : internal::kSkewedInnerDims; } template @@ -44,7 +45,7 @@ static DSizes RandomDims() { dims[i] = internal::random(1, 20); } return DSizes(dims); -}; +} /** Dummy data type to test TensorBlock copy ops. */ struct Data { @@ -91,21 +92,19 @@ static void Debug(DSizes dims) { template static void test_block_mapper_sanity() { - using T = int; - using TensorBlock = internal::TensorBlock; - using TensorBlockMapper = internal::TensorBlockMapper; + typedef internal::TensorBlockMapper TensorBlockMapper; DSizes tensor_dims(100, 100); // Test uniform blocks. TensorBlockMapper uniform_block_mapper( - tensor_dims, internal::TensorBlockShapeType::kUniformAllDims, 100); + tensor_dims, internal::kUniformAllDims, 100); VERIFY_IS_EQUAL(uniform_block_mapper.total_block_count(), 100); VERIFY_IS_EQUAL(uniform_block_mapper.block_dims_total_size(), 100); // 10x10 blocks - auto uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, nullptr); + auto uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(0), 10); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(1), 10); // Depending on a layout we stride by cols rows. @@ -117,13 +116,13 @@ static void test_block_mapper_sanity() // Test skewed to inner dims blocks. TensorBlockMapper skewed_block_mapper( - tensor_dims, internal::TensorBlockShapeType::kSkewedInnerDims, 100); + tensor_dims, internal::kSkewedInnerDims, 100); VERIFY_IS_EQUAL(skewed_block_mapper.total_block_count(), 100); VERIFY_IS_EQUAL(skewed_block_mapper.block_dims_total_size(), 100); // 1x100 (100x1) rows/cols depending on a tensor layout. - auto skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, nullptr); + auto skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(0), choose(Layout, 100, 1)); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(1), choose(Layout, 1, 100)); // Depending on a layout we stride by cols rows. @@ -171,7 +170,7 @@ static void test_block_mapper_maps_every_element() { TensorBlockMapper block_mapper(dims, RandomShape(), RandomTargetSize(dims)); for (int i = 0; i < block_mapper.total_block_count(); ++i) { - TensorBlock block = block_mapper.GetBlockForIndex(i, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(i, NULL); UpdateCoeffSet(block, block.first_coeff_index(), choose(Layout, NumDims - 1, 0), &coeff_set); @@ -219,7 +218,7 @@ static void test_slice_block_mapper_maps_every_element() { DimensionList()); for (int i = 0; i < block_mapper.total_block_count(); ++i) { - TensorBlock block = block_mapper.GetBlockForIndex(i, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(i, NULL); UpdateCoeffSet(block, block.first_coeff_index(), choose(Layout, NumDims - 1, 0), &coeff_set); @@ -647,17 +646,16 @@ static void test_block_cwise_binary_io_zero_strides() { template static void test_uniform_block_shape() { - using T = int; - typedef internal::TensorBlock TensorBlock; - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorBlockMapper TensorBlockMapper; { // Test shape 'UniformAllDims' with uniform 'max_coeff count'. DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 5 * 5 * 5 * 5 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); for (int i = 0; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); } @@ -669,9 +667,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 7 * 5 * 5 * 5 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -680,9 +678,9 @@ static void test_uniform_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 5 * 5 * 5 * 5 * 6; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(6, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -695,9 +693,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 5 * 5 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -706,9 +704,9 @@ static void test_uniform_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 5 * 5 * 5 * 5 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -721,9 +719,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); const size_t max_coeff_count = 7 * 5 * 6 * 7 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -733,9 +731,9 @@ static void test_uniform_block_shape() } else { DSizes dims(7, 5, 6, 9, 7); const size_t max_coeff_count = 5 * 5 * 5 * 6 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(6, block.block_sizes()[3]); VERIFY_IS_EQUAL(5, block.block_sizes()[2]); @@ -748,9 +746,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); const size_t max_coeff_count = 7 * 5 * 6 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -760,9 +758,9 @@ static void test_uniform_block_shape() } else { DSizes dims(7, 5, 6, 9, 7); const size_t max_coeff_count = 7 * 5 * 6 * 9 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(9, block.block_sizes()[3]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -783,9 +781,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 10 * 1 * 1 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(10, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -794,9 +792,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 1 * 1 * 6; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(6, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -808,9 +806,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 1 * 1 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -819,9 +817,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 1 * 1 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -834,9 +832,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 3 * 1 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); VERIFY_IS_EQUAL(3, block.block_sizes()[1]); for (int i = 2; i < 5; ++i) { @@ -846,9 +844,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 1 * 15 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(15, block.block_sizes()[3]); for (int i = 2; i >= 0; --i) { @@ -862,9 +860,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 5 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(5, block.block_sizes()[2]); @@ -875,9 +873,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 5 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(17, block.block_sizes()[3]); VERIFY_IS_EQUAL(5, block.block_sizes()[2]); @@ -891,9 +889,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 6 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -903,9 +901,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 6 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(17, block.block_sizes()[3]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -918,15 +916,13 @@ static void test_skewed_inner_dim_block_shape() template static void test_empty_dims(const internal::TensorBlockShapeType block_shape) { - using T = int; - // Test blocking of tensors with zero dimensions: // - we must not crash on asserts and divisions by zero // - we must not return block with zero dimensions // (recipe for overflows/underflows, divisions by zero and NaNs later) // - total block count must be zero { - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlockMapper TensorBlockMapper; DSizes dims(0); for (int max_coeff_count = 0; max_coeff_count < 2; ++max_coeff_count) { TensorBlockMapper block_mapper(dims, block_shape, max_coeff_count); @@ -936,7 +932,7 @@ static void test_empty_dims(const internal::TensorBlockShapeType block_shape) } { - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlockMapper TensorBlockMapper; for (int dim1 = 0; dim1 < 3; ++dim1) { for (int dim2 = 0; dim2 < 3; ++dim2) { DSizes dims(dim1, dim2); @@ -987,9 +983,9 @@ EIGEN_DECLARE_TEST(cxx11_tensor_block_access) { TEST_LAYOUTS(test_block_cwise_binary_io_zero_strides); TEST_LAYOUTS(test_uniform_block_shape); TEST_LAYOUTS(test_skewed_inner_dim_block_shape); - TEST_LAYOUTS_WITH_ARG(test_empty_dims, TensorBlockShapeType::kUniformAllDims); - TEST_LAYOUTS_WITH_ARG(test_empty_dims, TensorBlockShapeType::kSkewedInnerDims); + TEST_LAYOUTS_WITH_ARG(test_empty_dims, internal::kUniformAllDims); + TEST_LAYOUTS_WITH_ARG(test_empty_dims, internal::kSkewedInnerDims); } #undef TEST_LAYOUTS -#undef TEST_LAYOUTS_WITH_ARG \ No newline at end of file +#undef TEST_LAYOUTS_WITH_ARG -- cgit v1.2.3 From b6f96cf7dd616ed1604919892f68f5b94d31fa5e Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 15 Aug 2018 08:54:31 -0700 Subject: Removed dependencies on cxx11 language features from the tensor_block_access test --- unsupported/test/cxx11_tensor_block_access.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 2631767e2..417b72201 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -157,9 +157,8 @@ static void UpdateCoeffSet( template static void test_block_mapper_maps_every_element() { - using TensorBlock = internal::TensorBlock; - using TensorBlockMapper = - internal::TensorBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorBlockMapper TensorBlockMapper; DSizes dims = RandomDims(); @@ -186,9 +185,8 @@ static void test_block_mapper_maps_every_element() { template static void test_slice_block_mapper_maps_every_element() { - using TensorBlock = internal::TensorBlock; - using TensorSliceBlockMapper = - internal::TensorSliceBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorSliceBlockMapper TensorSliceBlockMapper; DSizes tensor_dims = RandomDims(); DSizes tensor_slice_offsets = RandomDims(); @@ -773,9 +771,8 @@ static void test_uniform_block_shape() template static void test_skewed_inner_dim_block_shape() { - using T = int; - typedef internal::TensorBlock TensorBlock; - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorBlockMapper TensorBlockMapper; // Test shape 'SkewedInnerDims' with partial allocation to inner-most dim. if (Layout == ColMajor) { -- cgit v1.2.3 From ede580ccdac3b964bdfcf12d55560a268c366c3c Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 16 Aug 2018 10:49:47 -0700 Subject: Avoid using the auto keyword to make the tensor block access test more portable --- unsupported/test/cxx11_tensor_block_access.cpp | 56 +++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 417b72201..da093166b 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -104,7 +104,7 @@ static void test_block_mapper_sanity() VERIFY_IS_EQUAL(uniform_block_mapper.block_dims_total_size(), 100); // 10x10 blocks - auto uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, NULL); + typename TensorBlockMapper::Block uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(0), 10); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(1), 10); // Depending on a layout we stride by cols rows. @@ -122,7 +122,7 @@ static void test_block_mapper_sanity() VERIFY_IS_EQUAL(skewed_block_mapper.block_dims_total_size(), 100); // 1x100 (100x1) rows/cols depending on a tensor layout. - auto skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, NULL); + typename TensorBlockMapper::Block skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(0), choose(Layout, 100, 1)); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(1), choose(Layout, 1, 100)); // Depending on a layout we stride by cols rows. @@ -203,7 +203,7 @@ static void test_slice_block_mapper_maps_every_element() { // Keep track of elements indices available via block access. std::set coeff_set; - auto total_coeffs = static_cast(tensor_slice_extents.TotalSize()); + int total_coeffs = static_cast(tensor_slice_extents.TotalSize()); // Pick a random dimension sizes for the tensor blocks. DSizes block_sizes; @@ -237,7 +237,7 @@ static void test_block_io_copy_data_from_source_to_target() { TensorBlockWriter; DSizes input_tensor_dims = RandomDims(); - const auto input_tensor_size = input_tensor_dims.TotalSize(); + const Index input_tensor_size = input_tensor_dims.TotalSize(); T* input_data = GenerateRandomData(input_tensor_size); T* output_data = new T[input_tensor_size]; @@ -316,7 +316,7 @@ static void test_block_io_copy_using_reordered_dimensions() { TensorBlockWriter; DSizes input_tensor_dims = RandomDims(); - const auto input_tensor_size = input_tensor_dims.TotalSize(); + const Index input_tensor_size = input_tensor_dims.TotalSize(); // Create a random input tensor. T* input_data = GenerateRandomData(input_tensor_size); @@ -339,8 +339,8 @@ static void test_block_io_copy_using_reordered_dimensions() { TensorBlockMapper block_mapper(output_tensor_dims, RandomShape(), RandomTargetSize(input_tensor_dims)); - auto* block_data = new T[block_mapper.block_dims_total_size()]; - auto* output_data = new T[input_tensor_size]; + T* block_data = new T[block_mapper.block_dims_total_size()]; + T* output_data = new T[input_tensor_size]; array input_tensor_strides = ComputeStrides(input_tensor_dims); @@ -382,8 +382,8 @@ static void test_block_io_zero_stride() input_tensor_dims[0] = 1; input_tensor_dims[2] = 1; input_tensor_dims[4] = 1; - const auto input_tensor_size = input_tensor_dims.TotalSize(); - auto* input_data = GenerateRandomData(input_tensor_size); + const Index input_tensor_size = input_tensor_dims.TotalSize(); + float* input_data = GenerateRandomData(input_tensor_size); DSizes output_tensor_dims = rnd_dims; @@ -424,7 +424,7 @@ static void test_block_io_zero_stride() }; { - auto* output_data = new float[output_tensor_dims.TotalSize()]; + float* output_data = new float[output_tensor_dims.TotalSize()]; TensorBlock read_block(0, output_tensor_dims, output_tensor_strides, input_tensor_strides_with_zeros, output_data); TensorBlockReader::Run(&read_block, input_data); @@ -433,7 +433,7 @@ static void test_block_io_zero_stride() } { - auto* output_data = new float[output_tensor_dims.TotalSize()]; + float* output_data = new float[output_tensor_dims.TotalSize()]; TensorBlock write_block(0, output_tensor_dims, input_tensor_strides_with_zeros, output_tensor_strides, input_data); @@ -456,14 +456,14 @@ static void test_block_io_squeeze_ones() { // Total size > 1. { DSizes block_sizes(1, 2, 1, 2, 1); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensor. - auto* input_data = GenerateRandomData(total_size); + float* input_data = GenerateRandomData(total_size); DSizes strides(ComputeStrides(block_sizes)); { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock read_block(0, block_sizes, strides, strides, output_data); TensorBlockReader::Run(&read_block, input_data); for (int i = 0; i < total_size; ++i) { @@ -473,7 +473,7 @@ static void test_block_io_squeeze_ones() { } { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock write_block(0, block_sizes, strides, strides, input_data); TensorBlockWriter::Run(write_block, output_data); for (int i = 0; i < total_size; ++i) { @@ -486,14 +486,14 @@ static void test_block_io_squeeze_ones() { // Total size == 1. { DSizes block_sizes(1, 1, 1, 1, 1); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensor. - auto* input_data = GenerateRandomData(total_size); + float* input_data = GenerateRandomData(total_size); DSizes strides(ComputeStrides(block_sizes)); { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock read_block(0, block_sizes, strides, strides, output_data); TensorBlockReader::Run(&read_block, input_data); for (int i = 0; i < total_size; ++i) { @@ -503,7 +503,7 @@ static void test_block_io_squeeze_ones() { } { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock write_block(0, block_sizes, strides, strides, input_data); TensorBlockWriter::Run(write_block, output_data); for (int i = 0; i < total_size; ++i) { @@ -524,7 +524,7 @@ static void test_block_cwise_binary_io_basic() { DSizes block_sizes = RandomDims(); DSizes strides(ComputeStrides(block_sizes)); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensors. T* left_data = GenerateRandomData(total_size); @@ -553,13 +553,13 @@ static void test_block_cwise_binary_io_squeeze_ones() { DSizes block_sizes(1, 2, 1, 3, 1); DSizes strides(ComputeStrides(block_sizes)); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensors. - auto* left_data = GenerateRandomData(total_size); - auto* right_data = GenerateRandomData(total_size); + float* left_data = GenerateRandomData(total_size); + float* right_data = GenerateRandomData(total_size); - auto* output_data = new float[total_size]; + float* output_data = new float[total_size]; BinaryFunctor functor; TensorBlockCwiseBinaryIO::Run(functor, block_sizes, strides, output_data, strides, left_data, strides, right_data); @@ -600,14 +600,14 @@ static void test_block_cwise_binary_io_zero_strides() { right_strides[3] = 0; // Generate random data. - auto* left_data = GenerateRandomData(left_sizes.TotalSize()); - auto* right_data = GenerateRandomData(right_sizes.TotalSize()); + float* left_data = GenerateRandomData(left_sizes.TotalSize()); + float* right_data = GenerateRandomData(right_sizes.TotalSize()); DSizes output_sizes = rnd_dims; DSizes output_strides(ComputeStrides(output_sizes)); - const auto output_total_size = output_sizes.TotalSize(); - auto* output_data = new float[output_total_size]; + const Index output_total_size = output_sizes.TotalSize(); + float* output_data = new float[output_total_size]; BinaryFunctor functor; TensorBlockCwiseBinaryIO::Run(functor, output_sizes, output_strides, -- cgit v1.2.3 From 43d9dd9b2844828de3996b762b2f760749df711b Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 17 Aug 2018 08:49:32 -0700 Subject: Removed more dependencies on cxx11. --- unsupported/test/cxx11_tensor_block_access.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index da093166b..7bf338522 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -11,7 +11,6 @@ #include "main.h" #include -#include #include #include @@ -49,8 +48,8 @@ static DSizes RandomDims() { /** Dummy data type to test TensorBlock copy ops. */ struct Data { - Data() : Data(0) {} - explicit Data(int v) { value = v; } + Data() : value(0) {} + explicit Data(int v) : value(v) { } int value; }; @@ -324,7 +323,7 @@ static void test_block_io_copy_using_reordered_dimensions() { // Create a random dimension re-ordering/shuffle. std::vector shuffle; for (int i = 0; i < NumDims; ++i) shuffle.push_back(i); - std::shuffle(shuffle.begin(), shuffle.end(), std::mt19937()); + std::random_shuffle(shuffle.begin(), shuffle.end()); DSizes output_tensor_dims; array input_to_output_dim_map; -- cgit v1.2.3 From ff8e0ecc2fa83ca4de14fc2f1049bd48907df3f6 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 17 Aug 2018 15:15:52 -0700 Subject: Updated one more line of code to avoid making the test dependent on cxx11 features. --- unsupported/test/cxx11_tensor_block_access.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 7bf338522..f572e496d 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -143,7 +143,8 @@ static void UpdateCoeffSet( for (int i = 0; i < block_sizes[dim_index]; ++i) { if (tensor_strides[dim_index] == 1) { - auto inserted = visited_coeffs->insert(first_coeff_index + i); + typedef std::pair::iterator, bool> ReturnType; + ReturnType inserted = visited_coeffs->insert(first_coeff_index + i); VERIFY_IS_EQUAL(inserted.second, true); } else { int next_dim_index = dim_index + choose(Layout, -1, 1); -- cgit v1.2.3 From f7675b826b2f0a33b09b97342e855a8ef059927e Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 24 Aug 2018 22:58:55 +0200 Subject: Fix several integer conversion and sign-compare warnings --- unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h | 27 ++++---- .../Eigen/CXX11/src/Tensor/TensorDimensions.h | 72 +++++++++++----------- .../Eigen/CXX11/src/Tensor/TensorExecutor.h | 4 +- .../Eigen/CXX11/src/Tensor/TensorIndexList.h | 2 +- unsupported/test/cxx11_tensor_block_access.cpp | 54 ++++++++-------- unsupported/test/cxx11_tensor_thread_pool.cpp | 2 +- 6 files changed, 80 insertions(+), 81 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h index 24a6343e8..aa500eb70 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h @@ -212,11 +212,11 @@ class TensorBlockIO { num_size_one_inner_dims, NumDims - num_size_one_inner_dims - 1); const StorageIndex block_dim_for_tensor_stride1_dim = NumDims == 0 ? 1 : tensor_to_block_dim_map[tensor_stride1_dim]; - size_t block_inner_dim_size = + StorageIndex block_inner_dim_size = NumDims == 0 ? 1 : block.block_sizes()[block_dim_for_tensor_stride1_dim]; - for (int i = num_size_one_inner_dims + 1; i < NumDims; ++i) { - const int dim = cond()(i, NumDims - i - 1); + for (Index i = num_size_one_inner_dims + 1; i < NumDims; ++i) { + const Index dim = cond()(i, NumDims - i - 1); const StorageIndex block_stride = block.block_strides()[tensor_to_block_dim_map[dim]]; if (block_inner_dim_size == block_stride && @@ -258,8 +258,8 @@ class TensorBlockIO { // Initialize block iterator state. Squeeze away any dimension of size 1. int num_squeezed_dims = 0; - for (int i = num_size_one_inner_dims; i < NumDims - 1; ++i) { - const int dim = cond()(i + 1, NumDims - i - 2); + for (Index i = num_size_one_inner_dims; i < NumDims - 1; ++i) { + const Index dim = cond()(i + 1, NumDims - i - 2); const StorageIndex size = block.block_sizes()[tensor_to_block_dim_map[dim]]; if (size == 1) { continue; @@ -626,7 +626,7 @@ class TensorBlockMapper { const TensorBlockShapeType block_shape, Index min_target_size) : m_dimensions(dims), - m_block_dim_sizes(BlockDimensions(dims, block_shape, min_target_size)) { + m_block_dim_sizes(BlockDimensions(dims, block_shape, internal::convert_index(min_target_size))) { // Calculate block counts by dimension and total block count. DSizes block_count; for (Index i = 0; i < block_count.rank(); ++i) { @@ -717,8 +717,8 @@ class TensorBlockMapper { private: static Dimensions BlockDimensions(const Dimensions& tensor_dims, const TensorBlockShapeType block_shape, - Index min_target_size) { - min_target_size = numext::maxi(1, min_target_size); + StorageIndex min_target_size) { + min_target_size = numext::maxi(1, min_target_size); // If tensor fully fits into the target size, we'll treat it a single block. Dimensions block_dim_sizes = tensor_dims; @@ -735,16 +735,15 @@ class TensorBlockMapper { if (block_shape == kUniformAllDims) { // Tensor will not fit within 'min_target_size' budget: calculate tensor // block dimension sizes based on "square" dimension size target. - const size_t dim_size_target = static_cast( + const StorageIndex dim_size_target = internal::convert_index( std::pow(static_cast(min_target_size), 1.0f / static_cast(block_dim_sizes.rank()))); - for (size_t i = 0; i < block_dim_sizes.rank(); ++i) { + for (Index i = 0; i < block_dim_sizes.rank(); ++i) { // TODO(andydavis) Adjust the inner most 'block_dim_size' to make it // a multiple of the packet size. Note that reducing // 'block_dim_size' in this manner can increase the number of // blocks, and so will amplify any per-block overhead. - block_dim_sizes[i] = numext::mini( - dim_size_target, static_cast(tensor_dims[i])); + block_dim_sizes[i] = numext::mini(dim_size_target, tensor_dims[i]); } // Add any un-allocated coefficients to inner dimension(s). StorageIndex total_size = block_dim_sizes.TotalSize(); @@ -781,7 +780,7 @@ class TensorBlockMapper { eigen_assert( block_dim_sizes.TotalSize() >= - numext::mini(min_target_size, tensor_dims.TotalSize())); + numext::mini(min_target_size, tensor_dims.TotalSize())); return block_dim_sizes; } @@ -824,7 +823,7 @@ class TensorSliceBlockMapper { m_total_block_count(1) { // Calculate block counts by dimension and total block count. DSizes block_count; - for (size_t i = 0; i < block_count.rank(); ++i) { + for (Index i = 0; i < block_count.rank(); ++i) { block_count[i] = divup(m_tensor_slice_extents[i], m_block_dim_sizes[i]); } m_total_block_count = array_prod(block_count); diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h index 4f973a5b7..ce91bc2a6 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h @@ -32,12 +32,12 @@ namespace Eigen { // Boilerplate code namespace internal { -template struct dget { +template struct dget { static const std::ptrdiff_t value = get::value; }; -template +template struct fixed_size_tensor_index_linearization_helper { template EIGEN_DEVICE_FUNC @@ -50,7 +50,7 @@ struct fixed_size_tensor_index_linearization_helper } }; -template +template struct fixed_size_tensor_index_linearization_helper { template EIGEN_DEVICE_FUNC @@ -60,7 +60,7 @@ struct fixed_size_tensor_index_linearization_helper +template struct fixed_size_tensor_index_extraction_helper { template EIGEN_DEVICE_FUNC @@ -94,7 +94,7 @@ struct Sizes { typedef internal::numeric_list Base; const Base t = Base(); static const std::ptrdiff_t total_size = internal::arg_prod(Indices...); - static const size_t count = Base::count; + static const ptrdiff_t count = Base::count; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank() const { return Base::count; @@ -121,16 +121,16 @@ struct Sizes { return *this; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[] (const std::size_t index) const { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[] (const std::ptrdiff_t index) const { return internal::fixed_size_tensor_index_extraction_helper::run(index, t); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - size_t IndexOfColMajor(const array& indices) const { + ptrdiff_t IndexOfColMajor(const array& indices) const { return internal::fixed_size_tensor_index_linearization_helper::run(indices, t); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - size_t IndexOfRowMajor(const array& indices) const { + ptrdiff_t IndexOfRowMajor(const array& indices) const { return internal::fixed_size_tensor_index_linearization_helper::run(indices, t); } }; @@ -144,25 +144,25 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes +template struct non_zero_size { - typedef internal::type2val type; + typedef internal::type2val type; }; template <> struct non_zero_size<0> { typedef internal::null_type type; }; -template struct Sizes { +template struct Sizes { typedef typename internal::make_type_list::type, typename non_zero_size::type, typename non_zero_size::type, typename non_zero_size::type, typename non_zero_size::type >::type Base; - static const size_t count = Base::count; - static const std::size_t total_size = internal::arg_prod::value; + static const std::ptrdiff_t count = Base::count; + static const std::ptrdiff_t total_size = internal::arg_prod::value; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t rank() const { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t rank() const { return count; } - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t TotalSize() { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t TotalSize() { return internal::arg_prod::value; } @@ -178,7 +178,7 @@ template Sizes(DenseIndex... /*indices*/) { } - explicit Sizes(std::initializer_list) { + explicit Sizes(std::initializer_list) { // todo: add assertion } #else @@ -213,18 +213,18 @@ template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - size_t IndexOfColMajor(const array& indices) const { + ptrdiff_t IndexOfColMajor(const array& indices) const { return internal::fixed_size_tensor_index_linearization_helper::run(indices, *reinterpret_cast(this)); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - size_t IndexOfRowMajor(const array& indices) const { + ptrdiff_t IndexOfRowMajor(const array& indices) const { return internal::fixed_size_tensor_index_linearization_helper::run(indices, *reinterpret_cast(this)); } }; namespace internal { -template -EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_prod(const Sizes&) { +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes&) { return Sizes::total_size; } } @@ -233,7 +233,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_prod(const Sizes +template struct tensor_index_linearization_helper { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE @@ -245,7 +245,7 @@ struct tensor_index_linearization_helper } }; -template +template struct tensor_index_linearization_helper { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE @@ -264,7 +264,7 @@ struct DSizes : array { typedef array Base; static const int count = NumDims; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t rank() const { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumDims; } @@ -298,7 +298,7 @@ struct DSizes : array { } } #else - template + template EIGEN_DEVICE_FUNC DSizes(const Sizes& a) { for (int i = 0 ; i < NumDims; ++i) { (*this)[i] = a[i]; @@ -359,7 +359,7 @@ struct DSizes : array { // Boilerplate namespace internal { -template +template struct tensor_vsize_index_linearization_helper { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE @@ -371,7 +371,7 @@ struct tensor_vsize_index_linearization_helper } }; -template +template struct tensor_vsize_index_linearization_helper { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE @@ -386,10 +386,10 @@ struct tensor_vsize_index_linearization_helper namespace internal { template struct array_size > { - static const size_t value = NumDims; + static const ptrdiff_t value = NumDims; }; template struct array_size > { - static const size_t value = NumDims; + static const ptrdiff_t value = NumDims; }; #ifndef EIGEN_EMULATE_CXX11_META_H template struct array_size > { @@ -399,33 +399,33 @@ template struct array_size::count; }; template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes&) { - return get >::value; + return get >::value; } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<>&) { eigen_assert(false && "should never be called"); return -1; } #else -template struct array_size > { - static const size_t value = Sizes::count; +template struct array_size > { + static const ptrdiff_t value = Sizes::count; }; -template struct array_size > { - static const size_t value = Sizes::count; +template struct array_size > { + static const ptrdiff_t value = Sizes::count; }; -template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_get(const Sizes&) { +template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes&) { return get::Base>::value; } #endif -template +template struct sizes_match_below_dim { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1&, Dims2&) { return false; } }; -template +template struct sizes_match_below_dim { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1& dims1, Dims2& dims2) { return (array_get(dims1) == array_get(dims2)) & diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h index 9b9587de5..b756be3b3 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h @@ -256,8 +256,8 @@ class TensorExecutor TensorBlockMapper; Evaluator evaluator(expr, device); - StorageIndex total_size = array_prod(evaluator.dimensions()); - StorageIndex cache_size = device.firstLevelCacheSize() / sizeof(Scalar); + Index total_size = array_prod(evaluator.dimensions()); + Index cache_size = device.firstLevelCacheSize() / sizeof(Scalar); if (total_size < cache_size) { // TODO(andydavis) Reduce block management overhead for small tensors. internal::TensorExecutor struct NumTraits > namespace internal { template EIGEN_DEVICE_FUNC void update_value(T& val, DenseIndex new_val) { - val = new_val; + val = internal::convert_index(new_val); } template EIGEN_DEVICE_FUNC void update_value(type2index& val, DenseIndex new_val) { diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index f572e496d..24a95ab12 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -33,8 +33,8 @@ static internal::TensorBlockShapeType RandomShape() { } template -static std::size_t RandomTargetSize(const DSizes& dims) { - return internal::random(1, dims.TotalSize()); +static Index RandomTargetSize(const DSizes& dims) { + return internal::random(1, dims.TotalSize()); } template @@ -178,7 +178,7 @@ static void test_block_mapper_maps_every_element() { // Verify that every coefficient in the original Tensor is accessible through // TensorBlock only once. Index total_coeffs = dims.TotalSize(); - VERIFY_IS_EQUAL(coeff_set.size(), total_coeffs); + VERIFY_IS_EQUAL(Index(coeff_set.size()), total_coeffs); VERIFY_IS_EQUAL(*coeff_set.begin(), 0); VERIFY_IS_EQUAL(*coeff_set.rbegin(), total_coeffs - 1); } @@ -208,7 +208,7 @@ static void test_slice_block_mapper_maps_every_element() { // Pick a random dimension sizes for the tensor blocks. DSizes block_sizes; for (int i = 0; i < NumDims; ++i) { - block_sizes[i] = internal::random(1, tensor_slice_extents[i]); + block_sizes[i] = internal::random(1, tensor_slice_extents[i]); } TensorSliceBlockMapper block_mapper(tensor_dims, tensor_slice_offsets, @@ -222,7 +222,7 @@ static void test_slice_block_mapper_maps_every_element() { &coeff_set); } - VERIFY_IS_EQUAL(coeff_set.size(), total_coeffs); + VERIFY_IS_EQUAL(Index(coeff_set.size()), total_coeffs); } template @@ -262,14 +262,14 @@ static void test_block_io_copy_data_from_source_to_target() { } template -static int GetInputIndex(Index output_index, +static Index GetInputIndex(Index output_index, const array& output_to_input_dim_map, const array& input_strides, const array& output_strides) { int input_index = 0; if (Layout == ColMajor) { for (int i = NumDims - 1; i > 0; --i) { - const int idx = output_index / output_strides[i]; + const Index idx = output_index / output_strides[i]; input_index += idx * input_strides[output_to_input_dim_map[i]]; output_index -= idx * output_strides[i]; } @@ -277,7 +277,7 @@ static int GetInputIndex(Index output_index, output_index * input_strides[output_to_input_dim_map[0]]; } else { for (int i = 0; i < NumDims - 1; ++i) { - const int idx = output_index / output_strides[i]; + const Index idx = output_index / output_strides[i]; input_index += idx * input_strides[output_to_input_dim_map[i]]; output_index -= idx * output_strides[i]; } @@ -650,7 +650,7 @@ static void test_uniform_block_shape() { // Test shape 'UniformAllDims' with uniform 'max_coeff count'. DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 5 * 5 * 5 * 5 * 5; + const Index max_coeff_count = 5 * 5 * 5 * 5 * 5; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -664,7 +664,7 @@ static void test_uniform_block_shape() // partially into first inner-most dimension. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 7 * 5 * 5 * 5 * 5; + const Index max_coeff_count = 7 * 5 * 5 * 5 * 5; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -675,7 +675,7 @@ static void test_uniform_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 5 * 5 * 5 * 5 * 6; + const Index max_coeff_count = 5 * 5 * 5 * 5 * 6; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -690,7 +690,7 @@ static void test_uniform_block_shape() // fully into first inner-most dimension. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 11 * 5 * 5 * 5 * 5; + const Index max_coeff_count = 11 * 5 * 5 * 5 * 5; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -701,7 +701,7 @@ static void test_uniform_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 5 * 5 * 5 * 5 * 7; + const Index max_coeff_count = 5 * 5 * 5 * 5 * 7; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -716,7 +716,7 @@ static void test_uniform_block_shape() // fully into first few inner-most dimensions. if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); - const size_t max_coeff_count = 7 * 5 * 6 * 7 * 5; + const Index max_coeff_count = 7 * 5 * 6 * 7 * 5; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -728,7 +728,7 @@ static void test_uniform_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(7, 5, 6, 9, 7); - const size_t max_coeff_count = 5 * 5 * 5 * 6 * 7; + const Index max_coeff_count = 5 * 5 * 5 * 6 * 7; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -743,7 +743,7 @@ static void test_uniform_block_shape() // Test shape 'UniformAllDims' with full allocation to all dims. if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); - const size_t max_coeff_count = 7 * 5 * 6 * 17 * 7; + const Index max_coeff_count = 7 * 5 * 6 * 17 * 7; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -755,7 +755,7 @@ static void test_uniform_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(7, 5, 6, 9, 7); - const size_t max_coeff_count = 7 * 5 * 6 * 9 * 7; + const Index max_coeff_count = 7 * 5 * 6 * 9 * 7; TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -777,7 +777,7 @@ static void test_skewed_inner_dim_block_shape() // Test shape 'SkewedInnerDims' with partial allocation to inner-most dim. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 10 * 1 * 1 * 1 * 1; + const Index max_coeff_count = 10 * 1 * 1 * 1 * 1; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -788,7 +788,7 @@ static void test_skewed_inner_dim_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 1 * 1 * 1 * 1 * 6; + const Index max_coeff_count = 1 * 1 * 1 * 1 * 6; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -802,7 +802,7 @@ static void test_skewed_inner_dim_block_shape() // Test shape 'SkewedInnerDims' with full allocation to inner-most dim. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 11 * 1 * 1 * 1 * 1; + const Index max_coeff_count = 11 * 1 * 1 * 1 * 1; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -813,7 +813,7 @@ static void test_skewed_inner_dim_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 1 * 1 * 1 * 1 * 7; + const Index max_coeff_count = 1 * 1 * 1 * 1 * 7; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -828,7 +828,7 @@ static void test_skewed_inner_dim_block_shape() // and partial allocation to second inner-dim. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 11 * 3 * 1 * 1 * 1; + const Index max_coeff_count = 11 * 3 * 1 * 1 * 1; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -840,7 +840,7 @@ static void test_skewed_inner_dim_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 1 * 1 * 1 * 15 * 7; + const Index max_coeff_count = 1 * 1 * 1 * 15 * 7; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -856,7 +856,7 @@ static void test_skewed_inner_dim_block_shape() // and partial allocation to third inner-dim. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 11 * 5 * 5 * 1 * 1; + const Index max_coeff_count = 11 * 5 * 5 * 1 * 1; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -869,7 +869,7 @@ static void test_skewed_inner_dim_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 1 * 1 * 5 * 17 * 7; + const Index max_coeff_count = 1 * 1 * 5 * 17 * 7; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -885,7 +885,7 @@ static void test_skewed_inner_dim_block_shape() // Test shape 'SkewedInnerDims' with full allocation to all dims. if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 11 * 5 * 6 * 17 * 7; + const Index max_coeff_count = 11 * 5 * 6 * 17 * 7; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); @@ -897,7 +897,7 @@ static void test_skewed_inner_dim_block_shape() VERIFY(block.block_sizes().TotalSize() <= max_coeff_count); } else { DSizes dims(11, 5, 6, 17, 7); - const size_t max_coeff_count = 11 * 5 * 6 * 17 * 7; + const Index max_coeff_count = 11 * 5 * 6 * 17 * 7; TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); diff --git a/unsupported/test/cxx11_tensor_thread_pool.cpp b/unsupported/test/cxx11_tensor_thread_pool.cpp index 7606b0abf..6d8e58214 100644 --- a/unsupported/test/cxx11_tensor_thread_pool.cpp +++ b/unsupported/test/cxx11_tensor_thread_pool.cpp @@ -300,7 +300,7 @@ static void test_multithread_contraction_with_output_kernel() { m_result = m_left * m_right; - for (size_t i = 0; i < t_result.dimensions().TotalSize(); i++) { + for (Index i = 0; i < t_result.dimensions().TotalSize(); i++) { VERIFY(&t_result.data()[i] != &m_result.data()[i]); VERIFY_IS_APPROX(t_result.data()[i], std::sqrt(m_result.data()[i])); } -- cgit v1.2.3 From 8295f02b36bc62584b71550cd48a5c56b173ee4c Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 24 Aug 2018 23:22:20 +0200 Subject: Hide "maybe uninitialized" warning on gcc --- unsupported/test/cxx11_tensor_block_access.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 24a95ab12..74ce2cc80 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -138,8 +138,8 @@ template static void UpdateCoeffSet( const internal::TensorBlock& block, Index first_coeff_index, int dim_index, std::set* visited_coeffs) { - const DSizes block_sizes = block.block_sizes(); - const DSizes tensor_strides = block.tensor_strides(); + const DSizes& block_sizes = block.block_sizes(); + const DSizes& tensor_strides = block.tensor_strides(); for (int i = 0; i < block_sizes[dim_index]; ++i) { if (tensor_strides[dim_index] == 1) { -- cgit v1.2.3 From 42123ff38bb061a25861d3ec0f98c059d07ec4c1 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Sat, 25 Aug 2018 11:53:28 +0200 Subject: Make unit test C++03 compatible --- unsupported/test/cxx11_tensor_block_access.cpp | 59 +++++++++++++++----------- 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'unsupported/test/cxx11_tensor_block_access.cpp') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 74ce2cc80..40e6227e5 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -367,6 +367,40 @@ static void test_block_io_copy_using_reordered_dimensions() { delete[] output_data; } +template +class EqualityChecker +{ + const Scalar* input_data; + const DSizes &input_dims, &input_strides, &output_dims, &output_strides; + void check_recursive(const Scalar* input, const Scalar* output, int depth=0) const + { + if(depth==Dim) + { + VERIFY_IS_EQUAL(*input, *output); + return; + } + + for(int i=0; i &input_dims_, const DSizes &input_strides_, + const DSizes &output_dims_, const DSizes &output_strides_) + : input_data(input_data_) + , input_dims(input_dims_), input_strides(input_strides_) + , output_dims(output_dims_), output_strides(output_strides_) + {} + + void operator()(const Scalar* output_data) const + { + check_recursive(input_data, output_data); + } +}; + + template static void test_block_io_zero_stride() { @@ -398,30 +432,7 @@ static void test_block_io_zero_stride() input_tensor_strides_with_zeros[4] = 0; // Verify that data was correctly read/written from/into the block. - const auto verify_is_equal = [&](const float* output_data) { - for (int i = 0; i < output_tensor_dims[0]; ++i) { - for (int j = 0; j < output_tensor_dims[1]; ++j) { - for (int k = 0; k < output_tensor_dims[2]; ++k) { - for (int l = 0; l < output_tensor_dims[3]; ++l) { - for (int m = 0; m < output_tensor_dims[4]; ++m) { - const Index output_offset = - i * output_tensor_strides[0] + j * output_tensor_strides[1] + - k * output_tensor_strides[2] + l * output_tensor_strides[3] + - m * output_tensor_strides[4]; - const Index input_offset = - i % input_tensor_dims[0] * input_tensor_strides[0] + - j % input_tensor_dims[1] * input_tensor_strides[1] + - k % input_tensor_dims[2] * input_tensor_strides[2] + - l % input_tensor_dims[3] * input_tensor_strides[3] + - m % input_tensor_dims[4] * input_tensor_strides[4]; - VERIFY_IS_EQUAL(output_data[output_offset], - input_data[input_offset]); - } - } - } - } - } - }; + const EqualityChecker verify_is_equal(input_data, input_tensor_dims, input_tensor_strides, output_tensor_dims, output_tensor_strides); { float* output_data = new float[output_tensor_dims.TotalSize()]; -- cgit v1.2.3