Beispiel #1
0
 def test_incorrect_numpy_array_shape(self):
     with self.assertRaisesRegexp(
             ValueError, r'The shape of n is expected to be \(1, 3\) '
             r'but got \(1, 5\)'):
         evaluators.evaluate_expression_strings_1d_grid(
             ['n + 1'],
             num_samples=1,
             num_grids=3,
             arguments={'n': np.array([[-1., 0., 1., 2., 3.]])})
Beispiel #2
0
 def test_incorrect_argument_type(self):
     with self.assertRaisesRegexp(
             ValueError, r'Argument should be np.ndarray, int, or '
             r'float. but got n, <(class|type) \'list\'>'):
         evaluators.evaluate_expression_strings_1d_grid(
             ['n + 1'],
             num_samples=1,
             num_grids=3,
             # Invalid argument type: list.
             arguments={'n': [[-1., 0., 1.]]})
Beispiel #3
0
 def test_arguments_numpy_array_and_int(self):
     np.testing.assert_allclose(
         evaluators.evaluate_expression_strings_1d_grid(
             ['n + 1', 'n + a'],
             num_samples=1,
             num_grids=3,
             arguments={
                 'a': 2,
                 'n': np.array([[-1., 0., 1.]])
             }), [[[0, 1, 2]], [[1, 2, 3]]])
Beispiel #4
0
 def test_argument_int(self):
     np.testing.assert_allclose(
         evaluators.evaluate_expression_strings_1d_grid(['a + 1', 'b + a'],
                                                        num_samples=1,
                                                        num_grids=3,
                                                        arguments={
                                                            'a': 1,
                                                            'b': 3
                                                        }),
         [[[2, 2, 2]], [[4, 4, 4]]])
Beispiel #5
0
 def test_arguments_numpy_array_and_int_with_callable(self):
     np.testing.assert_allclose(
         evaluators.evaluate_expression_strings_1d_grid(
             ['sin(n + a)'],
             num_samples=1,
             num_grids=3,
             callables={'sin': np.sin},
             arguments={
                 'a': 2,
                 'n': np.array([[-1., 0., 1.]])
             }), [[[np.sin(1), np.sin(2), np.sin(3)]]])