当前位置: 首页>>代码示例>>Python>>正文


Python math.isfinite方法代码示例

本文整理汇总了Python中math.isfinite方法的典型用法代码示例。如果您正苦于以下问题:Python math.isfinite方法的具体用法?Python math.isfinite怎么用?Python math.isfinite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math的用法示例。


在下文中一共展示了math.isfinite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: coerce_output

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def coerce_output(self, value: Any) -> float:
        """
        Coerce the resolved value for output.
        :param value: value to coerce
        :type value: Any
        :return: the coerced value
        :rtype: float
        """
        # pylint: disable=no-self-use
        try:
            result = value
            if value and isinstance(value, str):
                result = float(value)

            if not isfinite(result):
                raise ValueError

            return result if isinstance(result, float) else float(result)
        except Exception:  # pylint: disable=broad-except
            pass

        raise TypeError(
            f"Float cannot represent non numeric value: < {value} >."
        ) 
开发者ID:tartiflette,项目名称:tartiflette,代码行数:26,代码来源:float.py

示例2: coerce_input

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def coerce_input(self, value: Any) -> float:
        """
        Coerce the user input from variable value.
        :param value: value to coerce
        :type value: Any
        :return: the coerced value
        :rtype: float
        """
        # pylint: disable=no-self-use
        # ¯\_(ツ)_/¯ booleans are int: `assert isinstance(True, int) is True`
        try:
            if not isinstance(value, bool) and isfinite(value):
                return float(value)
        except Exception:  # pylint: disable=broad-except
            pass
        raise TypeError(
            f"Float cannot represent non numeric value: < {value} >."
        ) 
开发者ID:tartiflette,项目名称:tartiflette,代码行数:20,代码来源:float.py

示例3: coerce_output

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def coerce_output(self, value: Any) -> bool:
        """
        Coerce the resolved value for output.
        :param value: value to coerce
        :type value: Any
        :return: the coerced value
        :rtype: bool
        """
        # pylint: disable=no-self-use
        if isinstance(value, bool):
            return value

        try:
            if isfinite(value):
                return bool(value)
        except Exception:  # pylint: disable=broad-except
            pass
        raise TypeError(
            f"Boolean cannot represent a non boolean value: < {value} >."
        ) 
开发者ID:tartiflette,项目名称:tartiflette,代码行数:22,代码来源:boolean.py

示例4: _number_literal_format

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def _number_literal_format(translator, expr):
    value = expr.op().value

    if math.isfinite(value):
        # Spark interprets dotted number literals as decimals, not floats.
        # i.e. "select 1.0 as tmp" is a decimal(2,1), not a float or double
        if isinstance(expr.op().dtype, dt.Float64):
            formatted = "{}d".format(repr(value))
        elif isinstance(expr.op().dtype, dt.Floating):
            formatted = "CAST({} AS FLOAT)".format(repr(value))
        else:
            formatted = repr(value)
    else:
        if math.isnan(value):
            formatted_val = 'NaN'
        elif math.isinf(value):
            if value > 0:
                formatted_val = 'Infinity'
            else:
                formatted_val = '-Infinity'
        formatted = "CAST({!r} AS DOUBLE)".format(formatted_val)

    return formatted 
开发者ID:ibis-project,项目名称:ibis,代码行数:25,代码来源:compiler.py

示例5: _number_literal_format

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def _number_literal_format(translator, expr):
    value = expr.op().value

    if math.isfinite(value):
        formatted = repr(value)
    else:
        if math.isnan(value):
            formatted_val = 'NaN'
        elif math.isinf(value):
            if value > 0:
                formatted_val = 'Infinity'
            else:
                formatted_val = '-Infinity'
        formatted = "CAST({!r} AS DOUBLE)".format(formatted_val)

    return formatted 
开发者ID:ibis-project,项目名称:ibis,代码行数:18,代码来源:compiler.py

示例6: defuzzify

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def defuzzify(self, term: Term, minimum: float, maximum: float) -> float:
        if not math.isfinite(minimum + maximum):
            return nan
        resolution = self.resolution
        dx = (maximum - minimum) / resolution
        counter = resolution
        left = right = 0
        x_left, x_right = (minimum, maximum)
        left_area = right_area = 0.0

        # TODO: Improve?
        while counter > 0:
            counter = counter - 1
            if left_area <= right_area:
                x_left = minimum + (left + 0.5) * dx
                left_area += term.membership(x_left)
                left += 1
            else:
                x_right = maximum - (right + 0.5) * dx
                right_area += term.membership(x_right)
                right += 1

        # Inverse weighted average to compensate
        return (left_area * x_right + right_area * x_left) / (left_area + right_area) 
开发者ID:fuzzylite,项目名称:pyfuzzylite,代码行数:26,代码来源:defuzzifier.py

示例7: test_decimal_from_float

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def test_decimal_from_float(f):
    d = Decimal(f)
    if isfinite(f) and d.is_finite():
        try:
            # PDF is limited to ~5 sig figs
            decstr = str(d.quantize(Decimal('1.000000')))
        except InvalidOperation:
            return  # PDF doesn't support exponential notation
        try:
            py_d = Object.parse(decstr)
        except RuntimeError as e:
            if 'overflow' in str(e) or 'underflow' in str(e):
                py_d = Object.parse(str(f))

        assert isclose(py_d, d, abs_tol=1e-5), (d, f.hex())
    else:
        with pytest.raises(PdfError):
            Object.parse(str(d)) 
开发者ID:pikepdf,项目名称:pikepdf,代码行数:20,代码来源:test_object.py

示例8: update

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def update(self, candle):
    self._adl.update(candle)
    adl = self._adl.v()

    if not isfinite(adl):
      return
    
    self._shortEMA.update(adl)
    self._longEMA.update(adl)

    short = self._shortEMA.v()
    long = self._longEMA.v()

    if (isfinite(short) and isfinite(long)):
      super().update(short - long)

    return self.v() 
开发者ID:bitfinexcom,项目名称:bfx-hf-indicators-py,代码行数:19,代码来源:chaikin_oscillator.py

示例9: add

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def add(self, candle):
    self._adl.add(candle)
    adl = self._adl.v()

    if not isfinite(adl):
      return
    
    self._shortEMA.add(adl)
    self._longEMA.add(adl)

    short = self._shortEMA.v()
    long = self._longEMA.v()

    if (isfinite(short) and isfinite(long)):
      super().add(short - long)

    return self.v() 
开发者ID:bitfinexcom,项目名称:bfx-hf-indicators-py,代码行数:19,代码来源:chaikin_oscillator.py

示例10: add

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def add(self, v):
    self._roc.add(v)
    roc = self._roc.v()

    if not isfinite(roc):
      return

    if len(self._buffer) == self._p:
      super().add(roc - self._buffer[0])

    self._buffer.append(roc)

    if len(self._buffer) > self._p:
      del self._buffer[0]

    return self.v() 
开发者ID:bitfinexcom,项目名称:bfx-hf-indicators-py,代码行数:18,代码来源:acceleration.py

示例11: add

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def add(self, v):
    slowEMA = self._slowEMA.add(v)
    fastEMA = self._fastEMA.add(v)

    if not isfinite(slowEMA) or not isfinite(fastEMA):
      return

    macd = fastEMA - slowEMA
    signalEMA = self._signalEMA.add(macd)

    if not isfinite(signalEMA):
      return

    histogram = macd - signalEMA

    super().add({
      'macd': macd,
      'signal': signalEMA,
      'histogram': histogram
    })

    return self.v() 
开发者ID:bitfinexcom,项目名称:bfx-hf-indicators-py,代码行数:24,代码来源:macd.py

示例12: update

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def update(self, v):
    if self._prevInputValue == None:
      return self.v()

    self._stddev.update(v)
    stddev = self._stddev.v()

    if not isfinite(stddev):
      return self.v()
    
    [u, d] = RVI.ud(v, self._prevInputValue, stddev)

    self._uEMA.update(u)
    self._dEMA.update(d)

    uSum = self._uEMA.v()
    dSum = self._dEMA.v()

    if uSum == dSum:
      return super().update(0)
    else:
      return super().update(100 * (uSum / (uSum + dSum))) 
开发者ID:bitfinexcom,项目名称:bfx-hf-indicators-py,代码行数:24,代码来源:relative_volatility_index.py

示例13: rvs

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def rvs(self) -> float:
        """
        Will return a float value in the specified range as specified at creation.

        :return: a float.
        """
        if self.hard_clip_min is None and self.hard_clip_max is None:
            result = float(np.random.normal(self._mean, self._std))
        else:
            a = -np.inf
            b = np.inf

            if self.hard_clip_min is not None:
                a = (self.hard_clip_min - self._mean) / self._std

            if self.hard_clip_max is not None:
                b = (self.hard_clip_max - self._mean) / self._std

            result = truncnorm.rvs(a=a, b=b, loc=self._mean, scale=self._std)

        if not math.isfinite(result):
            return self.rvs()
        return float(result) 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:25,代码来源:distributions.py

示例14: intersection

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def intersection(p1, p2, q1, q2, ret):
        px = p1.y - p2.y
        py = p2.x - p1.x
        pw = p1.x * p2.y - p2.x * p1.y
        
        qx = q1.y - q2.y
        qy = q2.x - q1.x
        qw = q1.x * q2.y - q2.x * q1.y

        x = py * qw - qy * pw
        y = qx * pw - px * qw
        w = px * qy - qx * py

        xInt = x / w
        yInt = y / w

        if not isfinite(xInt) or not isfinite(yInt):
            raise ArithmeticError()

        ret.x, ret.y = xInt, yInt 
开发者ID:s-leger,项目名称:archipack,代码行数:22,代码来源:algorithms.py

示例15: mean_average_precision_score

# 需要导入模块: import math [as 别名]
# 或者: from math import isfinite [as 别名]
def mean_average_precision_score(gold, pred, callback=None):
    total, count = 0., 0

    for question in gold.values():
        if question.id in pred:
            ranks = compute_ranks(list(question.explanations), pred[question.id])

            score = average_precision(ranks)

            if not math.isfinite(score):
                score = 0.

            total += score
            count += 1

            if callback:
                callback(question.id, score)

    mean_ap = total / count if count > 0 else 0.

    return mean_ap 
开发者ID:umanlp,项目名称:tg2019task,代码行数:23,代码来源:evaluate.py


注:本文中的math.isfinite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。