MCPcopy Create free account
hub / github.com/numpy/numpy / test_power_float

Method test_power_float

numpy/core/tests/test_umath.py:1067–1092  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1065
1066class TestPower:
1067 def test_power_float(self):
1068 x = np.array([1., 2., 3.])
1069 assert_equal(x**0, [1., 1., 1.])
1070 assert_equal(x**1, x)
1071 assert_equal(x**2, [1., 4., 9.])
1072 y = x.copy()
1073 y **= 2
1074 assert_equal(y, [1., 4., 9.])
1075 assert_almost_equal(x**(-1), [1., 0.5, 1./3])
1076 assert_almost_equal(x**(0.5), [1., ncu.sqrt(2), ncu.sqrt(3)])
1077
1078 for out, inp, msg in _gen_alignment_data(dtype=np.float32,
1079 type='unary',
1080 max_size=11):
1081 exp = [ncu.sqrt(i) for i in inp]
1082 assert_almost_equal(inp**(0.5), exp, err_msg=msg)
1083 np.sqrt(inp, out=out)
1084 assert_equal(out, exp, err_msg=msg)
1085
1086 for out, inp, msg in _gen_alignment_data(dtype=np.float64,
1087 type='unary',
1088 max_size=7):
1089 exp = [ncu.sqrt(i) for i in inp]
1090 assert_almost_equal(inp**(0.5), exp, err_msg=msg)
1091 np.sqrt(inp, out=out)
1092 assert_equal(out, exp, err_msg=msg)
1093
1094 def test_power_complex(self):
1095 x = np.array([1+2j, 2+3j, 3+4j])

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
assert_almost_equalFunction · 0.90
_gen_alignment_dataFunction · 0.90
copyMethod · 0.45

Tested by

no test coverage detected