MilesCranmer commited on
Commit
9c31a35
1 Parent(s): 4d7fdcd

Convert torch test into unittest

Browse files
Files changed (1) hide show
  1. 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
- print("Test Torch 1 - test export")
7
- x, y, z = sympy.symbols('x y z')
8
- cosx = 1.0 * sympy.cos(x) + y
9
- X = torch.randn((1000, 3))
10
- true = 1.0 * torch.cos(X[:, 0]) + X[:, 1]
11
- torch_module = sympy2torch(cosx, [x, y, z])
12
- assert np.all(np.isclose(torch_module(X).detach().numpy(), true.detach().numpy()))
 
 
 
 
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
+ )