@@ -5828,6 +5828,15 @@ def test_index_getset(self):
5828
5828
# If the type was incorrect, this would show up on big-endian machines
5829
5829
assert it .index == it .base .size
5830
5830
5831
+ def test_maxdims (self ):
5832
+ # The flat iterator and thus attribute is currently unfortunately
5833
+ # limited to only 32 dimensions (after bumping it to 64 for 2.0)
5834
+ a = np .ones ((1 ,) * 64 )
5835
+
5836
+ with pytest .raises (RuntimeError ,
5837
+ match = ".*32 dimensions but the array has 64" ):
5838
+ a .flat
5839
+
5831
5840
5832
5841
class TestResize :
5833
5842
@@ -7406,6 +7415,22 @@ def test_output_dtype(self, ops):
7406
7415
expected_dt = np .result_type (* ops )
7407
7416
assert (np .choose ([0 ], ops ).dtype == expected_dt )
7408
7417
7418
+ def test_dimension_and_args_limit (self ):
7419
+ # Maxdims for the legacy iterator is 32, but the maximum number
7420
+ # of arguments is actually larger (a itself also counts here)
7421
+ a = np .ones ((1 ,) * 32 , dtype = np .intp )
7422
+ res = a .choose ([0 , a ] + [2 ] * 61 )
7423
+ with pytest .raises (ValueError ,
7424
+ match = "Need at least 0 and at most 64 array objects" ):
7425
+ a .choose ([0 , a ] + [2 ] * 62 )
7426
+
7427
+ assert_array_equal (res , a )
7428
+ # Choose is unfortunately limited to 32 dims as of NumPy 2.0
7429
+ a = np .ones ((1 ,) * 60 , dtype = np .intp )
7430
+ with pytest .raises (RuntimeError ,
7431
+ match = ".*32 dimensions but the array has 60" ):
7432
+ a .choose ([a , a ])
7433
+
7409
7434
7410
7435
class TestRepeat :
7411
7436
def setup_method (self ):
0 commit comments