@@ -965,154 +965,3 @@ def test_eq_reflexive_and_value_equality():
965965 assert a == a
966966 assert a == b
967967 assert a != c
968-
969-
970- def test_dense_like_invalid_stride_order_raises ():
971- """dense_like rejects a stride_order that is not 'K'/'C'/'F' or a permutation."""
972- layout = _StridedLayout .dense ((5 , 4 ), 4 )
973- with pytest .raises (ValueError , match = "must be 'K', 'C', 'F', or a permutation" ):
974- _StridedLayout .dense_like (layout , "X" )
975-
976-
977- def test_repr_includes_slice_offset_when_nonzero ():
978- """__repr__ renders the _slice_offset field only when the slice offset != 0."""
979- dense = _StridedLayout .dense ((5 , 6 ), 4 )
980- assert "_slice_offset" not in repr (dense )
981- sliced = dense [:, 1 :5 ]
982- assert sliced .slice_offset != 0
983- assert "_slice_offset" in repr (sliced )
984-
985-
986- def test_min_offset_max_offset_properties ():
987- """The min_offset / max_offset scalar properties match offset_bounds."""
988- layout = _StridedLayout .dense ((5 , 4 ), 4 )
989- assert layout .min_offset == 0
990- assert layout .max_offset == 19 # volume 20 -> last element at offset 19
991- assert (layout .min_offset , layout .max_offset ) == layout .offset_bounds
992-
993-
994- def test_broadcast_to_fewer_dims_raises ():
995- """broadcast_to rejects a target shape with fewer dims than the source."""
996- layout = _StridedLayout .dense ((2 , 3 ), 4 )
997- with pytest .raises (ValueError , match = "must be greater than or equal to" ):
998- layout .broadcast_to ((3 ,))
999-
1000-
1001- def test_broadcast_to_incompatible_extent_raises ():
1002- """broadcast_to rejects an extent that is neither 1 nor equal to the target."""
1003- layout = _StridedLayout .dense ((2 , 3 ), 4 )
1004- with pytest .raises (ValueError , match = "cannot be broadcast together" ):
1005- layout .broadcast_to ((2 , 5 ))
1006-
1007-
1008- def test_unsqueezed_invalid_axis_raises ():
1009- """unsqueezed rejects an axis outside the resulting rank."""
1010- layout = _StridedLayout .dense ((2 , 3 ), 4 )
1011- with pytest .raises (ValueError , match = "Invalid axis" ):
1012- layout .unsqueezed (9 )
1013-
1014-
1015- def test_unsqueezed_repeated_axis_raises ():
1016- """unsqueezed rejects the same new axis specified twice."""
1017- layout = _StridedLayout .dense ((2 , 3 ), 4 )
1018- with pytest .raises (ValueError , match = "appears multiple times" ):
1019- layout .unsqueezed ((0 , 0 ))
1020-
1021-
1022- def test_repacked_pack_invalid_axis_raises ():
1023- """repacked (packing) rejects an out-of-range axis."""
1024- layout = _StridedLayout .dense ((5 , 4 ), 4 )
1025- with pytest .raises (ValueError , match = "Invalid axis" ):
1026- layout .repacked (8 , axis = 5 )
1027-
1028-
1029- def test_repacked_pack_unaligned_data_ptr_raises ():
1030- """repacked (packing) requires data_ptr aligned to the packed itemsize."""
1031- layout = _StridedLayout .dense ((5 , 4 ), 4 )
1032- with pytest .raises (ValueError , match = "must be aligned to the packed itemsize" ):
1033- layout .repacked (8 , data_ptr = 4 )
1034-
1035-
1036- def test_repacked_pack_axis_stride_not_one_raises ():
1037- """repacked (packing) requires the packed axis stride to be 1."""
1038- layout = _StridedLayout ((4 , 5 ), (5 , 1 ), 4 )
1039- with pytest .raises (ValueError , match = "axis 0 stride must be 1" ):
1040- layout .repacked (8 , axis = 0 )
1041-
1042-
1043- def test_repacked_pack_extent_not_divisible_raises ():
1044- """repacked (packing) requires the packed axis extent divisible by vec_size."""
1045- layout = _StridedLayout .dense ((5 , 3 ), 4 )
1046- with pytest .raises (ValueError , match = "extent .* must be divisible by 2" ):
1047- layout .repacked (8 , axis = 1 )
1048-
1049-
1050- def test_repacked_pack_slice_offset_not_divisible_raises ():
1051- """repacked (packing) requires the slice offset divisible by vec_size."""
1052- layout = _StridedLayout .dense ((5 , 6 ), 4 )[:, 1 :5 ]
1053- assert layout .slice_offset == 1
1054- with pytest .raises (ValueError , match = "slice offset .* must be divisible by 2" ):
1055- layout .repacked (8 , axis = 1 )
1056-
1057-
1058- def test_repacked_pack_other_stride_not_divisible_raises ():
1059- """repacked (packing) requires non-packed strides divisible by vec_size."""
1060- layout = _StridedLayout ((3 , 4 ), (5 , 1 ), 4 )
1061- with pytest .raises (ValueError , match = "stride .* must be divisible by 2" ):
1062- layout .repacked (8 , axis = 1 )
1063-
1064-
1065- def test_repacked_unpack_invalid_axis_raises ():
1066- """repacked (unpacking) rejects an out-of-range axis."""
1067- layout = _StridedLayout .dense ((5 , 4 ), 8 )
1068- with pytest .raises (ValueError , match = "Invalid axis" ):
1069- layout .repacked (4 , axis = 9 )
1070-
1071-
1072- def test_repacked_unpack_nonpositive_itemsize_raises ():
1073- """repacked (unpacking) requires a positive new itemsize."""
1074- layout = _StridedLayout .dense ((5 , 4 ), 8 )
1075- with pytest .raises (ValueError , match = "new itemsize must be greater than zero" ):
1076- layout .repacked (0 )
1077-
1078-
1079- def test_repacked_unpack_zero_extent_raises ():
1080- """repacked (unpacking) rejects a zero extent on the unpacked axis."""
1081- layout = _StridedLayout ((5 , 0 ), (0 , 1 ), 8 )
1082- with pytest .raises (ValueError , match = "extent must be non-zero" ):
1083- layout .repacked (4 , axis = 1 )
1084-
1085-
1086- def test_repacked_unpack_axis_stride_not_one_raises ():
1087- """repacked (unpacking) requires the unpacked axis stride to be 1."""
1088- layout = _StridedLayout ((4 , 5 ), (5 , 1 ), 8 )
1089- with pytest .raises (ValueError , match = "axis 0 stride must be 1" ):
1090- layout .repacked (4 , axis = 0 )
1091-
1092-
1093- def test_max_compatible_itemsize_nonpositive_max_raises ():
1094- """max_compatible_itemsize requires a positive max_itemsize."""
1095- layout = _StridedLayout .dense ((5 , 4 ), 4 )
1096- with pytest .raises (ValueError , match = "max_itemsize must be greater than zero" ):
1097- layout .max_compatible_itemsize (max_itemsize = 0 )
1098-
1099-
1100- def test_max_compatible_itemsize_invalid_axis_raises ():
1101- """max_compatible_itemsize rejects an out-of-range axis."""
1102- layout = _StridedLayout .dense ((5 , 4 ), 4 )
1103- with pytest .raises (ValueError , match = "Invalid axis" ):
1104- layout .max_compatible_itemsize (axis = 9 )
1105-
1106-
1107- def test_max_compatible_itemsize_max_below_itemsize_raises ():
1108- """max_compatible_itemsize rejects max_itemsize smaller than the itemsize."""
1109- layout = _StridedLayout .dense ((5 , 4 ), 8 )
1110- with pytest .raises (ValueError , match = "cannot be less than itemsize" ):
1111- layout .max_compatible_itemsize (max_itemsize = 4 )
1112-
1113-
1114- def test_max_compatible_itemsize_axis_stride_not_one_returns_itemsize ():
1115- """When the axis stride is not 1, max_compatible_itemsize returns the
1116- current itemsize unchanged (no larger pack is possible)."""
1117- layout = _StridedLayout ((4 , 5 ), (5 , 1 ), 8 )
1118- assert layout .max_compatible_itemsize (axis = 0 , max_itemsize = 16 ) == 8
0 commit comments