[llvm-branch-commits] [libcxx] 219cef0 - [libc++][mdspan] Fix layout_left::stride(r)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 7 00:06:46 PDT 2023


Author: Christian Trott
Date: 2023-08-07T09:04:26+02:00
New Revision: 219cef0881be0088c77e326eb4ab22d58bca28a5

URL: https://github.com/llvm/llvm-project/commit/219cef0881be0088c77e326eb4ab22d58bca28a5
DIFF: https://github.com/llvm/llvm-project/commit/219cef0881be0088c77e326eb4ab22d58bca28a5.diff

LOG: [libc++][mdspan] Fix layout_left::stride(r)

It was using the stride calculation of layout_right.

Reviewed By: philnik

Differential Revision: https://reviews.llvm.org/D157065

(cherry picked from commit 0f4d7d81c9d08512a3871596fa2a14b737233c80)

Added: 
    

Modified: 
    libcxx/include/__mdspan/layout_left.h
    libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__mdspan/layout_left.h b/libcxx/include/__mdspan/layout_left.h
index f890c5ae025612..7503dcf77d1379 100644
--- a/libcxx/include/__mdspan/layout_left.h
+++ b/libcxx/include/__mdspan/layout_left.h
@@ -164,7 +164,7 @@ class layout_left::mapping {
     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
         __r < extents_type::rank(), "layout_left::mapping::stride(): invalid rank index");
     index_type __s = 1;
-    for (rank_type __i = extents_type::rank() - 1; __i > __r; __i--)
+    for (rank_type __i = 0; __i < __r; __i++)
       __s *= __extents_.extent(__i);
     return __s;
   }

diff  --git a/libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp
index c10da3a0002afc..b5fc73b6fd5bfe 100644
--- a/libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp
+++ b/libcxx/test/std/containers/views/mdspan/layout_left/stride.pass.cpp
@@ -39,8 +39,8 @@ constexpr bool test() {
   constexpr size_t D = std::dynamic_extent;
   test_stride<std::extents<unsigned, D>>(std::array<unsigned, 1>{1}, 7);
   test_stride<std::extents<unsigned, 7>>(std::array<unsigned, 1>{1});
-  test_stride<std::extents<unsigned, 7, 8>>(std::array<unsigned, 2>{8, 1});
-  test_stride<std::extents<int64_t, D, 8, D, D>>(std::array<int64_t, 4>{720, 90, 10, 1}, 7, 9, 10);
+  test_stride<std::extents<unsigned, 7, 8>>(std::array<unsigned, 2>{1, 7});
+  test_stride<std::extents<int64_t, D, 8, D, D>>(std::array<int64_t, 4>{1, 7, 56, 504}, 7, 9, 10);
   return true;
 }
 


        


More information about the llvm-branch-commits mailing list