2023-10-10 16:56:38 +08:00
|
|
|
@extern
|
|
|
|
def output_bool(x: bool):
|
|
|
|
...
|
|
|
|
|
2023-11-02 14:56:35 +08:00
|
|
|
@extern
|
|
|
|
def output_int32(x: int32):
|
|
|
|
...
|
|
|
|
|
|
|
|
@extern
|
|
|
|
def output_int64(x: int64):
|
|
|
|
...
|
|
|
|
|
2023-10-06 17:48:31 +08:00
|
|
|
@extern
|
|
|
|
def output_float64(x: float):
|
|
|
|
...
|
|
|
|
|
2023-10-10 16:56:38 +08:00
|
|
|
@extern
|
|
|
|
def dbl_nan() -> float:
|
|
|
|
...
|
|
|
|
|
|
|
|
@extern
|
|
|
|
def dbl_inf() -> float:
|
|
|
|
...
|
|
|
|
|
2023-10-11 17:52:12 +08:00
|
|
|
def dbl_pi() -> float:
|
|
|
|
return 3.1415926535897932384626433
|
|
|
|
|
|
|
|
def dbl_e() -> float:
|
|
|
|
return 2.71828182845904523536028747135266249775724709369995
|
|
|
|
|
2023-11-02 14:56:35 +08:00
|
|
|
def test_round():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int32(round(x))
|
|
|
|
|
|
|
|
def test_round64():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int64(round64(x))
|
|
|
|
|
2023-11-23 13:45:07 +08:00
|
|
|
def test_np_round():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
output_float64(np_round(x))
|
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_isnan():
|
2023-10-10 16:56:38 +08:00
|
|
|
for x in [dbl_nan(), 0.0, dbl_inf()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_bool(np_isnan(x))
|
2023-10-10 16:56:38 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_isinf():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [dbl_inf(), -dbl_inf(), 0.0, dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_bool(np_isinf(x))
|
2023-10-10 16:56:38 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_sin():
|
2023-10-11 17:52:12 +08:00
|
|
|
pi = dbl_pi()
|
|
|
|
for x in [-pi, -pi / 2.0, -pi / 4.0, 0.0, pi / 4.0, pi / 2.0, pi, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_sin(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_cos():
|
2023-10-11 17:52:12 +08:00
|
|
|
pi = dbl_pi()
|
|
|
|
for x in [-pi, -pi / 2.0, -pi / 4.0, 0.0, pi / 4.0, pi / 2.0, pi, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_cos(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_exp():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_exp(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_exp2():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_exp2(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_log():
|
2023-10-11 17:52:12 +08:00
|
|
|
e = dbl_e()
|
|
|
|
for x in [1.0, e, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_log(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_log10():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 10.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_log10(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_log2():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_log2(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_fabs():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, 0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_fabs(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
|
|
|
def test_floor():
|
2023-11-02 14:56:35 +08:00
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int32(floor(x))
|
|
|
|
|
|
|
|
def test_floor64():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int64(floor64(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:45:07 +08:00
|
|
|
def test_np_floor():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
output_float64(np_floor(x))
|
|
|
|
|
2023-10-06 17:48:31 +08:00
|
|
|
def test_ceil():
|
2023-11-02 14:56:35 +08:00
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int32(ceil(x))
|
|
|
|
|
|
|
|
def test_ceil64():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int64(ceil64(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:45:07 +08:00
|
|
|
def test_np_ceil():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
output_float64(np_ceil(x))
|
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_sqrt():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 2.0, 4.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_sqrt(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_rint():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_rint(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_tan():
|
2023-10-11 17:52:12 +08:00
|
|
|
pi = dbl_pi()
|
|
|
|
for x in [-pi, -pi / 2.0, -pi / 4.0, 0.0, pi / 4.0, pi / 2.0, pi, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_tan(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arcsin():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arcsin(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arccos():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arccos(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arctan():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arctan(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_sinh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_sinh(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_cosh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_cosh(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_tanh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_tanh(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arcsinh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arcsinh(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arccosh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arccosh(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arctanh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arctanh(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_expm1():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_expm1(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_cbrt():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 8.0, 27.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2024-04-24 14:57:54 +08:00
|
|
|
output_float64(np_cbrt(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_sp_spec_erf():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(sp_spec_erf(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_sp_spec_erfc():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(sp_spec_erfc(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_sp_spec_gamma():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(sp_spec_gamma(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_sp_spec_gammaln():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(sp_spec_gammaln(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_sp_spec_j0():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(sp_spec_j0(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_sp_spec_j1():
|
2023-10-06 17:48:31 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(sp_spec_j1(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_arctan2():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_arctan2(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_copysign():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_copysign(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_fmax():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_fmax(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_fmin():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_fmin(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_ldexp():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
for x2 in [-2, -1, 0, 1, 2]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_ldexp(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_hypot():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_hypot(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-11-23 13:32:08 +08:00
|
|
|
def test_np_nextafter():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-11-23 13:32:08 +08:00
|
|
|
output_float64(np_nextafter(x1, x2))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
2023-10-10 16:56:38 +08:00
|
|
|
def run() -> int32:
|
2023-11-02 14:56:35 +08:00
|
|
|
test_round()
|
|
|
|
test_round64()
|
2023-11-23 13:45:07 +08:00
|
|
|
test_np_round()
|
2023-11-23 13:32:08 +08:00
|
|
|
test_np_isnan()
|
|
|
|
test_np_isinf()
|
|
|
|
test_np_sin()
|
|
|
|
test_np_cos()
|
|
|
|
test_np_exp()
|
|
|
|
test_np_exp2()
|
|
|
|
test_np_log()
|
|
|
|
test_np_log10()
|
|
|
|
test_np_log2()
|
|
|
|
test_np_fabs()
|
2023-10-06 17:48:31 +08:00
|
|
|
test_floor()
|
2023-11-02 14:56:35 +08:00
|
|
|
test_floor64()
|
2023-11-23 13:45:07 +08:00
|
|
|
test_np_floor()
|
2023-10-06 17:48:31 +08:00
|
|
|
test_ceil()
|
2023-11-02 14:56:35 +08:00
|
|
|
test_ceil64()
|
2023-11-23 13:45:07 +08:00
|
|
|
test_np_ceil()
|
2023-11-23 13:32:08 +08:00
|
|
|
test_np_sqrt()
|
|
|
|
test_np_rint()
|
|
|
|
test_np_tan()
|
|
|
|
test_np_arcsin()
|
|
|
|
test_np_arccos()
|
|
|
|
test_np_arctan()
|
|
|
|
test_np_sinh()
|
|
|
|
test_np_cosh()
|
|
|
|
test_np_tanh()
|
|
|
|
test_np_arcsinh()
|
|
|
|
test_np_arccosh()
|
|
|
|
test_np_arctanh()
|
|
|
|
test_np_expm1()
|
|
|
|
test_np_cbrt()
|
|
|
|
test_sp_spec_erf()
|
|
|
|
test_sp_spec_erfc()
|
|
|
|
test_sp_spec_gamma()
|
|
|
|
test_sp_spec_gammaln()
|
|
|
|
test_sp_spec_j0()
|
|
|
|
test_sp_spec_j1()
|
|
|
|
test_np_arctan2()
|
|
|
|
test_np_copysign()
|
|
|
|
test_np_fmax()
|
|
|
|
test_np_fmin()
|
|
|
|
test_np_ldexp()
|
|
|
|
test_np_hypot()
|
|
|
|
test_np_nextafter()
|
2023-10-10 16:56:38 +08:00
|
|
|
|
|
|
|
return 0
|