@@ -995,6 +995,167 @@ def test_transpose(code: str, latex: str) -> None:
995
995
assert expression_codegen .ExpressionCodegen ().visit (tree ) == latex
996
996
997
997
998
+ @pytest .mark .parametrize (
999
+ "code,latex" ,
1000
+ [
1001
+ ("det(A)" , r"\det \mathopen{}\left( \mathbf{A} \mathclose{}\right)" ),
1002
+ ("det(b)" , r"\det \mathopen{}\left( \mathbf{b} \mathclose{}\right)" ),
1003
+ (
1004
+ "det([[1, 2], [3, 4]])" ,
1005
+ r"\det \mathopen{}\left( \begin{bmatrix} 1 & 2 \\"
1006
+ r" 3 & 4 \end{bmatrix} \mathclose{}\right)" ,
1007
+ ),
1008
+ (
1009
+ "det([[1, 2, 3], [4, 5, 6], [7, 8, 9]])" ,
1010
+ r"\det \mathopen{}\left( \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\"
1011
+ r" 7 & 8 & 9 \end{bmatrix} \mathclose{}\right)" ,
1012
+ ),
1013
+ # Unsupported
1014
+ ("det()" , r"\mathrm{det} \mathopen{}\left( \mathclose{}\right)" ),
1015
+ ("det(2)" , r"\mathrm{det} \mathopen{}\left( 2 \mathclose{}\right)" ),
1016
+ (
1017
+ "det(a, (1, 0))" ,
1018
+ r"\mathrm{det} \mathopen{}\left( a, "
1019
+ r"\mathopen{}\left( 1, 0 \mathclose{}\right) \mathclose{}\right)" ,
1020
+ ),
1021
+ ],
1022
+ )
1023
+ def test_determinant (code : str , latex : str ) -> None :
1024
+ tree = ast_utils .parse_expr (code )
1025
+ assert isinstance (tree , ast .Call )
1026
+ assert expression_codegen .ExpressionCodegen ().visit (tree ) == latex
1027
+
1028
+
1029
+ @pytest .mark .parametrize (
1030
+ "code,latex" ,
1031
+ [
1032
+ (
1033
+ "matrix_rank(A)" ,
1034
+ r"\mathrm{rank} \mathopen{}\left( \mathbf{A} \mathclose{}\right)" ,
1035
+ ),
1036
+ (
1037
+ "matrix_rank(b)" ,
1038
+ r"\mathrm{rank} \mathopen{}\left( \mathbf{b} \mathclose{}\right)" ,
1039
+ ),
1040
+ (
1041
+ "matrix_rank([[1, 2], [3, 4]])" ,
1042
+ r"\mathrm{rank} \mathopen{}\left( \begin{bmatrix} 1 & 2 \\"
1043
+ r" 3 & 4 \end{bmatrix} \mathclose{}\right)" ,
1044
+ ),
1045
+ (
1046
+ "matrix_rank([[1, 2, 3], [4, 5, 6], [7, 8, 9]])" ,
1047
+ r"\mathrm{rank} \mathopen{}\left( \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\"
1048
+ r" 7 & 8 & 9 \end{bmatrix} \mathclose{}\right)" ,
1049
+ ),
1050
+ # Unsupported
1051
+ (
1052
+ "matrix_rank()" ,
1053
+ r"\mathrm{matrix\_rank} \mathopen{}\left( \mathclose{}\right)" ,
1054
+ ),
1055
+ (
1056
+ "matrix_rank(2)" ,
1057
+ r"\mathrm{matrix\_rank} \mathopen{}\left( 2 \mathclose{}\right)" ,
1058
+ ),
1059
+ (
1060
+ "matrix_rank(a, (1, 0))" ,
1061
+ r"\mathrm{matrix\_rank} \mathopen{}\left( a, "
1062
+ r"\mathopen{}\left( 1, 0 \mathclose{}\right) \mathclose{}\right)" ,
1063
+ ),
1064
+ ],
1065
+ )
1066
+ def test_matrix_rank (code : str , latex : str ) -> None :
1067
+ tree = ast_utils .parse_expr (code )
1068
+ assert isinstance (tree , ast .Call )
1069
+ assert expression_codegen .ExpressionCodegen ().visit (tree ) == latex
1070
+
1071
+
1072
+ @pytest .mark .parametrize (
1073
+ "code,latex" ,
1074
+ [
1075
+ ("matrix_power(A, 2)" , r"\mathbf{A}^{2}" ),
1076
+ ("matrix_power(b, 2)" , r"\mathbf{b}^{2}" ),
1077
+ (
1078
+ "matrix_power([[1, 2], [3, 4]], 2)" ,
1079
+ r"\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}^{2}" ,
1080
+ ),
1081
+ (
1082
+ "matrix_power([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 42)" ,
1083
+ r"\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}^{42}" ,
1084
+ ),
1085
+ # Unsupported
1086
+ (
1087
+ "matrix_power()" ,
1088
+ r"\mathrm{matrix\_power} \mathopen{}\left( \mathclose{}\right)" ,
1089
+ ),
1090
+ (
1091
+ "matrix_power(2)" ,
1092
+ r"\mathrm{matrix\_power} \mathopen{}\left( 2 \mathclose{}\right)" ,
1093
+ ),
1094
+ (
1095
+ "matrix_power(a, (1, 0))" ,
1096
+ r"\mathrm{matrix\_power} \mathopen{}\left( a, "
1097
+ r"\mathopen{}\left( 1, 0 \mathclose{}\right) \mathclose{}\right)" ,
1098
+ ),
1099
+ ],
1100
+ )
1101
+ def test_matrix_power (code : str , latex : str ) -> None :
1102
+ tree = ast_utils .parse_expr (code )
1103
+ assert isinstance (tree , ast .Call )
1104
+ assert expression_codegen .ExpressionCodegen ().visit (tree ) == latex
1105
+
1106
+
1107
+ @pytest .mark .parametrize (
1108
+ "code,latex" ,
1109
+ [
1110
+ ("inv(A)" , r"\mathbf{A}^{-1}" ),
1111
+ ("inv(b)" , r"\mathbf{b}^{-1}" ),
1112
+ ("inv([[1, 2], [3, 4]])" , r"\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}^{-1}" ),
1113
+ (
1114
+ "inv([[1, 2, 3], [4, 5, 6], [7, 8, 9]])" ,
1115
+ r"\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}^{-1}" ,
1116
+ ),
1117
+ # Unsupported
1118
+ ("inv()" , r"\mathrm{inv} \mathopen{}\left( \mathclose{}\right)" ),
1119
+ ("inv(2)" , r"\mathrm{inv} \mathopen{}\left( 2 \mathclose{}\right)" ),
1120
+ (
1121
+ "inv(a, (1, 0))" ,
1122
+ r"\mathrm{inv} \mathopen{}\left( a, "
1123
+ r"\mathopen{}\left( 1, 0 \mathclose{}\right) \mathclose{}\right)" ,
1124
+ ),
1125
+ ],
1126
+ )
1127
+ def test_inv (code : str , latex : str ) -> None :
1128
+ tree = ast_utils .parse_expr (code )
1129
+ assert isinstance (tree , ast .Call )
1130
+ assert expression_codegen .ExpressionCodegen ().visit (tree ) == latex
1131
+
1132
+
1133
+ @pytest .mark .parametrize (
1134
+ "code,latex" ,
1135
+ [
1136
+ ("pinv(A)" , r"\mathbf{A}^{+}" ),
1137
+ ("pinv(b)" , r"\mathbf{b}^{+}" ),
1138
+ ("pinv([[1, 2], [3, 4]])" , r"\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}^{+}" ),
1139
+ (
1140
+ "pinv([[1, 2, 3], [4, 5, 6], [7, 8, 9]])" ,
1141
+ r"\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}^{+}" ,
1142
+ ),
1143
+ # Unsupported
1144
+ ("pinv()" , r"\mathrm{pinv} \mathopen{}\left( \mathclose{}\right)" ),
1145
+ ("pinv(2)" , r"\mathrm{pinv} \mathopen{}\left( 2 \mathclose{}\right)" ),
1146
+ (
1147
+ "pinv(a, (1, 0))" ,
1148
+ r"\mathrm{pinv} \mathopen{}\left( a, "
1149
+ r"\mathopen{}\left( 1, 0 \mathclose{}\right) \mathclose{}\right)" ,
1150
+ ),
1151
+ ],
1152
+ )
1153
+ def test_pinv (code : str , latex : str ) -> None :
1154
+ tree = ast_utils .parse_expr (code )
1155
+ assert isinstance (tree , ast .Call )
1156
+ assert expression_codegen .ExpressionCodegen ().visit (tree ) == latex
1157
+
1158
+
998
1159
# Check list for #89.
999
1160
# https://github.com/google/latexify_py/issues/89#issuecomment-1344967636
1000
1161
@pytest .mark .parametrize (
0 commit comments