Spaces:
Running
Running
Commit
·
9c31a35
1
Parent(s):
4d7fdcd
Convert torch test into unittest
Browse files- test/test_torch.py +11 -7
test/test_torch.py
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
from pysr import sympy2torch
|
| 3 |
import torch
|
| 4 |
import sympy
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
import numpy as np
|
| 3 |
from pysr import sympy2torch
|
| 4 |
import torch
|
| 5 |
import sympy
|
| 6 |
|
| 7 |
+
class TestTorch(unittest.TestCase):
|
| 8 |
+
def test_sympy2torch(self):
|
| 9 |
+
x, y, z = sympy.symbols('x y z')
|
| 10 |
+
cosx = 1.0 * sympy.cos(x) + y
|
| 11 |
+
X = torch.randn((1000, 3))
|
| 12 |
+
true = 1.0 * torch.cos(X[:, 0]) + X[:, 1]
|
| 13 |
+
torch_module = sympy2torch(cosx, [x, y, z])
|
| 14 |
+
self.assertTrue(
|
| 15 |
+
np.all(np.isclose(torch_module(X).detach().numpy(), true.detach().numpy()))
|
| 16 |
+
)
|