code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_neg,
(BigFloat._implicit_convert(x),),
context,
) | def neg(x, context=None) | Return -x. | 13.307238 | 13.102931 | 1.015592 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_abs,
(BigFloat._implicit_convert(x),),
context,
) | def abs(x, context=None) | Return abs(x). | 12.707308 | 12.6026 | 1.008308 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_dim,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def dim(x, y, context=None) | Return max(x - y, 0).
Return x - y if x > y, +0 if x <= y, and NaN if either x or y is NaN. | 7.150537 | 9.432891 | 0.758043 |
op1 = BigFloat._implicit_convert(op1)
op2 = BigFloat._implicit_convert(op2)
if is_nan(op1) or is_nan(op2):
raise ValueError("Cannot perform comparison with NaN.")
return mpfr.mpfr_cmp(op1, op2) | def cmp(op1, op2) | Perform a three-way comparison of op1 and op2.
Return a positive value if op1 > op2, zero if op1 = op2, and a negative
value if op1 < op2. Both op1 and op2 are considered to their full own
precision, which may differ. If one of the operands is NaN, raise
ValueError.
Note: This function may be usef... | 3.69498 | 3.902447 | 0.946837 |
op1 = BigFloat._implicit_convert(op1)
op2 = BigFloat._implicit_convert(op2)
if is_nan(op1) or is_nan(op2):
raise ValueError("Cannot perform comparison with NaN.")
return mpfr.mpfr_cmpabs(op1, op2) | def cmpabs(op1, op2) | Compare the absolute values of op1 and op2.
Return a positive value if op1 > op2, zero if op1 = op2, and a negative
value if op1 < op2. Both op1 and op2 are considered to their full own
precision, which may differ. If one of the operands is NaN, raise
ValueError.
Note: This function may be useful ... | 3.806784 | 4.059206 | 0.937815 |
x = BigFloat._implicit_convert(x)
if is_nan(x):
raise ValueError("Cannot take sign of a NaN.")
return mpfr.mpfr_sgn(x) | def sgn(x) | Return the sign of x.
Return a positive integer if x > 0, 0 if x == 0, and a negative integer if
x < 0. Raise ValueError if x is a NaN.
This function is equivalent to cmp(x, 0), but more efficient. | 9.163087 | 9.33046 | 0.982062 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_greater_p(x, y) | def greater(x, y) | Return True if x > y and False otherwise.
This function returns False whenever x and/or y is a NaN. | 5.934551 | 8.000957 | 0.74173 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_greaterequal_p(x, y) | def greaterequal(x, y) | Return True if x >= y and False otherwise.
This function returns False whenever x and/or y is a NaN. | 5.183678 | 7.030968 | 0.737264 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_less_p(x, y) | def less(x, y) | Return True if x < y and False otherwise.
This function returns False whenever x and/or y is a NaN. | 6.051977 | 8.133417 | 0.744088 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_lessequal_p(x, y) | def lessequal(x, y) | Return True if x <= y and False otherwise.
This function returns False whenever x and/or y is a NaN. | 5.750001 | 7.788715 | 0.738248 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_equal_p(x, y) | def equal(x, y) | Return True if x == y and False otherwise.
This function returns False whenever x and/or y is a NaN. | 5.990026 | 8.170936 | 0.733089 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return not mpfr.mpfr_equal_p(x, y) | def notequal(x, y) | Return True if x != y and False otherwise.
This function returns True whenever x and/or y is a NaN. | 7.050556 | 9.153898 | 0.770224 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_lessgreater_p(x, y) | def lessgreater(x, y) | Return True if x < y or x > y and False otherwise.
This function returns False whenever x and/or y is a NaN. | 6.170107 | 8.303854 | 0.743041 |
x = BigFloat._implicit_convert(x)
y = BigFloat._implicit_convert(y)
return mpfr.mpfr_unordered_p(x, y) | def unordered(x, y) | Return True if x or y is a NaN and False otherwise. | 6.50469 | 6.458997 | 1.007074 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_log,
(BigFloat._implicit_convert(x),),
context,
) | def log(x, context=None) | Return the natural logarithm of x. | 12.354224 | 12.794211 | 0.96561 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_log2,
(BigFloat._implicit_convert(x),),
context,
) | def log2(x, context=None) | Return the base-two logarithm of x. | 12.055848 | 12.953928 | 0.930671 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_log10,
(BigFloat._implicit_convert(x),),
context,
) | def log10(x, context=None) | Return the base-ten logarithm of x. | 10.882469 | 11.852426 | 0.918164 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_exp,
(BigFloat._implicit_convert(x),),
context,
) | def exp(x, context=None) | Return the exponential of x. | 12.021604 | 12.342786 | 0.973978 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_exp2,
(BigFloat._implicit_convert(x),),
context,
) | def exp2(x, context=None) | Return two raised to the power x. | 11.863485 | 11.731918 | 1.011214 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_exp10,
(BigFloat._implicit_convert(x),),
context,
) | def exp10(x, context=None) | Return ten raised to the power x. | 10.803794 | 10.33105 | 1.04576 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_cos,
(BigFloat._implicit_convert(x),),
context,
) | def cos(x, context=None) | Return the cosine of ``x``. | 12.311567 | 13.236899 | 0.930094 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_sin,
(BigFloat._implicit_convert(x),),
context,
) | def sin(x, context=None) | Return the sine of ``x``. | 13.403067 | 14.361096 | 0.93329 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_tan,
(BigFloat._implicit_convert(x),),
context,
) | def tan(x, context=None) | Return the tangent of ``x``. | 12.803681 | 13.814771 | 0.926811 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_sec,
(BigFloat._implicit_convert(x),),
context,
) | def sec(x, context=None) | Return the secant of ``x``. | 13.078995 | 13.212665 | 0.989883 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_csc,
(BigFloat._implicit_convert(x),),
context,
) | def csc(x, context=None) | Return the cosecant of ``x``. | 12.149011 | 13.874148 | 0.875658 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_cot,
(BigFloat._implicit_convert(x),),
context,
) | def cot(x, context=None) | Return the cotangent of ``x``. | 12.634162 | 13.87194 | 0.910771 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_acos,
(BigFloat._implicit_convert(x),),
context,
) | def acos(x, context=None) | Return the inverse cosine of ``x``.
The mathematically exact result lies in the range [0, π]. However, note
that as a result of rounding to the current context, it's possible for the
actual value returned to be fractionally larger than π::
>>> from bigfloat import precision
>>> with preci... | 12.420892 | 18.978735 | 0.654464 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_asin,
(BigFloat._implicit_convert(x),),
context,
) | def asin(x, context=None) | Return the inverse sine of ``x``.
The mathematically exact result lies in the range [-π/2, π/2]. However,
note that as a result of rounding to the current context, it's possible
for the actual value to lie just outside this range. | 14.027686 | 17.136927 | 0.818565 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_atan,
(BigFloat._implicit_convert(x),),
context,
) | def atan(x, context=None) | Return the inverse tangent of ``x``.
The mathematically exact result lies in the range [-π/2, π/2]. However,
note that as a result of rounding to the current context, it's possible
for the actual value to lie just outside this range. | 12.954076 | 15.948167 | 0.812261 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_atan2,
(
BigFloat._implicit_convert(y),
BigFloat._implicit_convert(x),
),
context,
) | def atan2(y, x, context=None) | Return ``atan(y / x)`` with the appropriate choice of function branch.
If ``x > 0``, then ``atan2(y, x)`` is mathematically equivalent to ``atan(y
/ x)``. If ``x < 0`` and ``y > 0``, ``atan(y, x)`` is equivalent to ``π +
atan(y, x)``. If ``x < 0`` and ``y < 0``, the result is ``-π + atan(y,
x)``.
... | 7.228373 | 10.909595 | 0.66257 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_cosh,
(BigFloat._implicit_convert(x),),
context,
) | def cosh(x, context=None) | Return the hyperbolic cosine of x. | 12.47486 | 12.862328 | 0.969876 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_sinh,
(BigFloat._implicit_convert(x),),
context,
) | def sinh(x, context=None) | Return the hyperbolic sine of x. | 12.777324 | 13.013489 | 0.981852 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_tanh,
(BigFloat._implicit_convert(x),),
context,
) | def tanh(x, context=None) | Return the hyperbolic tangent of x. | 13.482313 | 14.201577 | 0.949353 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_sech,
(BigFloat._implicit_convert(x),),
context,
) | def sech(x, context=None) | Return the hyperbolic secant of x. | 12.524677 | 12.661355 | 0.989205 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_csch,
(BigFloat._implicit_convert(x),),
context,
) | def csch(x, context=None) | Return the hyperbolic cosecant of x. | 13.112159 | 14.285136 | 0.917888 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_coth,
(BigFloat._implicit_convert(x),),
context,
) | def coth(x, context=None) | Return the hyperbolic cotangent of x. | 12.495841 | 12.776045 | 0.978068 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_acosh,
(BigFloat._implicit_convert(x),),
context,
) | def acosh(x, context=None) | Return the inverse hyperbolic cosine of x. | 12.445549 | 13.116021 | 0.948881 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_asinh,
(BigFloat._implicit_convert(x),),
context,
) | def asinh(x, context=None) | Return the inverse hyperbolic sine of x. | 13.470701 | 13.911873 | 0.968288 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_atanh,
(BigFloat._implicit_convert(x),),
context,
) | def atanh(x, context=None) | Return the inverse hyperbolic tangent of x. | 13.173924 | 13.831656 | 0.952447 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_log1p,
(BigFloat._implicit_convert(x),),
context,
) | def log1p(x, context=None) | Return the logarithm of one plus x. | 10.85423 | 11.215068 | 0.967826 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_expm1,
(BigFloat._implicit_convert(x),),
context,
) | def expm1(x, context=None) | Return one less than the exponential of x. | 11.111504 | 11.001763 | 1.009975 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_eint,
(BigFloat._implicit_convert(x),),
context,
) | def eint(x, context=None) | Return the exponential integral of x. | 12.490485 | 12.10501 | 1.031844 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_li2,
(BigFloat._implicit_convert(x),),
context,
) | def li2(x, context=None) | Return the real part of the dilogarithm of x. | 12.559909 | 11.679283 | 1.075401 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_gamma,
(BigFloat._implicit_convert(x),),
context,
) | def gamma(x, context=None) | Return the value of the Gamma function of x. | 12.978485 | 12.617677 | 1.028595 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_lngamma,
(BigFloat._implicit_convert(x),),
context,
) | def lngamma(x, context=None) | Return the value of the logarithm of the Gamma function of x. | 12.363128 | 13.189069 | 0.937377 |
return _apply_function_in_current_context(
BigFloat,
lambda rop, op, rnd: mpfr.mpfr_lgamma(rop, op, rnd)[0],
(BigFloat._implicit_convert(x),),
context,
) | def lgamma(x, context=None) | Return the logarithm of the absolute value of the Gamma function at x. | 12.06911 | 12.483347 | 0.966817 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_digamma,
(BigFloat._implicit_convert(x),),
context,
) | def digamma(x, context=None) | Return the value of the digamma (sometimes also called Psi) function on op. | 11.756928 | 12.001722 | 0.979603 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_zeta,
(BigFloat._implicit_convert(x),),
context,
) | def zeta(x, context=None) | Return the value of the Riemann zeta function on x. | 11.438344 | 11.991658 | 0.953858 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_erf,
(BigFloat._implicit_convert(x),),
context,
) | def erf(x, context=None) | Return the value of the error function at x. | 10.828225 | 11.826287 | 0.915606 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_erfc,
(BigFloat._implicit_convert(x),),
context,
) | def erfc(x, context=None) | Return the value of the complementary error function at x. | 11.273258 | 12.233841 | 0.921482 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_j0,
(BigFloat._implicit_convert(x),),
context,
) | def j0(x, context=None) | Return the value of the first kind Bessel function of order 0 at x. | 12.098229 | 13.283297 | 0.910785 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_j1,
(BigFloat._implicit_convert(x),),
context,
) | def j1(x, context=None) | Return the value of the first kind Bessel function of order 1 at x. | 12.111751 | 13.607745 | 0.890063 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_jn,
(n, BigFloat._implicit_convert(x)),
context,
) | def jn(n, x, context=None) | Return the value of the first kind Bessel function of order ``n`` at ``x``.
``n`` should be a Python integer. | 12.44228 | 17.768129 | 0.700258 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_y0,
(BigFloat._implicit_convert(x),),
context,
) | def y0(x, context=None) | Return the value of the second kind Bessel function of order 0 at x. | 12.623765 | 13.732327 | 0.919274 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_y1,
(BigFloat._implicit_convert(x),),
context,
) | def y1(x, context=None) | Return the value of the second kind Bessel function of order 1 at x. | 12.751699 | 13.786044 | 0.924972 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_yn,
(n, BigFloat._implicit_convert(x)),
context,
) | def yn(n, x, context=None) | Return the value of the second kind Bessel function of order ``n`` at
``x``.
``n`` should be a Python integer. | 13.076189 | 19.591433 | 0.667444 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_fma,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
BigFloat._implicit_convert(z),
),
context,
) | def fma(x, y, z, context=None) | Return (x * y) + z, with a single rounding according to the current
context. | 4.866287 | 5.177339 | 0.939921 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_fms,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
BigFloat._implicit_convert(z),
),
context,
) | def fms(x, y, z, context=None) | Return (x * y) - z, with a single rounding according to the current
context. | 4.857854 | 5.046887 | 0.962545 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_agm,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def agm(x, y, context=None) | Return the arithmetic geometric mean of x and y. | 6.515758 | 6.357614 | 1.024875 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_hypot,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def hypot(x, y, context=None) | Return the Euclidean norm of x and y, i.e., the square root of the sum of
the squares of x and y. | 6.898762 | 7.493403 | 0.920645 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_ai,
(BigFloat._implicit_convert(x),),
context,
) | def ai(x, context=None) | Return the Airy function of x. | 13.391904 | 13.932606 | 0.961192 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_rint_ceil,
(BigFloat._implicit_convert(x),),
context,
) | def ceil(x, context=None) | Return the next higher or equal integer to x.
If the result is not exactly representable, it will be rounded according to
the current context. Note that the rounding step means that it's possible
for the result to be smaller than ``x``. For example::
>>> x = 2**100 + 1
>>> ceil(2**100 + ... | 14.184353 | 14.035156 | 1.01063 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_rint_floor,
(BigFloat._implicit_convert(x),),
context,
) | def floor(x, context=None) | Return the next lower or equal integer to x.
If the result is not exactly representable, it will be rounded according to
the current context.
Note that it's possible for the result to be larger than ``x``. See the
documentation of the :func:`ceil` function for more information.
.. note::
... | 14.720509 | 13.487437 | 1.091424 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_rint_round,
(BigFloat._implicit_convert(x),),
context,
) | def round(x, context=None) | Return the nearest integer to x, rounding halfway cases *away from zero*.
If the result is not exactly representable, it will be rounded according to
the current context.
.. note::
This function corresponds to the MPFR function ``mpfr_rint_round``, not
to ``mpfr_round``. | 14.784692 | 13.46505 | 1.098005 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_rint_trunc,
(BigFloat._implicit_convert(x),),
context,
) | def trunc(x, context=None) | Return the next integer towards zero.
If the result is not exactly representable, it will be rounded according to
the current context.
.. note::
This function corresponds to the MPFR function ``mpfr_rint_trunc``,
not to ``mpfr_trunc``. | 14.463476 | 13.870763 | 1.042731 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_frac,
(BigFloat._implicit_convert(x),),
context,
) | def frac(x, context=None) | Return the fractional part of ``x``.
The result has the same sign as ``x``. | 12.190042 | 15.512073 | 0.785842 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_fmod,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def fmod(x, y, context=None) | Return ``x`` reduced modulo ``y``.
Returns the value of x - n * y, where n is the integer quotient of x
divided by y, rounded toward zero.
Special values are handled as described in Section F.9.7.1 of the ISO C99
standard: If x is infinite or y is zero, the result is NaN. If y is
infinite and x is... | 6.914576 | 8.849515 | 0.781351 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_remainder,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def remainder(x, y, context=None) | Return x reduced modulo y.
Returns the value of x - n * y, where n is the integer quotient of x
divided by y, rounded to the nearest integer (ties rounded to even).
Special values are handled as described in Section F.9.7.1 of the ISO C99
standard: If x is infinite or y is zero, the result is NaN. If ... | 7.567576 | 9.50304 | 0.796332 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_min,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def min(x, y, context=None) | Return the minimum of x and y.
If x and y are both NaN, return NaN. If exactly one of x and y is NaN,
return the non-NaN value. If x and y are zeros of different signs, return
−0. | 7.184196 | 9.108191 | 0.788762 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_max,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def max(x, y, context=None) | Return the maximum of x and y.
If x and y are both NaN, return NaN. If exactly one of x and y is NaN,
return the non-NaN value. If x and y are zeros of different signs, return
+0. | 6.93127 | 8.61798 | 0.80428 |
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_copysign,
(
BigFloat._implicit_convert(x),
BigFloat._implicit_convert(y),
),
context,
) | def copysign(x, y, context=None) | Return a new BigFloat object with the magnitude of x but the sign of y. | 7.52351 | 6.026424 | 1.24842 |
# figure out precision to use
if isinstance(value, six.string_types):
if precision is None:
raise TypeError("precision must be supplied when "
"converting from a string")
else:
if precision is not None:
... | def exact(cls, value, precision=None) | Convert an integer, float or BigFloat with no loss of precision.
Also convert a string with given precision.
This constructor makes no use of the current context. | 4.710488 | 4.614763 | 1.020743 |
m = self.copy()
if self and is_finite(self):
mpfr.mpfr_set_exp(m, 0)
mpfr.mpfr_setsign(m, m, False, ROUND_TIES_TO_EVEN)
return m | def _significand(self) | Return the significand of self, as a BigFloat.
If self is a nonzero finite number, return a BigFloat m
with the same precision as self, such that
0.5 <= m < 1. and
self = +/-m * 2**e
for some exponent e.
If self is zero, infinity or nan, return a copy of self with... | 11.699206 | 9.651649 | 1.212146 |
if self and is_finite(self):
return mpfr.mpfr_get_exp(self)
if not self:
return '0'
elif is_inf(self):
return 'inf'
elif is_nan(self):
return 'nan'
else:
assert False, "shouldn't ever get here" | def _exponent(self) | Return the exponent of self, as an integer.
The exponent is defined as the unique integer k such that
2**(k-1) <= abs(self) < 2**k.
If self is not finite and nonzero, return a string: one
of '0', 'inf' or 'nan'. | 4.764613 | 4.196188 | 1.135462 |
result = mpfr.Mpfr_t.__new__(BigFloat)
mpfr.mpfr_init2(result, self.precision)
mpfr.mpfr_set(result, self, ROUND_TIES_TO_EVEN)
return result | def copy(self) | Return a copy of self.
This function does not make use of the context. The result has the
same precision as the original. | 9.695041 | 8.663513 | 1.119066 |
result = mpfr.Mpfr_t.__new__(BigFloat)
mpfr.mpfr_init2(result, self.precision)
new_sign = not self._sign()
mpfr.mpfr_setsign(result, self, new_sign, ROUND_TIES_TO_EVEN)
return result | def copy_neg(self) | Return a copy of self with the opposite sign bit.
Unlike -self, this does not make use of the context: the result
has the same precision as the original. | 10.262334 | 9.684329 | 1.059685 |
result = mpfr.Mpfr_t.__new__(BigFloat)
mpfr.mpfr_init2(result, self.precision)
mpfr.mpfr_setsign(result, self, False, ROUND_TIES_TO_EVEN)
return result | def copy_abs(self) | Return a copy of self with the sign bit unset.
Unlike abs(self), this does not make use of the context: the result
has the same precision as the original. | 11.347849 | 9.698001 | 1.170122 |
sign = '-' if self._sign() else ''
e = self._exponent()
if isinstance(e, six.string_types):
return sign + e
m = self._significand()
_, digits, _ = _mpfr_get_str2(
16,
0,
m,
ROUND_TIES_TO_EVEN,
)
... | def hex(self) | Return a hexadecimal representation of a BigFloat. | 7.285595 | 6.66819 | 1.09259 |
if not is_finite(self):
raise ValueError("Can't express infinity or nan as "
"an integer ratio")
elif not self:
return 0, 1
# convert to a hex string, and from there to a fraction
negative, digits, e = _mpfr_get_str2(
... | def as_integer_ratio(self) | Return pair n, d of integers such that the value of self is
exactly equal to n/d, n and d are relatively prime, and d >= 1. | 6.883364 | 6.565932 | 1.048345 |
if precision <= 0:
raise ValueError("precision argument should be at least 1")
sign, digits, exp = _mpfr_get_str2(
10,
precision,
self,
ROUND_TIES_TO_EVEN,
)
return sign, digits, exp - len(digits) | def _format_to_floating_precision(self, precision) | Format a nonzero finite BigFloat instance to a given number of
significant digits.
Returns a triple (negative, digits, exp) where:
- negative is a boolean, True for a negative number, else False
- digits is a string giving the digits of the output
- exp represents the exp... | 8.39608 | 7.566804 | 1.109594 |
# MPFR only provides functions to format to a given number of
# significant digits. So we must:
#
# (1) Identify an e such that 10**(e-1) <= abs(x) < 10**e.
#
# (2) Determine the number of significant digits required, and format
# to that numbe... | def _format_to_fixed_precision(self, precision) | Format 'self' to a given number of digits after the decimal point.
Returns a triple (negative, digits, exp) where:
- negative is a boolean, True for a negative number, else False
- digits is a string giving the digits of the output
- exp represents the exponent of the output
... | 4.279296 | 4.105073 | 1.042441 |
# ints, long and floats mix freely with BigFloats, and are
# converted exactly.
if isinstance(arg, six.integer_types) or isinstance(arg, float):
return cls.exact(arg)
elif isinstance(arg, BigFloat):
return arg
else:
raise TypeError("U... | def _implicit_convert(cls, arg) | Implicit conversion used for binary operations, comparisons,
functions, etc. Return value should be an instance of
BigFloat. | 5.474535 | 4.582907 | 1.194555 |
hashes = list(bin_hashes)
# if there are an odd number of hashes, double up the last one
if len(hashes) % 2 == 1:
hashes.append(hashes[-1])
new_hashes = []
for i in range(0, len(hashes), 2):
new_hashes.append(hash_function(hashes[i] + hashes[i+1]))
return new_hashes | def calculate_merkle_pairs(bin_hashes, hash_function=bin_double_sha256) | Calculate the parents of a row of a merkle tree.
Takes in a list of binary hashes, returns a binary hash.
The returned parents list is such that parents[i] == hash(bin_hashes[2*i] + bin_hashes[2*i+1]). | 2.160324 | 2.36085 | 0.915062 |
merkle_root = hex_to_bin_reversed(merkle_root_hex)
leaf_hash = hex_to_bin_reversed(leaf_hash_hex)
path = MerkleTree.path_deserialize(serialized_path)
path = [{'order': p['order'], 'hash': hex_to_bin_reversed(p['hash'])} for p in path]
if len(path) == 0:
raise ValueError("Empty pa... | def verify_merkle_path(merkle_root_hex, serialized_path, leaf_hash_hex, hash_function=bin_double_sha256) | Verify a merkle path. The given path is the path from two leaf nodes to the root itself.
merkle_root_hex is a little-endian, hex-encoded hash.
serialized_path is the serialized merkle path
path_hex is a list of little-endian, hex-encoded hashes.
Return True if the path is consistent with the merkle r... | 2.156871 | 2.181772 | 0.988587 |
# make it into a netstring
path_parts = ['{}-{}'.format(p['order'], p['hash']) for p in path]
path_ns_parts = ['{}:{},'.format(len(pp), pp) for pp in path_parts]
path_str = ''.join(path_ns_parts)
return '{}:{},'.format(len(path_str), path_str) | def path_serialize(cls, path) | Given a list of [{'hash': ..., 'order': ...}], serialize it to a string. | 4.892105 | 3.953057 | 1.23755 |
def _chomp_netstring_payload(s):
try:
ns_len_str, ns_body = s.split(':', 1)
ns_len = int(ns_len_str)
assert ns_body[ns_len] == ','
ns_payload = ns_body[:ns_len]
return ns_payload, ns_body[ns_len+1:]
... | def path_deserialize(cls, serialized_path) | Given a netstring of path parts, go and parse it back into [{'hash': ..., 'order': ...}] | 3.288399 | 2.77969 | 1.183009 |
leaf_hash = hex_to_bin_reversed(leaf_hash_hex)
# sanity check
found = False
ri = None # index into self.rows where leaf_hash occurs. Note that self.rows[0] is the bottom (leaves) of the Merkle tree.
for ri, row in enumerate(self.rows):
found ... | def path(self, leaf_hash_hex, serialize=True) | Get the path (as a list of hashes) from the leaf hash to the root.
leaf_hash_hex is hex-encoded, little-endian.
The returned path will be a list of {'hash': hex-encoded little-endian hash, 'order': 'l' or 'r'}
Raise ValueError if leaf_hash is not present in the tree. | 2.803888 | 2.701219 | 1.038008 |
# c = coords.transform_to(self._frame)
# vec = np.empty((c.shape[0], 2), dtype='f8')
# vec[:,0] = coordinates.Longitude(coords.l, wrap_angle=360.*units.deg).deg[:]
# vec[:,1] = coords.b.deg[:]
# return np.radians(vec)
c = coords.transform_to(self._frame).repres... | def _coords2vec(self, coords) | Converts from sky coordinates to unit vectors. Before conversion to unit
vectors, the coordiantes are transformed to the coordinate system used
internally by the :obj:`UnstructuredDustMap`, which can be set during
initialization of the class.
Args:
coords (:obj:`astropy.coor... | 3.01035 | 2.823865 | 1.066039 |
x = self._coords2vec(coords)
idx = self._kd.query(x, p=self._metric_p,
distance_upper_bound=self._max_pix_scale)
return idx[1] | def _coords2idx(self, coords) | Converts from sky coordinates to pixel indices.
Args:
coords (:obj:`astropy.coordinates.SkyCoord`): Sky coordinates.
Returns:
Pixel indices of the coordinates, with the same shape as the input
coordinates. Pixels which are outside the map are given an index
... | 8.835362 | 8.998177 | 0.981906 |
table_dir = os.path.join(data_dir(), 'marshall')
# Check if file already exists
if not clobber:
h5_fname = os.path.join(table_dir, 'marshall.h5')
h5_size = 5033290 # Guess, in Bytes
h5_dsets = {
'l': (801, 81),
'b': (801, 81),
'chi2_all': (8... | def fetch(clobber=False) | Downloads the Marshall et al. (2006) dust map, which is based on 2MASS
stellar photometry.
Args:
clobber (Optional[:obj:`bool`]): If ``True``, any existing file will be
overwritten, even if it appears to match. If ``False`` (the
default), :obj:`fetch()` will attempt to determine... | 3.351429 | 3.255563 | 1.029447 |
# Make sure that l is in domain [-180 deg, 180 deg)
l = coordinates.Longitude(gal.l, wrap_angle=180.*units.deg)
j = (self._inv_pix_scale * (l.deg - self._l_bounds[0])).astype('i4')
k = (self._inv_pix_scale * (gal.b.deg - self._b_bounds[0])).astype('i4')
idx = (j < 0) ... | def _gal2idx(self, gal) | Converts from Galactic coordinates to pixel indices.
Args:
gal (:obj:`astropy.coordinates.SkyCoord`): Galactic coordinates. Must
store an array of coordinates (i.e., not be scalar).
Returns:
``j, k, mask`` - Pixel indices of the coordinates, as well as a mask
... | 3.28132 | 2.947734 | 1.113167 |
if len(self.block_hashes) > 2000:
raise Exception("A getheaders request cannot have over 2000 block hashes")
hash_num = int("0x" + block_hash, 16)
bh = BlockHash()
bh.block_hash = hash_num
self.block_hashes.append( bh )
self.hash_stop = has... | def add_block_hash( self, block_hash ) | Append up to 2000 block hashes for which to get headers. | 4.697821 | 3.663204 | 1.282435 |
self.handshake()
try:
self.loop()
except socket.error, se:
if self.finished:
return True
else:
raise | def run( self ) | Interact with the blockchain peer,
until we get a socket error or we
exit the loop explicitly.
Return True on success
Raise on error | 7.982571 | 5.439982 | 1.467389 |
getheaders = GetHeaders()
getheaders.add_block_hash( prev_block_hash )
log.debug("send getheaders")
self.send_message( getheaders ) | def send_getheaders( self, prev_block_hash ) | Request block headers from a particular block hash.
Will receive up to 2000 blocks, starting with the block *after*
the given block hash (prev_block_hash) | 4.716636 | 4.418884 | 1.067382 |
log.debug("handle version")
verack = VerAck()
log.debug("send VerAck")
self.send_message(verack)
self.verack = True
# begin!
self.send_getheaders( self.first_block_hash ) | def handle_version(self, message_header, message) | This method will handle the Version message and
will send a VerAck message when it receives the
Version message.
:param message_header: The Version message header
:param message: The Version message | 8.163481 | 8.044827 | 1.014749 |
log.debug("handle ping")
pong = Pong()
pong.nonce = message.nonce
log.debug("send pong")
self.send_message(pong) | def handle_ping(self, message_header, message) | This method will handle the Ping message and then
will answer every Ping message with a Pong message
using the nonce received.
:param message_header: The header of the Ping message
:param message: The Ping message | 3.873928 | 3.692646 | 1.049093 |
if not os.path.exists( path ):
block_header_serializer = BlockHeaderSerializer()
genesis_block_header = BlockHeader()
if USE_MAINNET:
# we know the mainnet block header
# but we don't know the testnet/regtest block header
... | def init(cls, path) | Set up an SPV client.
If the locally-stored headers do not exist, then
create a stub headers file with the genesis block information. | 2.644802 | 2.534553 | 1.043498 |
if os.path.exists( path ):
sb = os.stat( path )
h = (sb.st_size / BLOCK_HEADER_SIZE) - 1
return h
else:
return None | def height(cls, path) | Get the locally-stored block height | 5.344544 | 4.349082 | 1.22889 |
header_parser = BlockHeaderSerializer()
hdr = header_parser.deserialize( f )
h = {}
h['version'] = hdr.version
h['prev_block_hash'] = "%064x" % hdr.prev_block
h['merkle_root'] = "%064x" % hdr.merkle_root
h['timestamp'] = hdr.timestamp
h['bits'] = ... | def read_header_at( cls, f) | Given an open file-like object, read a block header
from it and return it as a dict containing:
* version (int)
* prev_block_hash (hex str)
* merkle_root (hex str)
* timestamp (int)
* bits (int)
* nonce (ini)
* hash (hex str) | 2.420146 | 2.092884 | 1.156369 |
header_parser = BlockHeaderSerializer()
chain = []
height = 0
with open(chain_path, "rb") as f:
h = SPVClient.read_header_at( f )
h['block_height'] = height
height += 1
chain.append(h)
return chain | def load_header_chain( cls, chain_path ) | Load the header chain from disk.
Each chain element will be a dictionary with:
* | 7.280338 | 7.961097 | 0.914489 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.