@@ -557,7 +557,7 @@ def test_fmpz_mat():
557
557
assert raises (lambda : M ([[1 ],[2 ,3 ]]), ValueError )
558
558
assert raises (lambda : M (None ), TypeError )
559
559
assert raises (lambda : M (2 ,2 ,[1 ,2 ,3 ]), ValueError )
560
- assert raises (lambda : M (2 ,2 ,2 ,2 ), ValueError )
560
+ assert raises (lambda : M (2 ,2 ,2 ,2 ), TypeError )
561
561
assert M ([[1 ,2 ,3 ],[4 ,5 ,6 ]]) == M (2 ,3 ,[1 ,2 ,3 ,4 ,5 ,6 ])
562
562
assert raises (lambda : M ([[1 ]]) < M ([[2 ]]), TypeError )
563
563
assert (M ([[1 ]]) == 1 ) is False
@@ -571,15 +571,15 @@ def test_fmpz_mat():
571
571
def set_bad (i ,j ):
572
572
D [i ,j ] = - 1
573
573
# XXX: Should be IndexError
574
- raises (lambda : set_bad (2 ,0 ), ValueError )
575
- raises (lambda : set_bad (0 ,2 ), ValueError )
576
- raises (lambda : D [0 ,2 ], ValueError )
577
- raises (lambda : D [0 ,2 ], ValueError )
574
+ raises (lambda : set_bad (2 ,0 ), IndexError )
575
+ raises (lambda : set_bad (0 ,2 ), IndexError )
576
+ raises (lambda : D [0 ,2 ], IndexError )
577
+ raises (lambda : D [0 ,2 ], IndexError )
578
578
# XXX: Negative indices?
579
- raises (lambda : set_bad (- 1 ,0 ), ValueError )
580
- raises (lambda : set_bad (0 ,- 1 ), ValueError )
581
- raises (lambda : D [- 1 ,0 ], ValueError )
582
- raises (lambda : D [0 ,- 1 ], ValueError )
579
+ raises (lambda : set_bad (- 1 ,0 ), IndexError )
580
+ raises (lambda : set_bad (0 ,- 1 ), IndexError )
581
+ raises (lambda : D [- 1 ,0 ], IndexError )
582
+ raises (lambda : D [0 ,- 1 ], IndexError )
583
583
assert M .hadamard (2 ) == M ([[1 ,1 ],[1 ,- 1 ]])
584
584
assert raises (lambda : M .hadamard (3 ), ValueError )
585
585
assert M .hadamard (2 ).is_hadamard () is True
@@ -1067,7 +1067,7 @@ def test_fmpq_mat():
1067
1067
assert raises (lambda : Q (2 ,3 ,[1 ,2 ,3 ,4 ,5 ]), ValueError )
1068
1068
assert raises (lambda : Q ([[1 ,2 ,3 ],[4 ,[],6 ]]), TypeError )
1069
1069
assert raises (lambda : Q (2 ,3 ,[1 ,2 ,3 ,4 ,[],6 ]), TypeError )
1070
- assert raises (lambda : Q (2 ,3 ,[1 ,2 ],[3 ,4 ]), ValueError )
1070
+ assert raises (lambda : Q (2 ,3 ,[1 ,2 ],[3 ,4 ]), TypeError )
1071
1071
assert bool (Q ([[1 ]])) is True
1072
1072
assert bool (Q ([[0 ]])) is False
1073
1073
assert raises (lambda : Q ([[1 ]]) < Q ([[0 ]]), TypeError )
@@ -1078,13 +1078,12 @@ def test_fmpq_mat():
1078
1078
# XXX: Negative indices should probably be allowed
1079
1079
def set_bad (i ):
1080
1080
M [i ,0 ] = - 1
1081
- raises (lambda : M [- 1 ,0 ], ValueError )
1082
- raises (lambda : M [0 ,- 1 ], ValueError )
1083
- raises (lambda : set_bad (- 1 ), ValueError )
1084
- # XXX: Should be IndexError
1085
- raises (lambda : M [2 ,0 ], ValueError )
1086
- raises (lambda : M [0 ,2 ], ValueError )
1087
- raises (lambda : set_bad (2 ), ValueError )
1081
+ raises (lambda : M [- 1 ,0 ], IndexError )
1082
+ raises (lambda : M [0 ,- 1 ], IndexError )
1083
+ raises (lambda : set_bad (- 1 ), IndexError )
1084
+ raises (lambda : M [2 ,0 ], IndexError )
1085
+ raises (lambda : M [0 ,2 ], IndexError )
1086
+ raises (lambda : set_bad (2 ), IndexError )
1088
1087
assert Q ([[1 ,2 ,3 ],[4 ,5 ,6 ]]).transpose () == Q ([[1 ,4 ],[2 ,5 ],[3 ,6 ]])
1089
1088
raises (lambda : M + [], TypeError )
1090
1089
raises (lambda : M - [], TypeError )
@@ -1488,9 +1487,12 @@ def test_nmod_mat():
1488
1487
assert A * (B * C ) == (A * B )* C
1489
1488
assert bool (M (2 ,2 ,[0 ,0 ,0 ,0 ],17 )) == False
1490
1489
assert bool (M (2 ,2 ,[0 ,0 ,0 ,1 ],17 )) == True
1491
- ctx .pretty = False
1492
- assert repr (M (2 ,2 ,[1 ,2 ,3 ,4 ],17 )) == 'nmod_mat(2, 2, [1, 2, 3, 4], 17)'
1493
- ctx .pretty = True
1490
+ pretty = ctx .pretty
1491
+ try :
1492
+ ctx .pretty = False
1493
+ assert repr (M (2 ,2 ,[1 ,2 ,3 ,4 ],17 )) == 'nmod_mat(2, 2, [1, 2, 3, 4], 17)'
1494
+ finally :
1495
+ ctx .pretty = pretty
1494
1496
assert str (M (2 ,2 ,[1 ,2 ,3 ,4 ],17 )) == '[1, 2]\n [3, 4]'
1495
1497
assert repr (M (2 ,2 ,[1 ,2 ,3 ,4 ],17 )) == '[1, 2]\n [3, 4]'
1496
1498
assert M (1 ,2 ,[3 ,4 ],17 ) / 3 == M (1 ,2 ,[3 ,4 ],17 ) * (~ G (3 ,17 ))
@@ -1504,7 +1506,7 @@ def test_nmod_mat():
1504
1506
assert raises (lambda : M (None ,17 ), TypeError )
1505
1507
assert M (2 ,3 ,17 ) == M (2 ,3 ,[0 ,0 ,0 ,0 ,0 ,0 ],17 )
1506
1508
assert raises (lambda : M (2 ,3 ,[0 ,0 ,0 ,0 ,0 ],17 ), ValueError )
1507
- assert raises (lambda : M (2 ,3 ,[0 ,1 ],[1 ,2 ],17 ), ValueError )
1509
+ assert raises (lambda : M (2 ,3 ,[0 ,1 ],[1 ,2 ],17 ), TypeError )
1508
1510
assert M ([[1 ,2 ,3 ],[4 ,5 ,6 ]], 5 ) == M (2 ,3 ,[1 ,2 ,3 ,4 ,5 ,6 ], 5 )
1509
1511
assert raises (lambda : M ([[0 ]],13 ) < M ([[1 ]],13 ), TypeError )
1510
1512
assert (M ([[1 ]],17 ) == M ([[1 ]],13 )) is False
@@ -1522,18 +1524,17 @@ def test_nmod_mat():
1522
1524
def set_bad (i ,j ):
1523
1525
M3 [i ,j ] = 2
1524
1526
# XXX: negative indices should be allowed
1525
- assert raises (lambda : M3 [- 1 ,0 ], ValueError )
1526
- assert raises (lambda : M3 [0 ,- 1 ], ValueError )
1527
- assert raises (lambda : set_bad (- 1 ,0 ), ValueError )
1528
- assert raises (lambda : set_bad (0 ,- 1 ), ValueError )
1529
- # XXX: Should be IndexError
1530
- assert raises (lambda : M3 [2 ,0 ], ValueError )
1531
- assert raises (lambda : M3 [0 ,2 ], ValueError )
1532
- assert raises (lambda : set_bad (2 ,0 ), ValueError )
1533
- assert raises (lambda : set_bad (0 ,2 ), ValueError )
1527
+ assert raises (lambda : M3 [- 1 ,0 ], IndexError )
1528
+ assert raises (lambda : M3 [0 ,- 1 ], IndexError )
1529
+ assert raises (lambda : set_bad (- 1 ,0 ), IndexError )
1530
+ assert raises (lambda : set_bad (0 ,- 1 ), IndexError )
1531
+ assert raises (lambda : M3 [2 ,0 ], IndexError )
1532
+ assert raises (lambda : M3 [0 ,2 ], IndexError )
1533
+ assert raises (lambda : set_bad (2 ,0 ), IndexError )
1534
+ assert raises (lambda : set_bad (0 ,2 ), IndexError )
1534
1535
def set_bad2 ():
1535
1536
M3 [0 ,0 ] = 1.5
1536
- assert raises (set_bad2 , ValueError )
1537
+ assert raises (set_bad2 , TypeError )
1537
1538
assert raises (lambda : M3 + [], TypeError )
1538
1539
assert raises (lambda : M3 - [], TypeError )
1539
1540
assert raises (lambda : M3 * [], TypeError )
@@ -2643,8 +2644,7 @@ def test_matrices_eq():
2643
2644
2644
2645
def test_matrices_constructor ():
2645
2646
for M , S , is_field in _all_matrices ():
2646
- # XXX: Inconsistent exception types for different matrix types.
2647
- assert raises (lambda : M (), (ValueError , TypeError ))
2647
+ assert raises (lambda : M (), TypeError )
2648
2648
2649
2649
# Empty matrices
2650
2650
assert M ([]).nrows () == 0
@@ -2720,13 +2720,8 @@ def test_matrices_strrepr():
2720
2720
A_str = "[1, 2]\n [3, 4]"
2721
2721
A_repr = _matrix_repr (A )
2722
2722
2723
- # XXX: inconsistent repr/str for different matrix types
2724
- if type (A ) is not flint .nmod_mat :
2725
- assert A .str () == A_str , type (A ).__name__
2726
- if type (A ) not in (flint .fmpz_mat , flint .fmpq_mat ):
2727
- assert A .repr () == A_repr , type (A ).__name__
2728
- else :
2729
- assert A .repr () == A_str , type (A ).__name__
2723
+ assert A .str () == A_str , type (A ).__name__
2724
+ assert A .repr () == A_repr , type (A ).__name__
2730
2725
2731
2726
# str always returns a pretty result
2732
2727
assert str (A ) == A_str , type (A ).__name__
@@ -2749,14 +2744,13 @@ def test_matrices_getitem():
2749
2744
assert M1234 [0 , 1 ] == S (2 )
2750
2745
assert M1234 [1 , 0 ] == S (3 )
2751
2746
assert M1234 [1 , 1 ] == S (4 )
2752
- # XXX: Should be IndexError
2753
- assert raises (lambda : M1234 [0 , 2 ], ValueError )
2754
- assert raises (lambda : M1234 [2 , 0 ], ValueError )
2755
- assert raises (lambda : M1234 [2 , 2 ], ValueError )
2747
+ assert raises (lambda : M1234 [0 , 2 ], IndexError )
2748
+ assert raises (lambda : M1234 [2 , 0 ], IndexError )
2749
+ assert raises (lambda : M1234 [2 , 2 ], IndexError )
2756
2750
# XXX: Should negative indices be allowed?
2757
- assert raises (lambda : M1234 [- 1 , 0 ], ValueError )
2758
- assert raises (lambda : M1234 [0 , - 1 ], ValueError )
2759
- assert raises (lambda : M1234 [- 1 , - 1 ], ValueError )
2751
+ assert raises (lambda : M1234 [- 1 , 0 ], IndexError )
2752
+ assert raises (lambda : M1234 [0 , - 1 ], IndexError )
2753
+ assert raises (lambda : M1234 [- 1 , - 1 ], IndexError )
2760
2754
2761
2755
2762
2756
def test_matrices_setitem ():
@@ -2770,19 +2764,19 @@ def test_matrices_setitem():
2770
2764
2771
2765
def setbad (obj , key , val ):
2772
2766
obj [key ] = val
2773
- # XXX: Inconsistent exception types for different matrix types.
2774
- assert raises (lambda : setbad (M1234 , (0 ,0 ), None ), ( TypeError , ValueError ) )
2767
+
2768
+ assert raises (lambda : setbad (M1234 , (0 ,0 ), None ), TypeError )
2775
2769
assert raises (lambda : setbad (M1234 , (0 ,None ), 1 ), TypeError )
2776
2770
assert raises (lambda : setbad (M1234 , (None ,0 ), 1 ), TypeError )
2777
2771
assert raises (lambda : setbad (M1234 , None , 1 ), TypeError )
2778
- # XXX: Should be IndexError
2779
- assert raises (lambda : setbad (M1234 , (0 ,2 ), 1 ), ValueError )
2780
- assert raises (lambda : setbad (M1234 , (2 ,0 ), 1 ), ValueError )
2781
- assert raises (lambda : setbad (M1234 , (2 ,2 ), 1 ), ValueError )
2772
+
2773
+ assert raises (lambda : setbad (M1234 , (0 ,2 ), 1 ), IndexError )
2774
+ assert raises (lambda : setbad (M1234 , (2 ,0 ), 1 ), IndexError )
2775
+ assert raises (lambda : setbad (M1234 , (2 ,2 ), 1 ), IndexError )
2782
2776
# XXX: Should negative indices be allowed?
2783
- assert raises (lambda : setbad (M1234 , (- 1 ,0 ), 1 ), ValueError )
2784
- assert raises (lambda : setbad (M1234 , (0 ,- 1 ), 1 ), ValueError )
2785
- assert raises (lambda : setbad (M1234 , (- 1 ,- 1 ), 1 ), ValueError )
2777
+ assert raises (lambda : setbad (M1234 , (- 1 ,0 ), 1 ), IndexError )
2778
+ assert raises (lambda : setbad (M1234 , (0 ,- 1 ), 1 ), IndexError )
2779
+ assert raises (lambda : setbad (M1234 , (- 1 ,- 1 ), 1 ), IndexError )
2786
2780
2787
2781
2788
2782
def test_matrices_bool ():
@@ -2819,7 +2813,6 @@ def test_matrices_add():
2819
2813
assert raises (lambda : M1234 + M2 ([[1 , 2 , 3 ], [4 , 5 , 6 ]]), ValueError )
2820
2814
assert raises (lambda : M2 ([[1 , 2 , 3 ], [4 , 5 , 6 ]]) + M1234 , ValueError )
2821
2815
for M2 in _incompatible_matrix_types (M ):
2822
- # XXX: Inconsistent exception types for different matrix types.
2823
2816
assert raises (lambda : M1234 + M2 ([[1 , 2 ], [3 , 4 ]]), (TypeError , ValueError ))
2824
2817
assert raises (lambda : M2 ([[1 , 2 ], [3 , 4 ]]) + M1234 , (TypeError , ValueError ))
2825
2818
@@ -2840,7 +2833,6 @@ def test_matrices_sub():
2840
2833
assert raises (lambda : M1234 - M2 ([[1 , 2 , 3 ], [4 , 5 , 6 ]]), ValueError )
2841
2834
assert raises (lambda : M2 ([[1 , 2 , 3 ], [4 , 5 , 6 ]]) - M1234 , ValueError )
2842
2835
for M2 in _incompatible_matrix_types (M ):
2843
- # XXX: Inconsistent exception types for different matrix types.
2844
2836
assert raises (lambda : M1234 - M2 ([[1 , 2 ], [3 , 4 ]]), (TypeError , ValueError ))
2845
2837
assert raises (lambda : M2 ([[1 , 2 ], [3 , 4 ]]) - M1234 , (TypeError , ValueError ))
2846
2838
@@ -2867,17 +2859,13 @@ def test_matrices_mul():
2867
2859
assert M2 ([[1 , 2 ], [3 , 4 ]]) * M1234 == M ([[7 , 10 ], [15 , 22 ]])
2868
2860
2869
2861
for M2 in _incompatible_matrix_types (M ):
2870
- # XXX: Inconsistent exception types for different matrix types.
2871
2862
assert raises (lambda : M1234 * M2 ([[1 , 2 ], [3 , 4 ]]), (TypeError , ValueError ))
2872
2863
assert raises (lambda : M2 ([[1 , 2 ], [3 , 4 ]]) * M1234 , (TypeError , ValueError ))
2873
2864
2874
2865
2875
2866
def test_matrices_pow ():
2876
2867
for M , S , is_field in _all_matrices ():
2877
2868
M1234 = M ([[1 , 2 ], [3 , 4 ]])
2878
- # XXX: nmod_mat should support __pow__
2879
- if type (M1234 ) is flint .nmod_mat :
2880
- continue
2881
2869
assert M1234 ** 0 == M ([[1 , 0 ], [0 , 1 ]])
2882
2870
assert M1234 ** 1 == M1234
2883
2871
assert M1234 ** 2 == M ([[7 , 10 ], [15 , 22 ]])
@@ -2889,15 +2877,9 @@ def test_matrices_pow():
2889
2877
Ms = M ([[1 , 2 ], [3 , 6 ]])
2890
2878
assert raises (lambda : Ms ** - 1 , ZeroDivisionError )
2891
2879
Mr = M ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
2892
- # XXX: Fix fmpq_mat.__pow__
2893
- if type (Mr ) is flint .fmpq_mat :
2894
- assert raises (lambda : Mr ** 0 , AssertionError )
2895
- assert Mr ** 1 == Mr
2896
- assert raises (lambda : Mr ** 2 , ValueError )
2897
- else :
2898
- assert raises (lambda : Mr ** 0 , ValueError )
2899
- assert raises (lambda : Mr ** 1 , ValueError )
2900
- assert raises (lambda : Mr ** 2 , ValueError )
2880
+ assert raises (lambda : Mr ** 0 , ValueError )
2881
+ assert raises (lambda : Mr ** 1 , ValueError )
2882
+ assert raises (lambda : Mr ** 2 , ValueError )
2901
2883
assert raises (lambda : M1234 ** None , TypeError )
2902
2884
assert raises (lambda : None ** M1234 , TypeError )
2903
2885
@@ -2938,41 +2920,28 @@ def test_matrices_det():
2938
2920
2939
2921
def test_matrices_charpoly ():
2940
2922
for M , S , is_field in _all_matrices ():
2941
- # XXX: Add support for nmod_mat charpoly
2942
- if type (M ([[0 ]])) is flint .nmod_mat :
2943
- continue
2944
2923
P = _poly_type_from_matrix_type (M )
2945
2924
M1234 = M ([[1 , 2 ], [3 , 4 ]])
2946
2925
assert M1234 .charpoly () == P ([- 2 , - 5 , 1 ])
2947
2926
M9 = M ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 10 ]])
2948
2927
assert M9 .charpoly () == P ([3 , - 12 , - 16 , 1 ])
2949
2928
Mr = M ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
2950
- # XXX: Fix fmpz_mat and fmpq_mat charpoly to not abort
2951
- if M is not flint .fmpz_mat and M is not flint .fmpq_mat :
2952
- assert raises (lambda : Mr .charpoly (), ValueError )
2929
+ assert raises (lambda : Mr .charpoly (), ValueError )
2953
2930
2954
2931
2955
2932
def test_matrices_minpoly ():
2956
2933
for M , S , is_field in _all_matrices ():
2957
- # XXX: Add support for nmod_mat minpoly
2958
- if type (M ([[0 ]])) is flint .nmod_mat :
2959
- continue
2960
2934
P = _poly_type_from_matrix_type (M )
2961
2935
M1234 = M ([[1 , 2 ], [3 , 4 ]])
2962
2936
assert M1234 .minpoly () == P ([- 2 , - 5 , 1 ])
2963
2937
M9 = M ([[2 , 1 , 0 ], [0 , 2 , 0 ], [0 , 0 , 2 ]])
2964
2938
assert M9 .minpoly () == P ([4 , - 4 , 1 ])
2965
2939
Mr = M ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
2966
- # XXX: Fix fmpz_mat and fmpq_mat minpoly to not abort
2967
- if M is not flint .fmpz_mat and M is not flint .fmpq_mat :
2968
- assert raises (lambda : Mr .minpoly (), ValueError )
2940
+ assert raises (lambda : Mr .minpoly (), ValueError )
2969
2941
2970
2942
2971
2943
def test_matrices_rank ():
2972
2944
for M , S , is_field in _all_matrices ():
2973
- # XXX: fmpq_mat doesn't support rank
2974
- if M is flint .fmpq_mat :
2975
- continue
2976
2945
M1234 = M ([[1 , 2 ], [3 , 4 ]])
2977
2946
assert M1234 .rank () == 2
2978
2947
Mr = M ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
0 commit comments