From d36a7db7b510d154c98fa030c11c35853c675a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 3 Mar 2026 22:15:47 +0000 Subject: [PATCH] Fix Eigen::array constructors. libeigen/eigen!2235 --- unsupported/Eigen/src/Tensor/README.md | 20 +++++++++---------- unsupported/test/cxx11_tensor_contraction.cpp | 4 ++-- .../test/cxx11_tensor_of_bfloat16_gpu.cu | 2 +- unsupported/test/cxx11_tensor_thread_pool.cpp | 18 ++++++++--------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/unsupported/Eigen/src/Tensor/README.md b/unsupported/Eigen/src/Tensor/README.md index 9a3934395..52ace7c89 100644 --- a/unsupported/Eigen/src/Tensor/README.md +++ b/unsupported/Eigen/src/Tensor/README.md @@ -1297,7 +1297,7 @@ Example: Reduction along one dimension. Eigen::Tensor a(2, 3); a.setValues({{1, 2, 3}, {6, 5, 4}}); // Reduce it along the second dimension (1)... -Eigen::array dims({1 /* dimension to reduce */}); +Eigen::array dims{1 /* dimension to reduce */}; // ...using the "maximum" operator. // The result is a tensor with one dimension. The size of // that dimension is the same as the first (non-reduced) dimension of a. @@ -1328,7 +1328,7 @@ a.setValues({{{0.0f, 1.0f, 2.0f, 3.0f}, // Note that we pass the array of reduction dimensions // directly to the maximum() call. Eigen::Tensor b = - a.maximum(Eigen::array({0, 1})); + a.maximum(Eigen::array{0, 1}); std::cout << "b" << endl << b << endl << endl; // b @@ -1475,7 +1475,7 @@ a.setValues({{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}}); // Specify the dimensions along which the trace will be computed. // In this example, the trace can only be computed along the dimensions // with indices 0 and 1 -Eigen::array dims({0, 1}); +Eigen::array dims{0, 1}; // The output tensor contains all but the trace dimensions. Tensor a_trace = a.trace(dims); std::cout << "a_trace:" << endl; @@ -1572,7 +1572,7 @@ Tensor output(3, 2, 6, 11); input.setRandom(); kernel.setRandom(); -Eigen::array dims({1, 2}); // Specify second and third dimension for convolution. +Eigen::array dims{1, 2}; // Specify second and third dimension for convolution. output = input.convolve(kernel, dims); for (int i = 0; i < 3; ++i) { @@ -1630,7 +1630,7 @@ to one dimension: ```cpp Eigen::Tensor a(2, 3); a.setValues({{0.0f, 100.0f, 200.0f}, {300.0f, 400.0f, 500.0f}}); -Eigen::array one_dim({3 * 2}); +Eigen::array one_dim{3 * 2}; Eigen::Tensor b = a.reshape(one_dim); std::cout << "b" << endl << b << endl; @@ -1648,7 +1648,7 @@ This is what happens when the 2D `Tensor` is `RowMajor`: ```cpp Eigen::Tensor a(2, 3); a.setValues({{0.0f, 100.0f, 200.0f}, {300.0f, 400.0f, 500.0f}}); -Eigen::array one_dim({3 * 2}); +Eigen::array one_dim{3 * 2}; Eigen::Tensor b = a.reshape(one_dim); std::cout << "b" << endl << b << endl; @@ -1669,7 +1669,7 @@ The previous example can be rewritten as follow: ```cpp Eigen::Tensor a(2, 3); a.setValues({{0.0f, 100.0f, 200.0f}, {300.0f, 400.0f, 500.0f}}); -Eigen::array two_dim({2, 3}); +Eigen::array two_dim{2, 3}; Eigen::Tensor b(6); b.reshape(two_dim) = a; std::cout << "b" << endl << b << endl; @@ -1747,7 +1747,7 @@ a.setValues({{0, 100, 200}, {300, 400, 500}, {600, 700, 800}, {900, 1000, 1100}}); -Eigen::array strides({3, 2}); +Eigen::array strides{3, 2}; Eigen::Tensor b = a.stride(strides); std::cout << "b" << endl << b << endl; // b @@ -1934,7 +1934,7 @@ of a 2D tensor: Eigen::Tensor a(4, 3); a.setValues({{0, 100, 200}, {300, 400, 500}, {600, 700, 800}, {900, 1000, 1100}}); -Eigen::array reverse({true, false}); +Eigen::array reverse{true, false}; Eigen::Tensor b = a.reverse(reverse); std::cout << "a\n" << a << "\n"; std::cout << "b\n" << b << "\n"; @@ -1994,7 +1994,7 @@ made in each of the dimensions. ```cpp Eigen::Tensor a(2, 3); a.setValues({{0, 100, 200}, {300, 400, 500}}); -Eigen::array bcast({3, 2}); +Eigen::array bcast{3, 2}; Eigen::Tensor b = a.broadcast(bcast); std::cout << "a" << endl << a << endl << "b" << endl << b << endl; // a diff --git a/unsupported/test/cxx11_tensor_contraction.cpp b/unsupported/test/cxx11_tensor_contraction.cpp index c9fabce0e..9bf7ec69b 100644 --- a/unsupported/test/cxx11_tensor_contraction.cpp +++ b/unsupported/test/cxx11_tensor_contraction.cpp @@ -139,7 +139,7 @@ static void test_multidims() { Tensor mat6(2); mat6.setZero(); - Eigen::array dims2({{DimPair(0, 1), DimPair(1, 0)}}); + Eigen::array dims2{{DimPair(0, 1), DimPair(1, 0)}}; typedef TensorEvaluator Evaluator2; Evaluator2 eval2(mat4.contract(mat5, dims2), DefaultDevice()); eval2.evalTo(mat6.data()); @@ -515,7 +515,7 @@ static void test_large_contraction_with_output_kernel() { Eigen::Matrix m_result(1500, 1400); // this contraction should be equivalent to a single matrix multiplication - Eigen::array dims({{DimPair(2, 0), DimPair(3, 1)}}); + Eigen::array dims{{DimPair(2, 0), DimPair(3, 1)}}; // compute results by separate methods t_result = t_left.contract(t_right, dims, SqrtOutputKernel()); diff --git a/unsupported/test/cxx11_tensor_of_bfloat16_gpu.cu b/unsupported/test/cxx11_tensor_of_bfloat16_gpu.cu index 4f171ff39..599a1309c 100644 --- a/unsupported/test/cxx11_tensor_of_bfloat16_gpu.cu +++ b/unsupported/test/cxx11_tensor_of_bfloat16_gpu.cu @@ -278,7 +278,7 @@ void test_gpu_contractions() { gpu_float2.device(gpu_device) = gpu_float2.random() - gpu_float2.constant(0.5f); typedef Tensor::DimensionPair DimPair; - Eigen::array dims(DimPair(1, 0)); + Eigen::array dims{DimPair(1, 0)}; gpu_res_float.device(gpu_device) = gpu_float1.contract(gpu_float2, dims).cast(); gpu_res_bfloat16.device(gpu_device) = gpu_float1.cast().contract(gpu_float2.cast(), dims); diff --git a/unsupported/test/cxx11_tensor_thread_pool.cpp b/unsupported/test/cxx11_tensor_thread_pool.cpp index 0072bf0dd..d1645ee5b 100644 --- a/unsupported/test/cxx11_tensor_thread_pool.cpp +++ b/unsupported/test/cxx11_tensor_thread_pool.cpp @@ -193,7 +193,7 @@ void test_multithread_contraction() { // this contraction should be equivalent to a single matrix multiplication typedef Tensor::DimensionPair DimPair; - Eigen::array dims({{DimPair(2, 0), DimPair(3, 1)}}); + Eigen::array dims{{DimPair(2, 0), DimPair(3, 1)}}; typedef Map> MapXf; MapXf m_left(t_left.data(), 1500, 1147); @@ -324,7 +324,7 @@ void test_multithread_contraction_agrees_with_singlethread() { right += right.constant(1.5f); typedef Tensor::DimensionPair DimPair; - Eigen::array dims({{DimPair(1, 2)}}); + Eigen::array dims{{DimPair(1, 2)}}; Eigen::ThreadPool tp(internal::random(2, 11)); Eigen::ThreadPoolDevice thread_pool_device(&tp, internal::random(2, 11)); @@ -386,7 +386,7 @@ static void test_multithread_contraction_with_output_kernel() { Eigen::Matrix m_result(1500, 1400); // this contraction should be equivalent to a single matrix multiplication - Eigen::array dims({{DimPair(2, 0), DimPair(3, 1)}}); + Eigen::array dims{{DimPair(2, 0), DimPair(3, 1)}}; // compute results by separate methods t_result.device(device) = t_left.contract(t_right, dims, SqrtOutputKernel()); @@ -416,7 +416,7 @@ void test_async_multithread_contraction_agrees_with_singlethread() { right += right.constant(1.5f); typedef Tensor::DimensionPair DimPair; - Eigen::array dims({{DimPair(1, 2)}}); + Eigen::array dims{{DimPair(1, 2)}}; Eigen::ThreadPool tp(internal::random(2, 11)); Eigen::ThreadPoolDevice thread_pool_device(&tp, internal::random(8, 32)); @@ -468,7 +468,7 @@ static void test_sharded_by_inner_dim_contraction() { Eigen::Matrix m_result(2, 10); // this contraction should be equivalent to a single matrix multiplication - Eigen::array dims({{DimPair(1, 0)}}); + Eigen::array dims{{DimPair(1, 0)}}; // compute results by separate methods t_result.device(device) = t_left.contract(t_right, dims); @@ -507,7 +507,7 @@ static void test_sharded_by_inner_dim_contraction_with_output_kernel() { Eigen::Matrix m_result(2, 10); // this contraction should be equivalent to a single matrix multiplication - Eigen::array dims({{DimPair(1, 0)}}); + Eigen::array dims{{DimPair(1, 0)}}; // compute results by separate methods t_result.device(device) = t_left.contract(t_right, dims, SqrtOutputKernel()); @@ -546,7 +546,7 @@ static void test_async_sharded_by_inner_dim_contraction() { Eigen::Matrix m_result(2, 10); // this contraction should be equivalent to a single matrix multiplication - Eigen::array dims({{DimPair(1, 0)}}); + Eigen::array dims{{DimPair(1, 0)}}; // compute results by separate methods Eigen::Barrier barrier(1); @@ -588,7 +588,7 @@ static void test_async_sharded_by_inner_dim_contraction_with_output_kernel() { Eigen::Matrix m_result(2, 10); // this contraction should be equivalent to a single matrix multiplication - Eigen::array dims({{DimPair(1, 0)}}); + Eigen::array dims{{DimPair(1, 0)}}; // compute results by separate methods Eigen::Barrier barrier(1); @@ -616,7 +616,7 @@ void test_full_contraction() { right += right.constant(1.5f); typedef Tensor::DimensionPair DimPair; - Eigen::array dims({{DimPair(0, 0), DimPair(1, 1)}}); + Eigen::array dims{{DimPair(0, 0), DimPair(1, 1)}}; Eigen::ThreadPool tp(internal::random(2, 11)); Eigen::ThreadPoolDevice thread_pool_device(&tp, internal::random(2, 11));