Python math.atanh() Examples

The following are 30 code examples of math.atanh(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module math , or try the search function .
Example #1
Source Project: ironpython2   Author: IronLanguages   File: test_math.py    License: Apache License 2.0 7 votes vote down vote up
def test_math_subclass(self):
        """verify subtypes of float/long work w/ math functions"""
        import math
        class myfloat(float): pass
        class mylong(long): pass

        mf = myfloat(1)
        ml = mylong(1)

        for x in math.log, math.log10, math.log1p, math.asinh, math.acosh, math.atanh, math.factorial, math.trunc, math.isinf:
            try:
                resf = x(mf)
            except ValueError:
                resf = None
            try:
                resl = x(ml)
            except ValueError:
                resl = None
            self.assertEqual(resf, resl) 
Example #2
Source Project: pyth   Author: isaacg1   File: macros.py    License: MIT License 6 votes vote down vote up
def trig(a, b=' '):
    if is_num(a) and isinstance(b, int):

        funcs = [math.sin, math.cos, math.tan,
                 math.asin, math.acos, math.atan,
                 math.degrees, math.radians,
                 math.sinh, math.cosh, math.tanh,
                 math.asinh, math.acosh, math.atanh]

        return funcs[b](a)

    if is_lst(a):
        width = max(len(row) for row in a)
        padded_matrix = [list(row) + (width - len(row)) * [b] for row in a]
        transpose = list(zip(*padded_matrix))
        if all(isinstance(row, str) for row in a) and isinstance(b, str):
            normalizer = ''.join
        else:
            normalizer = list
        norm_trans = [normalizer(padded_row) for padded_row in transpose]
        return norm_trans
    return unknown_types(trig, ".t", a, b) 
Example #3
Source Project: ironpython3   Author: IronLanguages   File: test_math.py    License: Apache License 2.0 6 votes vote down vote up
def test_math_subclass(self):
        """verify subtypes of float/long work w/ math functions"""
        import math
        class myfloat(float): pass
        class mylong(long): pass

        mf = myfloat(1)
        ml = mylong(1)

        for x in math.log, math.log10, math.log1p, math.asinh, math.acosh, math.atanh, math.factorial, math.trunc, math.isinf:
            try:
                resf = x(mf)
            except ValueError:
                resf = None
            try:
                resl = x(ml)
            except ValueError:
                resl = None
            self.assertEqual(resf, resl) 
Example #4
Source Project: tensor   Author: calston   File: generator.py    License: MIT License 6 votes vote down vote up
def get(self):
        self.x += self.config.get('dx', 0.1)

        val = eval(self.config.get('function', 'sin(x)'), {
            'sin': math.sin,
            'sinh': math.sinh,
            'cos': math.cos,
            'cosh': math.cosh,
            'tan': math.tan,
            'tanh': math.tanh,
            'asin': math.asin,
            'acos': math.acos,
            'atan': math.atan,
            'asinh': math.asinh,
            'acosh': math.acosh,
            'atanh': math.atanh,
            'log': math.log,
            'abs': abs,
            'e': math.e,
            'pi': math.pi,
            'x': self.x
        })

        return self.createEvent('ok', 'Sine wave', val) 
Example #5
Source Project: vidaug   Author: okankop   File: temporal.py    License: MIT License 6 votes vote down vote up
def _get_distorted_indices(self, nb_images):
        inverse = random.randint(0, 1)

        if inverse:
            scale = random.random()
            scale *= 0.21
            scale += 0.6
        else:
            scale = random.random()
            scale *= 0.6
            scale += 0.8

        frames_per_clip = nb_images

        indices = np.linspace(-scale, scale, frames_per_clip).tolist()
        if inverse:
            values = [math.atanh(x) for x in indices]
        else:
            values = [math.tanh(x) for x in indices]

        values = [x / values[-1] for x in values]
        values = [int(round(((x + 1) / 2) * (frames_per_clip - 1), 0)) for x in values]
        return values 
Example #6
Source Project: pymap3d   Author: geospace-code   File: latitude.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def geodetic2isometric_point(geodetic_lat: float, ell: Ellipsoid = None, deg: bool = True) -> float:
    geodetic_lat, ell = sanitize(geodetic_lat, ell, deg)

    e = ell.eccentricity

    if abs(geodetic_lat - pi / 2) <= 1e-9:
        isometric_lat = inf
    elif abs(-geodetic_lat - pi / 2) <= 1e-9:
        isometric_lat = -inf
    else:
        isometric_lat = asinh(tan(geodetic_lat)) - e * atanh(e * sin(geodetic_lat))
        # same results
        # a1 = e * sin(geodetic_lat)
        # y = (1 - a1) / (1 + a1)
        # a2 = pi / 4 + geodetic_lat / 2
        # isometric_lat = log(tan(a2) * (y ** (e / 2)))
        # isometric_lat = log(tan(a2)) + e/2 * log((1-e*sin(geodetic_lat)) / (1+e*sin(geodetic_lat)))

    return degrees(isometric_lat) if deg else isometric_lat 
Example #7
Source Project: exposure   Author: yuanming-hu   File: util.py    License: MIT License 5 votes vote down vote up
def tanh_range(l, r, initial=None):

  def get_activation(left, right, initial):

    def activation(x):
      if initial is not None:
        bias = math.atanh(2 * (initial - left) / (right - left) - 1)
      else:
        bias = 0
      return tanh01(x + bias) * (right - left) + left

    return activation

  return get_activation(l, r, initial) 
Example #8
Source Project: ironpython2   Author: IronLanguages   File: test_math.py    License: Apache License 2.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #9
Source Project: BinderFilter   Author: dxwu   File: test_math.py    License: MIT License 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #10
Source Project: oss-ftp   Author: aliyun   File: test_math.py    License: MIT License 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #11
Source Project: fastats   Author: fastats   File: test_convert_to_jit.py    License: MIT License 5 votes vote down vote up
def test_does_not_convert_math_builtins():
    for func in (math.atan2, math.atanh, math.degrees, math.exp, math.floor, math.log,
                 math.sin, math.sinh, math.tan, math.tanh):
        assert convert_to_jit(func) is func 
Example #12
Source Project: ufora   Author: ufora   File: pure_math.py    License: Apache License 2.0 5 votes vote down vote up
def __call__(self, val):
        if val >= 1:
            raise ValueError("math domain error")

        return __inline_fora(
            """fun(@unnamed_args:(val), *args) {
                   PyFloat(math.atanh(val.@m))
                   }"""
            )(val) 
Example #13
Source Project: ufora   Author: ufora   File: MathTestCases.py    License: Apache License 2.0 5 votes vote down vote up
def test_pure_python_math_module(self):
        vals = [1, -.5, 1.5, 0, 0.0, -2, -2.2, .2]

        # not being tested: math.asinh, math.atanh, math.lgamma, math.erfc, math.acos
        def f():
            functions = [
                math.sqrt, math.cos, math.sin, math.tan, math.asin, math.atan,
                math.acosh, math.cosh, math.sinh, math.tanh, math.ceil,
                math.erf, math.exp, math.expm1, math.factorial, math.floor,
                math.log, math.log10, math.log1p
            ]
            tr = []
            for idx1 in range(len(vals)):
                v1 = vals[idx1]
                for funIdx in range(len(functions)):
                    function = functions[funIdx]
                    try:
                        tr = tr + [function(v1)]
                    except ValueError as ex:
                        pass

            return tr

        r1 = self.evaluateWithExecutor(f)
        r2 = f()
        self.assertGreater(len(r1), 100)
        self.assertTrue(numpy.allclose(r1, r2, 1e-6)) 
Example #14
Source Project: hask   Author: billpmurphy   File: Num.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def make_instance(typeclass, cls, pi, exp, sqrt, log, pow, logBase, sin,
            tan, cos, asin, atan, acos, sinh, tanh, cosh, asinh, atanh, acosh):
        attrs = {"pi":pi, "exp":exp, "sqrt":sqrt, "log":log, "pow":pow,
                "logBase":logBase, "sin":sin, "tan":tan, "cos":cos,
                "asin":asin, "atan":atan, "acos":acos, "sinh":sinh,
                "tanh":tanh, "cosh":cosh, "asinh":asinh, "atanh":atanh,
                "acosh":acosh}
        build_instance(Floating, cls, attrs)
        return 
Example #15
Source Project: hask   Author: billpmurphy   File: Num.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def atanh(x):
    """
    atanh :: Floating a => a -> a
    """
    return Floating[x].atanh(x) 
Example #16
Source Project: Fluid-Designer   Author: Microvellum   File: test_math.py    License: GNU General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #17
Source Project: Fluid-Designer   Author: Microvellum   File: transverse_mercator.py    License: GNU General Public License v3.0 5 votes vote down vote up
def fromGeographic(self, lat, lon):
        lat_rad = radians(lat)
        lon_rad = radians(lon)
        B = cos(lat_rad) * sin(lon_rad - self.lon_rad)
        x = self.radius * atanh(B)
        y = self.radius * (atan(tan(lat_rad) / cos(lon_rad - self.lon_rad)) - self.lat_rad)
        return x, y 
Example #18
Source Project: ironpython3   Author: IronLanguages   File: test_math.py    License: Apache License 2.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #19
Source Project: PyFlow   Author: wonderworks-software   File: MathLib.py    License: Apache License 2.0 5 votes vote down vote up
def atanh(x=('FloatPin', 0.0), Result=(REF, ('BoolPin', False))):
        '''Return the inverse hyperbolic tangent of `x`.'''
        try:
            Result(True)
            return math.atanh(x)
        except:
            Result(False)
            return -1 
Example #20
Source Project: Azimuth   Author: MicrosoftResearch   File: corrstats.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def rz_ci(r, n, conf_level = 0.95):
    zr_se = pow(1/(n - 3), .5)
    moe = norm.ppf(1 - (1 - conf_level)/float(2)) * zr_se
    zu = atanh(r) + moe
    zl = atanh(r) - moe
    return tanh((zl, zu)) 
Example #21
Source Project: gcblue   Author: gcblue   File: test_math.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #22
Source Project: flavio   Author: flav-io   File: bllgamma.py    License: MIT License 5 votes vote down vote up
def dG2dsMN(s, par, B, ff, ff0, lep, wc):
    mlh = par['m_'+lep]/par['m_'+B]
    bq = meson_quark[B]
    label = bq+lep+lep
    pref = 16*prefactor(s, par, B, ff, lep, wc)*(par['f_'+B]/par['m_'+B]*abs(wc['C10_'+label])*mlh)**2/(1-s)
    return pref*(-8*sqrt(s-4*mlh**2)*sqrt(s)+4*atanh(sqrt(1-4*mlh**2/s))*(1+s-mlh**2*(1-s)**2)) 
Example #23
Source Project: flavio   Author: flav-io   File: bllgamma.py    License: MIT License 5 votes vote down vote up
def dG12dsMN(s, par, B, ff, ff0, lep, wc):
    mlh = par['m_'+lep]/par['m_'+B]
    pref = 4*prefactor(s, par, B, ff, lep, wc)*par['f_'+B]/par['m_'+B]*(1-s)
    return pref*atanh(sqrt(1-4*mlh**2/s))*B120(s, par, B, ff, ff0, lep, wc) 
Example #24
Source Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_math.py    License: GNU General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #25
Source Project: qgis-shapetools-plugin   Author: NationalSecurityAgency   File: geomath.py    License: GNU General Public License v2.0 5 votes vote down vote up
def atanh(x):
    """atanh(x) (missing from python 2.5.2)"""

    if sys.version_info > (2, 6):
      return math.atanh(x)

    y = abs(x)                  # Enforce odd parity
    y = Math.log1p(2 * y/(1 - y))/2
    return -y if x < 0 else y 
Example #26
Source Project: hyperbolic   Author: cduck   File: util.py    License: MIT License 5 votes vote down vote up
def radialEuclidToPoincare(r):
    return 2 * math.atanh(r) 
Example #27
Source Project: hyperbolic   Author: cduck   File: Hypercycle.py    License: MIT License 5 votes vote down vote up
def fromHypercycleOffset(cls, hcycle, offset, unit=Circle(0,0,1)):
        dh = offset #dh = math.asinh(offset/2)
        if isinstance(hcycle.projShape, Circle):
            # May throw if bad geometry
            x1, y1, x2, y2 = intersection.circleCircle(hcycle.projShape, unit)
            cx, cy = hcycle.projShape.cx, hcycle.projShape.cy
            r, cw = hcycle.projShape.r, hcycle.projShape.cw
            if cw:
                x1, y1, x2, y2 = x2, y2, x1, y1
            rc = math.hypot(cx, cy)
            deMid = rc - r
            dhMid = 2 * math.atanh(deMid)
            sign = -1 if cw else 1
            t = math.tanh((dhMid + sign*dh)/2)
            xOff, yOff = t * cx / rc, t * cy / rc
        else:
            # May throw if bad geometry
            x1, y1, x2, y2 = intersection.lineCircle(hcycle.projShape, unit)
            lineAng = math.atan2(y2-y1, x2-x1)
            mx, my = (x1+x2)/2, (y1+y2)/2  # Midpoint
            if util.nearZero(mx) and util.nearZero(my):
                ang = math.atan2(y2-y1, x2-x1) + math.pi/2
            else:
                ang = math.atan2(my, mx)
            # Test if the line goes clockwise around the origin
            cw = (ang - lineAng) % (math.pi*2) < math.pi
            rm = math.hypot(mx, my)
            deMid = rm
            dhMid = 2 * math.atanh(deMid)
            sign = 1 if cw else -1
            t = math.tanh((dhMid + sign*dh)/2)
            xOff, yOff = t * math.cos(ang), t * math.sin(ang)
        return cls.fromPoints(x1, y1, x2, y2, xOff, yOff, segment=False, excludeMid=False) 
Example #28
Source Project: hyperbolic   Author: cduck   File: Point.py    License: MIT License 5 votes vote down vote up
def __init__(self, x, y, hr=None, theta=None):
        self.x = x
        self.y = y
        # Hyperbolic polar coordinates
        if theta is None:
            theta = math.atan2(y, x)
        if hr is None:
            r = math.hypot(x, y)
            if self.isIdeal():
                hr = float('inf')
            else:
                hr = 2 * math.atanh(r)
        self.theta = theta
        self.hr = hr 
Example #29
Source Project: CTFCrackTools-V2   Author: Acmesec   File: test_math.py    License: GNU General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example #30
Source Project: hyper-engine   Author: maxim5   File: sugar.py    License: Apache License 2.0 5 votes vote down vote up
def atanh(node): return merge([node], math.atanh)