MCPcopy Index your code
hub / github.com/numpy/numpy / test_simple

Method test_simple

numpy/lib/tests/test_function_base.py:2885–2912  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2883class TestPiecewise:
2884
2885 def test_simple(self):
2886 # Condition is single bool list
2887 x = piecewise([0, 0], [True, False], [1])
2888 assert_array_equal(x, [1, 0])
2889
2890 # List of conditions: single bool list
2891 x = piecewise([0, 0], [[True, False]], [1])
2892 assert_array_equal(x, [1, 0])
2893
2894 # Conditions is single bool array
2895 x = piecewise([0, 0], np.array([True, False]), [1])
2896 assert_array_equal(x, [1, 0])
2897
2898 # Condition is single int array
2899 x = piecewise([0, 0], np.array([1, 0]), [1])
2900 assert_array_equal(x, [1, 0])
2901
2902 # List of conditions: int array
2903 x = piecewise([0, 0], [np.array([1, 0])], [1])
2904 assert_array_equal(x, [1, 0])
2905
2906 x = piecewise([0, 0], [[False, True]], [lambda x:-1])
2907 assert_array_equal(x, [0, -1])
2908
2909 assert_raises_regex(ValueError, '1 or 2 functions are expected',
2910 piecewise, [0, 0], [[False, True]], [])
2911 assert_raises_regex(ValueError, '1 or 2 functions are expected',
2912 piecewise, [0, 0], [[False, True]], [1, 2, 3])
2913
2914 def test_two_conditions(self):
2915 x = piecewise([1, 2], [[True, False], [False, True]], [3, 4])

Callers

nothing calls this directly

Calls 3

piecewiseFunction · 0.90
assert_array_equalFunction · 0.90
assert_raises_regexFunction · 0.90

Tested by

no test coverage detected