Esempio n. 1
0
def _is_close(a, b, rtol=1e-05, atol=1e-08):
    # np.isclose for mp.mpf, i.e. absolute(a - b) <= (atol + rtol * absolute(b))
    try:
        return [
            mp.almosteq(le, ri, rel_eps=rtol, abs_eps=atol)
            for le, ri in itertools.zip_longest(a, b)
        ]
    except TypeError:
        return mp.almosteq(a, b, rel_eps=rtol, abs_eps=atol)
Esempio n. 2
0
 def dTk(x):
     with mp.extradps(extradps):
         x = clip(x, -1.0, 1.0)
         if mp.almosteq(x, mp.one): return pos
         if mp.almosteq(x, -mp.one): return neg
         moredps = max(
             0,
             int(-math.log10(
                 min(abs(x - mp.one), abs(x + mp.one))) / 2))
         moredps = min(moredps, 100)
         with mp.extradps(moredps):
             t = mp.acos(x)
             return k * mp.sin(k * t) / mp.sin(t)
Esempio n. 3
0
    def _filter_corners(self, pts, basis):
        r"""A generator to return only those points not on corner positions.

        Does nothing (i.e. no filtering) in the 1D case.
        """
        if self._dim == 1:
            for x in pts: yield x
        domains = [basis.get_basis(d).domain() for d in range(self._dim)]
        for i, p in pts:
            is_corner = True
            for d in range(self._dim):
                if d != self._idx and not (mp.almosteq(p[d], domains[d][0]) or mp.almosteq(p[d], domains[d][1])):
                    is_corner = False
            if not is_corner:
                yield i, p
Esempio n. 4
0
 def ddTk(x):
     with mp.extradps(extradps):
         x = clip(x, -1.0, 1.0)
         if mp.almosteq(x, mp.one): return pos
         if mp.almosteq(x, -mp.one): return neg
         moredps = max(
             0,
             int(-math.log10(
                 min(abs(x - mp.one), abs(x + mp.one))) * 1.5) +
             2)
         moredps = min(moredps, 100)
         with mp.extradps(moredps):
             t = mp.acos(x)
             s = mp.sin(t)
             return -k**2 * mp.cos(k * t) / s**2 + k * mp.cos(
                 t) * mp.sin(k * t) / s**3
Esempio n. 5
0
 def get_seq(self, n):
     seq = np.zeros(n, dtype=np.longlong)
     number = self.number
     for i in range(n):
         a = mp.floor(number)
         frac = number - a
         seq[i] = a
         if mp.almosteq(number, a):
             number = 0
         else:
             number = mp.fdiv(1, frac)
     return seq
def isclose(a, b, rel_tol=None, abs_tol=None, use_mp=False):
    r"""Test if two numbers agree within an absolute/relative tolerance.

    For floating point comparison (i.e. if `use_mp==False`), the default
    relative tolerance is `1e-9` and the absolute one `0.0`.
    """
    if use_mp:
        return mp.almosteq(a, b, rel_eps=rel_tol, abs_eps=abs_tol)
    if rel_tol is None:
        rel_tol = 1e-9
    if abs_tol is None:
        abs_tol = 0.0
    return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
Esempio n. 7
0
def _is_close(a, b, rtol=1e-05, atol=1e-08):
    # np.isclose for mp.mpf, i.e. absolute(a - b) <= (atol + rtol * absolute(b))
    return mp.almosteq(a, b, rel_eps=rtol, abs_eps=atol)