def test11_hyp(): for i in range(-5, 5): for j in range(-5, 5): a = ek.sinh(C(i, j)) b = C(cmath.sinh(complex(i, j))) assert ek.allclose(a, b) a = ek.cosh(C(i, j)) b = C(cmath.cosh(complex(i, j))) assert ek.allclose(a, b) sa, ca = ek.sincosh(C(i, j)) sb = C(cmath.sinh(complex(i, j))) cb = C(cmath.cosh(complex(i, j))) assert ek.allclose(sa, sb) assert ek.allclose(ca, cb) # Python appears to handle the branch cuts # differently from Enoki, C, and Mathematica.. a = ek.asinh(C(i + 0.1, j)) b = C(cmath.asinh(complex(i + 0.1, j))) assert ek.allclose(a, b) a = ek.acosh(C(i, j)) b = C(cmath.acosh(complex(i, j))) assert ek.allclose(a, b, atol=1e-7) if abs(i) != 1 or j != 0: a = ek.atanh(C(i, j)) b = C(cmath.atanh(complex(i, j))) assert ek.allclose(a, b, atol=1e-7)
def acosh_(a0): if not a0.IsFloat: raise Exception("acosh(): requires floating point operands!") ar, sr = _check1(a0) if not a0.IsSpecial: for i in range(sr): ar[i] = _ek.acosh(a0[i]) elif a0.IsComplex: return 2 * _ek.log(_ek.sqrt(.5 * (a0 + 1)) + _ek.sqrt(.5 * (a0 - 1))) else: raise Exception("acosh(): unsupported array type!") return ar
def test38_acosh(m): x = ek.linspace(m.Float, 1.01, 2, 10) ek.enable_grad(x) y = ek.acosh(x) ek.backward(y) assert ek.allclose( y, m.Float(0.141304, 0.485127, 0.665864, 0.802882, 0.916291, 1.01426, 1.10111, 1.17944, 1.25098, 1.31696)) assert ek.allclose( ek.grad(x), m.Float(7.05346, 1.98263, 1.39632, 1.12112, 0.952381, 0.835191, 0.747665, 0.679095, 0.623528, 0.57735))