1
1
import numpy
2
2
import jax
3
- from neurallogic import symbolic_primitives , sym_gen
3
+ from neurallogic import symbolic_primitives , symbolic_generation
4
4
5
5
6
6
def test_unary_operator_str ():
7
7
output = symbolic_primitives .unary_operator ("not" , "True" )
8
8
expected = "not(True)"
9
9
assert output == expected
10
- eval_output = sym_gen .eval_symbolic_expression (output )
11
- eval_expected = sym_gen .eval_symbolic_expression (expected )
10
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
11
+ eval_expected = symbolic_generation .eval_symbolic_expression (expected )
12
12
assert eval_output == eval_expected
13
13
14
14
@@ -17,8 +17,8 @@ def test_unary_operator_vector():
17
17
output = symbolic_primitives .unary_operator ("not" , x )
18
18
expected = numpy .array (["not(True)" , "not(False)" ])
19
19
assert numpy .array_equal (output , expected )
20
- eval_output = sym_gen .eval_symbolic_expression (output )
21
- eval_expected = sym_gen .eval_symbolic_expression (expected )
20
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
21
+ eval_expected = symbolic_generation .eval_symbolic_expression (expected )
22
22
assert numpy .array_equal (eval_output , eval_expected )
23
23
24
24
@@ -28,18 +28,18 @@ def test_unary_operator_matrix():
28
28
expected = numpy .array (
29
29
[["not(True)" , "not(False)" ], ["not(False)" , "not(True)" ]])
30
30
assert numpy .array_equal (output , expected )
31
- eval_output = sym_gen .eval_symbolic_expression (output )
32
- eval_expected = sym_gen .eval_symbolic_expression (expected )
31
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
32
+ eval_expected = symbolic_generation .eval_symbolic_expression (expected )
33
33
assert numpy .array_equal (eval_output , eval_expected )
34
34
35
35
36
36
def test_binary_operator_str_str ():
37
37
output = symbolic_primitives .binary_infix_operator ("+" , "1" , "2" )
38
38
expected = "1 + 2"
39
39
assert output == expected
40
- eval_output = sym_gen .eval_symbolic_expression (output )
41
- numpy_output = numpy .add (sym_gen .eval_symbolic_expression (
42
- "1" ), sym_gen .eval_symbolic_expression ("2" ))
40
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
41
+ numpy_output = numpy .add (symbolic_generation .eval_symbolic_expression (
42
+ "1" ), symbolic_generation .eval_symbolic_expression ("2" ))
43
43
assert numpy .array_equal (eval_output , numpy_output )
44
44
45
45
@@ -49,9 +49,9 @@ def test_binary_operator_vector_vector():
49
49
output = symbolic_primitives .binary_infix_operator ("+" , x1 , x2 )
50
50
expected = numpy .array (["1 + 3" , "2 + 4" ])
51
51
assert numpy .array_equal (output , expected )
52
- eval_output = sym_gen .eval_symbolic_expression (output )
53
- numpy_output = numpy .add (sym_gen .eval_symbolic_expression (
54
- x1 ), sym_gen .eval_symbolic_expression (x2 ))
52
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
53
+ numpy_output = numpy .add (symbolic_generation .eval_symbolic_expression (
54
+ x1 ), symbolic_generation .eval_symbolic_expression (x2 ))
55
55
assert numpy .array_equal (eval_output , numpy_output )
56
56
57
57
@@ -61,9 +61,9 @@ def test_binary_operator_matrix_vector():
61
61
output = symbolic_primitives .binary_infix_operator ("+" , x1 , x2 )
62
62
expected = numpy .array ([["1 + 5" , "2 + 6" ], ["3 + 5" , "4 + 6" ]])
63
63
assert numpy .array_equal (output , expected )
64
- eval_output = sym_gen .eval_symbolic_expression (output )
65
- numpy_output = numpy .add (sym_gen .eval_symbolic_expression (
66
- x1 ), sym_gen .eval_symbolic_expression (x2 ))
64
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
65
+ numpy_output = numpy .add (symbolic_generation .eval_symbolic_expression (
66
+ x1 ), symbolic_generation .eval_symbolic_expression (x2 ))
67
67
assert numpy .array_equal (eval_output , numpy_output )
68
68
69
69
@@ -73,9 +73,9 @@ def test_binary_operator_vector_matrix():
73
73
output = symbolic_primitives .binary_infix_operator ("+" , x1 , x2 )
74
74
expected = numpy .array ([["1 + 3" , "2 + 4" ], ["1 + 5" , "2 + 6" ]])
75
75
assert numpy .array_equal (output , expected )
76
- eval_output = sym_gen .eval_symbolic_expression (output )
77
- numpy_output = numpy .add (sym_gen .eval_symbolic_expression (
78
- x1 ), sym_gen .eval_symbolic_expression (x2 ))
76
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
77
+ numpy_output = numpy .add (symbolic_generation .eval_symbolic_expression (
78
+ x1 ), symbolic_generation .eval_symbolic_expression (x2 ))
79
79
assert numpy .array_equal (eval_output , numpy_output )
80
80
81
81
@@ -85,9 +85,9 @@ def test_binary_operator_matrix_matrix():
85
85
output = symbolic_primitives .binary_infix_operator ("+" , x1 , x2 )
86
86
expected = numpy .array ([["1 + 5" , "2 + 6" ], ["3 + 7" , "4 + 8" ]])
87
87
assert numpy .array_equal (output , expected )
88
- eval_output = sym_gen .eval_symbolic_expression (output )
89
- numpy_output = numpy .add (sym_gen .eval_symbolic_expression (
90
- x1 ), sym_gen .eval_symbolic_expression (x2 ))
88
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
89
+ numpy_output = numpy .add (symbolic_generation .eval_symbolic_expression (
90
+ x1 ), symbolic_generation .eval_symbolic_expression (x2 ))
91
91
assert numpy .array_equal (eval_output , numpy_output )
92
92
93
93
@@ -100,9 +100,9 @@ def test_binary_operator_matrix_matrix_2():
100
100
expected = numpy .array (
101
101
[["1 + 5" , "2 + 6" , "3 + 7" , "4 + 8" ] for _ in range (10 )])
102
102
assert numpy .array_equal (output , expected )
103
- eval_output = sym_gen .eval_symbolic_expression (output )
104
- numpy_output = numpy .add (sym_gen .eval_symbolic_expression (
105
- x1 ), sym_gen .eval_symbolic_expression (x2 ))
103
+ eval_output = symbolic_generation .eval_symbolic_expression (output )
104
+ numpy_output = numpy .add (symbolic_generation .eval_symbolic_expression (
105
+ x1 ), symbolic_generation .eval_symbolic_expression (x2 ))
106
106
assert numpy .array_equal (eval_output , numpy_output )
107
107
108
108
@@ -141,34 +141,34 @@ def test_to_boolean_value_string():
141
141
142
142
143
143
def test_symbolic_eval ():
144
- output = sym_gen .eval_symbolic_expression ("1 + 2" )
144
+ output = symbolic_generation .eval_symbolic_expression ("1 + 2" )
145
145
expected = 3
146
146
assert output == expected
147
- output = sym_gen .eval_symbolic_expression ("[1, 2, 3]" )
147
+ output = symbolic_generation .eval_symbolic_expression ("[1, 2, 3]" )
148
148
expected = [1 , 2 , 3 ]
149
149
assert numpy .array_equal (output , expected )
150
- output = sym_gen .eval_symbolic_expression ("[1, 2, 3] + [4, 5, 6]" )
150
+ output = symbolic_generation .eval_symbolic_expression ("[1, 2, 3] + [4, 5, 6]" )
151
151
expected = [1 , 2 , 3 , 4 , 5 , 6 ]
152
152
assert numpy .array_equal (output , expected )
153
- output = sym_gen .eval_symbolic_expression (['1' , '2' , '3' ])
153
+ output = symbolic_generation .eval_symbolic_expression (['1' , '2' , '3' ])
154
154
expected = [1 , 2 , 3 ]
155
155
assert numpy .array_equal (output , expected )
156
- output = sym_gen .eval_symbolic_expression (
156
+ output = symbolic_generation .eval_symbolic_expression (
157
157
['1' , '2' , '3' ] + ['4' , '5' , '6' ])
158
158
expected = [1 , 2 , 3 , 4 , 5 , 6 ]
159
159
assert numpy .array_equal (output , expected )
160
- output = sym_gen .eval_symbolic_expression (['not(False)' , 'not(True)' ])
160
+ output = symbolic_generation .eval_symbolic_expression (['not(False)' , 'not(True)' ])
161
161
expected = [True , False ]
162
162
assert numpy .array_equal (output , expected )
163
- output = sym_gen .eval_symbolic_expression (
163
+ output = symbolic_generation .eval_symbolic_expression (
164
164
[['not(False)' , 'not(True)' ] + ['not(False)' , 'not(True)' ]])
165
165
expected = [[True , False , True , False ]]
166
166
assert numpy .array_equal (output , expected )
167
- output = sym_gen .eval_symbolic_expression (numpy .array (
167
+ output = symbolic_generation .eval_symbolic_expression (numpy .array (
168
168
[['not(False)' , 'not(True)' ] + ['not(False)' , 'not(True)' ]]))
169
169
expected = [[True , False , True , False ]]
170
170
assert numpy .array_equal (output , expected )
171
- output = sym_gen .eval_symbolic_expression (numpy .array (
171
+ output = symbolic_generation .eval_symbolic_expression (numpy .array (
172
172
[['not(False)' , False ], ['not(False)' , 'not(True)' ]]))
173
173
expected = [[True , False ], [True , False ]]
174
174
assert numpy .array_equal (output , expected )
@@ -179,7 +179,7 @@ def test_symbolic_not():
179
179
output = symbolic_primitives .symbolic_not (x1 )
180
180
expected = numpy .array ([False , True ])
181
181
assert numpy .array_equal (output , expected )
182
- x1 = sym_gen .make_symbolic (x1 )
182
+ x1 = symbolic_generation .make_symbolic (x1 )
183
183
output = symbolic_primitives .symbolic_not (x1 )
184
184
expected = numpy .array (["not(True)" , "not(False)" ])
185
185
assert numpy .array_equal (output , expected )
@@ -191,8 +191,8 @@ def test_symbolic_and():
191
191
output = symbolic_primitives .symbolic_and (x1 , x2 )
192
192
expected = numpy .array ([True , False ])
193
193
assert numpy .array_equal (output , expected )
194
- x1 = sym_gen .make_symbolic (x1 )
195
- x2 = sym_gen .make_symbolic (x2 )
194
+ x1 = symbolic_generation .make_symbolic (x1 )
195
+ x2 = symbolic_generation .make_symbolic (x2 )
196
196
output = symbolic_primitives .symbolic_and (x1 , x2 )
197
197
expected = numpy .array (["True and True" , "False and True" ])
198
198
assert numpy .array_equal (output , expected )
@@ -204,8 +204,8 @@ def test_symbolic_xor():
204
204
output = symbolic_primitives .symbolic_xor (x1 , x2 )
205
205
expected = numpy .array ([False , True ])
206
206
assert numpy .array_equal (output , expected )
207
- x1 = sym_gen .make_symbolic (x1 )
208
- x2 = sym_gen .make_symbolic (x2 )
207
+ x1 = symbolic_generation .make_symbolic (x1 )
208
+ x2 = symbolic_generation .make_symbolic (x2 )
209
209
output = symbolic_primitives .symbolic_xor (x1 , x2 )
210
210
expected = numpy .array (["True ^ True" , "False ^ True" ])
211
211
assert numpy .array_equal (output , expected )
@@ -242,12 +242,12 @@ def symbolic_reduce_or_impl(input, expected, symbolic_expected, axes):
242
242
expected = numpy .array (expected )
243
243
assert numpy .array_equal (output , expected )
244
244
# Test symbolic implementation
245
- input = sym_gen .make_symbolic (input )
245
+ input = symbolic_generation .make_symbolic (input )
246
246
output = symbolic_primitives .symbolic_reduce_or (input , axes = axes )
247
247
symbolic_expected = numpy .array (symbolic_expected )
248
248
assert numpy .array_equal (output , symbolic_expected )
249
249
# Compare the reference and symbolic evaluation
250
- symbolic_expected = sym_gen .eval_symbolic_expression (symbolic_expected )
250
+ symbolic_expected = symbolic_generation .eval_symbolic_expression (symbolic_expected )
251
251
assert numpy .array_equal (expected , symbolic_expected )
252
252
253
253
0 commit comments