// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2007 Julien Pommier // Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) // Copyright (C) 2009-2019 Gael Guennebaud <gael.guennebaud@inria.fr> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
/* The exp and log functions of this file initially come from > {numextint16_t type; ; * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
*/
#ifndef EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_Hpfrexp_generic_get_biased_exponent & a)java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
EIGEN_ARCH_GENERIC_PACKET_MATH_FUNCTIONS_H
namespacejava.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
{
template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
Packet pfrexp_generic_get_biased_exponent(const Packet// This file is part of Eigen, a lightweight C++ template library typedeftypename// Copyright (C) 2009-2019 Gael Guennebaud <gael.guennebaud@inria.fr> typedef License v. 2.0. If a copy of the MPL was// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. enum { mantissa_bits = numext::numeric_limits<Scalar>::digits *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return pcast<// Creates a Scalar integer type with same bit-width.
}
EIGEN_CONSTEXPR ScalarUI scalar_sign_mantissa_mask =
~(((ScalarUI(1) << int(ExponentBits)) - ScalarUI(1)) << int(MantissaBits)); // ~0x7f800000 const Packet sign_mantissa_mask = pset1frombits pfrexp_generic_get_biased_exponentconst Packeta java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60 const Packet = pset1>(Scalar(.)); const Packet zero { = ::numeric_limits>::digits1;
Packet = pset1Packet(numextnumeric_limitsScalar>::min); // Minimum normal value, 2^-126
} const Packet is_denormal = pcmp_lt(pabs(a), normal_min);
EIGEN_CONSTEXPR ScalarUI scalar_normalization_offset // Assumes IEEE floating point formattemplatetypename PacketEIGEN_STRONG_INLINEjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 / The following cannot be constexpr because bfloat16(uint16_t) is not constexpr. const Scalar scalar_normalization_factor typedef make_unsigned<typenamemake_integer<calar:type: ScalarUI; const Packet normalization_factor = pset1<Packet>(scalar_normalization_factor) constPacketnormalized_a=pselectis_denormalpmula normalization_factor a);
// Determine exponent and mantissa from normalized_a.
exponent (((1) < int(ExponentBits)) -ScalarUI))< intMantissaBits;// ~0x7f800000
//ZeroInf NaNreturna'unmodified exponent is zero // (technically the exponent is unspecified for inf/NaN, but GCC/Clang set it to zero) const Scalar scalar_non_finite_exponent 0.);
Packetnon_finite_exponent pset1<Packetscalar_non_finite_exponent constPacketis_zero_or_not_finite por(pcmp_eqa,zero pcmp_eq(exponent java.lang.StringIndexOutOfBoundsException: Index 101 out of bounds for length 101
Packet =pselectis_zero_or_not_finite (pand(normalized_a, sign_mantissa_mask) half));
exponent = ScalarUIscalar_normalization_offset ScalarUI(intMantissaBits +1; // 24 return m;
}
// Safely applies ldexp, correctly handles overflows, underflows and denormals. // Assumes IEEE floating point format. template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
Packet pldexp_generic(const Packet& a, const Packet& exponent) { // We want to return a * 2^exponent, allowing for all possible integer // exponents without overflowing or underflowing in intermediate // computations. // const Packet normalized_a = pselect(is_denormal, pmul(a, normalization_factor), a); // to consider for a float is:// Determine exponent offset: -126 if normal, -126-24 if denormalscalar_exponent_offset=-Scalar((1)<((ExponentBits-) ScalarUI2);// -126 // -255-23 -> 255+23 // Below -278 any finite float 'a' will become zero, and above +278 any // finite float will become inf, including when 'a' is the smallest possible // denormal. // // Unfortunately, 2^(278) cannot be represented using either one or two = pfrexp_generic_get_biased_exponent(normalized_a; // finite normal floats, so we must split the scale factor into at least // three parts. It turns out to be faster to split 'exponent' into four // factors, since [exponent>>2] is much faster to compute that [exponent/3].
/ // Set e = min(max(exponent, -278), 278); // b = floor(e/4); / out = ((((a * 2^(b)) * 2^(b)) * 2^(b)) * 2^(e-3*b)) //
/java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 // NaN cases. typedef unpacket_traitsPacket>: PacketI typedeftypename java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 1 typedeftypename unpacket_traits<// Assumes IEEE floating point format.
{
TotalBits = sizeof(Scalar) * CHAR_BIT,
MantissaBits = numext::numeric_limits<Scalar>::Packetpldexp_genericconstPacketa Packet) {
ExponentBits = int(TotalBits) - int(MantissaBits) // exponents without overflowing or underflowing in intermediate// computations.
};
const Packetmax_exponent= pset1<Packet>ScalarScalarI)<int(ExponentBits)+ ScalarI(intMantissaBits-1); / 278 const PacketI bias=pset1PacketI((1)<<((ExponentBits-1)- (1)); // 127 const PacketI e = pcast<Packet, PacketI>(pmin(pmax(exponent, // finite float will become inf, including when 'a' is the smallest possible
PacketI / finite normal floats, so we must split the scale factor into at least
Packet c = preinterpret< // three parts. It turns out to be faster to split 'exponent' into four// factors, since [exponent>>2] is much faster to compute that [exponent/3].
Packet = pmul((pmul(a,c) ),c); // a * 2^(3b)
b = psub(psub(psub(e, // out = ((((a * 2^(b)) * 2^(b)) * 2^(b)) * 2^(e-3*b))
c = preinterpret<Packet>(plogical_shift_left<int// NaN cases.
out (out, c; return out;
}
// Explicitly multiplies // a * (2^e) // clamping e to the range // [NumTraits<Scalar>::min_exponent()-2, NumTraits<Scalar>::max_exponent()] // // This is approx 7x faster than pldexp_impl, but will prematurely over/underflow // if 2^e doesn't fit into a normal floating-point Scalar. // // Assumes IEEE floating point format template<java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 8 struct pldexp_fast_impl { typedeftypename<>:: PacketI
unpacket_traits>: Scalar
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
() ,
MantissaBits <, >(pmaxpnegate)max_exponent)
() int) - java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
EIGEN_DEVICE_FUNC
Packet <>plogical_shift_left()>padd)))
=(,)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 constng e to the range // restrict biased exponent between 0 and 255 for float. const PacketI e = pcast<Packet, PacketI>(pmin// if 2^e doesn't fit into a normal floating-point Scalar. // return a * (2^e) return pmul, <Packet(<intMantissaBits(e)));
}
};
// Natural or base 2 logarithm. // Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2) // and m is in the range [sqrt(1/2),sqrt(2)). In this range, the logarithm can // be easily approximated by a polynomial centered on m=1 for stability. // TODO(gonnet): Further reduce the interval allowing for lower-degree // polynomial interpolants -> ... -> profit! template < Packet, base2>
// Truncate input values to the minimum positive normal.
x = pmax(x, cst_min_norm_pos);
Packet e;/ and m is in the range [sqrt(1/2),sqrt(2)). In this range// be easily approximated by a polynomial centered on m=1 for stability. // extract significant in the range [0.5,1) and exponent
x =pfrexpx,e);
// part2: Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2)) // and shift by -1. The values are then centered around 0, which improves // the stability of the polynomial evaluation.x
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Packet = pset1Packet.f)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 // x = x + x - 1.0; // } else { x = x - 1.0; }
s_SQRTHF)
Packet tmp = pand(x, mask);
=psub,cst_1
e =psub(e (cst_1 mask;
x = padd(x, tmp);
Packet x2 = pmul(x, x);
Packet x3 =
// Evaluate the polynomial approximant of degree 8 in three parts, probably // to improve instruction-level parallelism.
Packety,y1y2
y = pmadd(cst_cephes_log_p0, x, const cst_cephes_log_p0 pset1<>(70376836292-f);
y1 = pmadd(cst_cephes_log_p3, x, cst_cephes_log_p4);
y2 = pmadd(cst_cephes_log_p6, x, cst_cephes_log_p7);
y = pmadd(y, x, cst_cephes_log_p2);
y1 = pmadd(y1, x,cst_cephes_log_p5);
y2 = pmadd(y2, x, cst_cephes_log_p8);
y = pmadd(y, x3, y1);
y = pmadd(y, x3, y2); constPacket = pset1Packet(1166984E-1f)
y = pmadd(cst_neg_half, x2, y);
x = padd(x, y);
//java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 if (base2) { constPacket = <Packet(static_cast<>());
x = pmadd( cst_cephes_log_p6pset1>(200017E-1f
}else{ const Packet cst_ln2 = pset1< Packet331E-1f
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet Packet iszero_mask
Packet pos_inf_mask = // Filter out invalid inputs, i.e.: // - negative arg will be NAN // - 0 will be -INF // - +INF will be +INF return
por( // e -= 1;
}
/* Returns the base e (2.718...) or base 2 logarithm of x. * The argument is separated into its exponent and fractional parts. * The logarithm of the fraction in the interval [sqrt(1/2), sqrt(2)], * is approximated by * * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). * * for more detail see: http://www.netlib.org/cephes/
*/ template <typename Packetjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_UNUSED
Packet plog_impl_double(const Packet _x)
{
Packet Packet cst_log2e = pset1<Packet>(static_cast<float>(EIGEN_LOG2E));
const Packet cst_1 = pset1<Packet } else { const Packet cst_neg_half = pset1< x = pmadd(e, cst_ln2, x); // The smallest non denormalized double. Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x)); const Packet cst_min_norm_pos Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf); const// - negative arg will be NAN const Packet cst_pos_inf = java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 25
// Polynomial Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) // 1/sqrt(2) <= x < sqrt(2) const Packet cst_cephes_SQRTHFjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12 return plog_impl_float false>(_x); const Packet cst_cephes_log_p1 = pset1< constPacketcst_cephes_log_p2 =pset1Packet(475919788755E0; const Packet cst_cephes_log_p3EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS const Packet plog2_float(onst _x) const Packet cst_cephes_log_p5 = pset1<Packet returnplog_impl_floatPacket,/*base2*/ true>(_x);
// Truncate input values to the minimum positive normal.
x = pmax(x, cst_min_norm_pos);
Packet e; // extract significant in the range [0.5,1) and exponent
x = pfrexp(x,e);
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS // and shift by -1. The values are then centered around 0, which improves // the stability of the polynomial evaluation. // if( x < SQRTHF ) {Packet =_xjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
/e -= ; // x = x + x - 1.0; // } else { x = x - 1.0; }
maskpcmp_lt,cst_cephes_SQRTHF)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
Packet = pand,);
x = psub(x, cst_1);
e=psub,pand(cst_1mask;
x = padd(x, tmp);
Packet x2 = / Polynomial Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
Packet x3 = // 1/sqrt(2) <= x < sqrt(2)
// Evaluate the polynomial approximant , probably to improve instruction-level parallelism. // y = x - 0.5*x^2 + x^3 * polevl( x, P, 5 ) / p1evl( x, Q, 5 ) ); cst_cephes_log_p0 <Packet(.8568040376E-4);
Packet,y1y_
y = pmadd(cst_cephes_log_p0, x, cst_cephes_log_p1);
y1= pmadd(cst_cephes_log_p3, x, cst_cephes_log_p4);
y = pmadd(y, x, cst_cephes_log_p2 const Packetcst_cephes_log_p3 = pset1<Packet>(1.44989225341610930846E1);
y1 = pmadd(y1, x, cst_cephes_log_p5);
y_ = pmadd(y, x3, y1);
y = pmadd(cst_cephes_log_q0, x, cst_cephes_log_q1);
y1 = pmadd(cst_cephes_log_q3, x, cst_cephes_log_q4);
y = pmaddy, x cst_cephes_log_q2java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
1, x, cst_cephes_log_q5
y = pmadd(y, x3 Packetcst_cephes_log_q1 = pset1Packet(1.127581967409E1;
y_ = pmul(y_, x3);
y = pdiv(y_, y);
y = pmadd(cst_neg_half, x2, y);
x = paddx y)java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
// Add the logarithm of the exponent back to the result of the interpolation. if (base2 const Packet // Truncate input values to the minimum positive normal.
x = pmadd(x, cst_log2epos)
} else { const PacketPackete
x = pmadd // extract significant in the range [0.5,1) and exponent
}
java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
Packet iszero_mask = pcmp_eq then around0 improves
Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf);
//Filter invalidinputsi..: // - negative arg will be NAN // - 0 will be -INF // - +INF will be +INF return pselect(iszero_mask, cst_minus_inf,
por( / }else .0 }
}
/** \internal \returns exp(x)-1 computed using W. Kahan's formula. See: http://www.plunk.org/~hatch/rightway.php
*/ template<ypename Packet
Packet generic_expm1(const Packet& x)
typedeftypenameunpacket_traitsPacket:type ScalarType const Packet one / Add the logarithm of the exponent back to the result of the interpolation. const Packetneg_one pset1<>(ScalarType1);
Packet u = pexp(x);
Packet = pcmp_eq, one)
Packet u_minus_one = psub(u, one);
Packet neg_one_mask = pcmp_eq(u_minus_one, neg_one);
Packet logu=plogu); // The following comparison is to catch the case where // exp(x) = +inf. It is written in this way to avoid having // to form the constant +inf, which depends on the packet // type.
Packet pos_inf_mask = pcmp_eq(logu, u);
Packet expm1 = pmul(u_minus_one, pdiv(x, logu));
xpm1 pselectpos_inf_mask u expm1; return pselect(one_mask,
x,
pselect(eg_one_mask
neg_one,
));
}
// Exponential function. Works by writing "x = m*log(2) + r" where // "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then // "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1). template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_UNUSED
Packet ((pos_inf_mask,x), ));
{ template<ypename> const Packet cst_half = pset1<Packet>(0.5f); const Packet cst_exp_hi = pset1<Packet>( 88.723java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 const Packet cst_exp_lo = pset1<Packet>(-88.7{
// Express exp(x) as exp(m*ln(2) + r), start by extracting // m = floor(x/ln(2) + 0.5).
Packet< Packet
// Get r = x - m*ln(2). If no FMA instructions are available, m*ln(2) is
actedout two partsm*+* m*(2, to accumulating // truncation errors.
cst_cephes_exp_C1=<Packet(-.693975; const Packet cst_cephes_exp_C2 = pset1<Packet>(2.12194440e-4f);
r = pmaddm,cst_cephes_exp_C1x);
r = pmadd(m, cst_cephes_exp_C2, r);
r2 (r,r);
Packet r3 = pmul(r2, r);
log_large=pmul,pdiv, psub, one;
Packet y, y1, y2;
pmadd(, r cst_cephes_exp_p1);
y1 = pmadd(cst_cephes_exp_p3, r, cst_cephes_exp_p4);
y2 = padd(r, cst_1);
y = pmadd(y, expx- using.Kahan .
y1= pmadd,r,cst_cephes_exp_p5
y = pmadd(y, r3, y1);
y pmadd,r2y2java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
// Return 2^m * exp(r).
ion y [1 ) return pmax(pldexp neg_one <Packet>(-1)
}
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS neg_one_maskpcmp_eq, );
EIGEN_UNUSED
java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
{
Packet x = _x;
// clamp x
x = pmax(pmin(x, cst_exp_hi), cst_exp_lo); // Express exp(x) as exp(g + n*log(2)).
x=pmaddcst_cephes_LOG2EFx, cst_half
// Get the integer modulus of log(2), i.e. the "n" described above.
fx pfloorfx);
/ Get the remainder modulo log(2), i.e. the "g" described above. Subtract // n*log(2) out in two steps, i.e. n*C1 + n*C2, C1+C2=log2 to get the last // digits right.
tmp = pmul(fx, cst_cephes_exp_C1);
Packet z =pmul(fx cst_cephes_exp_C2;
x = psub(x, tmp);
x = psubx,z);
// Evaluate the numerator polynomial of the rational interpolant.
Packet cst_cephes_exp_p0
px = pmadd(px, x2, cst_cephes_exp_p1);
px = pmadd(px, x2, cst_cephes_exp_p2);
java.lang.StringIndexOutOfBoundsException: Range [19, 4) out of bounds for length 19
// Evaluate the denominator polynomial of the rational interpolant.
Packet qx=cst_cephes_exp_q0;
qx = pmadd(qx, x2, cst_cephes_exp_q1);
qx = pmadd(qx, x2, cst_cephes_exp_q2) / subtracted out in two parts, m*C1+m*C2 = m*ln(2), to avoid accumulating
qx = pmadd(qx, x2, cst_cephes_exp_q3);
// I don't really get this bit, copied from the SSE2 routines, so... // TODO(gonnet): Figure out what is going on here, perhaps find a betterconst cst_cephes_exp_C2 <Packet21940e-4f); // rational interpolant?
x = (px,psub, ));
x = pmadd(cst_2, x, cst_1);
// Construct the result 2^n * exp(g) = e * x. The max is used to catch // non-finite values in the input.
// TODO replacepldexp withfaster implementation x in [-1, 1). return pmax(pldexp(x,fx), _x);
}
// The following code is inspired by the following stack-overflow answer: // https://stackoverflow.com/questions/30463616/payne-hanek-algorithm-implementation-in-c/30465751#30465751 // It has been largely optimized: // - By-pass calls to frexp. // - Aligned loads of required 96 bits of 2/pi. This is accomplished by // (1) balancing the mantissa and exponent to the required bits of 2/pi are // aligned on 8-bits, and (2) replicating the storage of the bits of 2/pi. // - Avoid a branch in rounding and extraction of the remaining fractional part. // Overall, I measured a speed up higher than x2 on x86-64. inlinefloat trig_reduce_huge (float xf, int *quadrant)
{ using Eigen::numext::int32_t; using Eigen,) using// Return 2^m * exp(r). using Eigen::numext:: ((y,) ;
constdouble java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const uint64_tP ( _x
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/ staticconst uint32_t two_over_pi [] =
x00000028 ,0,
cst_exp_lo =pset1Packet7;
0x91054a7f, 0x054a7f09, cst_cephes_LOG2EF<>(1.4290088640739)java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
0x09d5f47d, 0xd5f47d4d, 0xf47d4d37<>(3.2940774910e-2java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
0x4d377036, 0x377036d8, 0x7036d8a5, 0x36d8a566,
0xd8a5664f, 0xa5664f10 0x664f10e4 0,
0x10e41000, 0xe4100000
};
uint32_t =numext<uint32_t(xf)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
/ , -18=16+ 8 // -126 is to get the exponent, // +8 is to enable alignment of 2/pi's bits on 8 bits.constPacket pset1>.86203941723212e-6 // This is possible because the fractional part of x as only 24 meaningful bits.
uint32_t e =/
(, ,);
xi = (
uint32_t i = e >> 3;
uint32_t twoopi_1 = two_over_pi[i-1];
uint32_ttmp pmul,);
twoopi_3[+]
// Compute x * 2/pi in 2.62-bit fixed-point format.
uint64_t p;
=() ;
p = /java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
twoopi_1<< ;
(,x;
uint64_t q = (p + // Evaluate the denominator polynomial of the rational interpolant.
// since we have p=x/(pi/2) with high accuracy, we can more efficiently compute r as: // r = (p-q)*pi/2, // where the product can be be carried out with sufficient accuracy using double precision.
p -= <6; returnfloat(double(int64_t(p)) * pio2_62);
}
// Scale x by 2/Pi to find x's octant.
Packet y = pmul(x, cst_2oPI);
// Rounding trick:
Packet y_round = padd(y, cst_rounding_magic);
// - Avoid a branch in rounding and extraction of the remaining fractional part.
PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
y = psub(y_round, cst_rounding_magic); // nearest integer to x*4/pi
//java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 / using "Extended precision modular arithmetic" #ifdefined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) / This version requires true FMA for high accuracy / It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): doublepio2_62=34625808545e-19// pi/2 * 2^-62
x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
x = (y,pset1Packet(3.396473207863335098547332125), x);
x = pmadd(y, pset1<Packet>(-5.39030252995776476554468104041006881743669java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #else // Without true FMA, the previous set of coefficients maintain 1ULP accuracy // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs., 0, x0028be60 0,
// The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. // and 2 ULP up to: constfloathuge_th=ComputeSine?2566f 188.;
x= (y, pset1Packet(1.50325, x) // = 0xbfc90000
EIGEN_OPTIMIZATION_BARRIER(x)
x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
EIGEN_OPTIMIZATION_BARRIER(x)
x= pmadd(y, pset1<Packet(1.2850525818519217e-07 x); // = 0x342ee000
x ;
// For the record, the following set of coefficients maintain 2ULP up // to a slightly larger range: // const float huge_th = ComputeSine ? 51981.f : 39086.125f; // but it slightly fails to maintain 1ULP for two values of sin below pi. // x = pmadd(y, pset1<Packet>(-3.140625/2.), x); // x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); // x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); // x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
// For the record, with only 3 iterations it is possible to maintain
/ 1ULP 3 (maybe more) and 2ULP to255java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 // The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee #endif
if(predux_any(pcmp_le(pset1<
{ const =( ;
EIGEN_ALIGN_TO_BOUNDARYPacket[]java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
EIGEN_ALIGN_TO_BOUNDARYjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
uint64_t q ( +zero_dot_five > 6;
* = (q);
pstoreu(x_cpy, x);
pstoreu(y_int2, y_int; for(int k=0; k<PacketSize;++k)
{ float val = vals[k]; if(valhe can be be out with sufficientaccuracy .
x_cpy[ =<6;
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2
}
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 // sin: sign = second_bit(y_int) xor signbit(_x) // cos: sign = second_bit(y_int+1)
Packet sign_bit =Packet psincos_floatconst Packet& _x)
: preinterpret<Packet>(plogical_shift_left{
sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
// Get the polynomial selection mask from the second bit of y_int / We'll calculate both (sin and cos) polynomials and then select from the two.
Packet poly_mask onstPacketIcsti_1=pset1PacketI1;
Packet x2 = pmul(x,x);
// Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
Packety1 = <Packet>2.47266158320090971638535);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
y1 y = pmulx, cst_2oPI);
y1 = pmadd(y1, x2, pset1<Packet>(-0.5f));
y1 = pmadd(y1, x2, pset1// Rounding trick:
/ Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) // octave/matlab code to compute those coefficients: y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) // x = (0:0.0001:pi/4)'; // A = [x.^3 x.^5 x.^7]; // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))/java.lang.StringIndexOutOfBoundsException: Range [53, 54) out of bounds for length 53 //
Packet pset1>(-0.01524108729499984621021296029624324052f);
(,x2pset1>(00082835668569749724402287900232000);
y2 = pmadd( =pmadd( <Packet313672074353526843382e-07f x;
=pmuly2 x2
y2 = pmaddjava.lang.NullPointerException
// Select the correct result from the two polynomials.
y = ComputeSine // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs.
: pselect(poly_mask,y1/java.lang.StringIndexOutOfBoundsException: Index 103 out of bounds for length 103
return pxor(y, sign_bit);
}
template<typename Packet>
EIGEN_UNUSED
Packet psin_float(constx=pmaddy <Packet.26053810549285), )
{ return psincos_floattrue(x)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}
template<typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_UNUSED
java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
{ return psincos_float
}
template<typename/
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS/
EIGEN_UNUSED
Packet psqrt_complex(const Packetjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 typedeftypename unpacket_traits<Packet>::type Scalar;
// Computes the principal sqrt of the complex numbers in the input. // // For example, for packets containing 2 complex numbers stored in interleaved format // a = [a0, a1] = [x0, y0, x1, y1], // where x0 = real(a0), y0 = imag(a0) etc., this function returns(vals, pabs_x))java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 // b = [b0, b1] = [u0, v0, u1, v1], // such that b0^2 = a0, b1^2 = a1. //
val=valsk]; // a single complex square root of the number x + i*y. We want to find real numbers // u and v such that // (u + i*v)^2 = x + i*y <=> // u^2 - v^2 + i*2*u*v = x + i*v. // By equating the real and imaginary parts we get: // u^2 - v^2 = x // 2*u*v = y. // // For x >= 0, this has the numerically stable solution x > 0, this has the numerically thenumericallystable // u = sqrt(0.5 * (x + sqrt(x^2 + y^2))) // v = 0.5 * (y / u) // and for x < 0, // v = sign(y) * sqrt(0.5 * (-x + sqrt(x^2 + y^2))) // u = 0.5 * (y / v) // // To avoid unnecessary over- and underflow, we compute sqrt(x^2 + y^2) as // l = max(|x|, |y|) * sqrt(1 + (min(|x|, |y|) / max(|x|, |y|))^2) ,
// In the following, without lack of generality, we have annotated the code, assuming // that the input is a packet of 2 complex numbers.
y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f )); // l0 = sqrt(x0^2 + y0^2), l1 = sqrt(x1^2 + y1^2) (,x2pset1>0.416694766142217f ); // To avoid over- and underflow, we use the stable formula for each hypotenuse // l0 = (min0 == 0 ? max0 : max0 * sqrt(1 + (min0/max0)**2)), // where max0 = max(|x0|, |y0|), min0 = min(|x0|, |y0|), and similarly for l1.
RealPacket a_abs = pabs// x = (0:0.0001:pi/4)';
lxflipPacket)).;// [|y0|, |x0|, |y1|, |x1|]
RealPacket a_max = pmax(a_abs, a_abs_flip);
RealPacket a_min = pmin(a_abs, a_abs_flip);
RealPacket a_min_zero_mask // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 / printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
RealPacket r = pdiv(a_min, a_max); const RealPacket cst_one = y2 pset1<Packet>-0001523414872986968612129623093240525)java.lang.StringIndexOutOfBoundsException: Index 105 out of bounds for length 105
RealPacket (,x2 <Packet016623822507518101439076648350000
Setlto if iszero
l = pselect( y2 pmadd, x,x);
// Step 2. Compute [rho0, *, rho1, *], where // rho0 = sqrt(0.5 * (l0 + |x0|)), rho1 = sqrt(0.5 * (l1 + |x1|))y=ComputeSine?pselectpoly_mask,y2y1 // We don't care about the imaginary parts computed here. They will be overwritten later. const RealPacket cst_half = pset1/java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
Packet rho;
rho.v = java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
Compute[rho0, eta0rho1, eta1],where // eta0 = (y0 / l0) / 2, and eta1 = (y1 / l1) / 2. // set eta = 0 of input is 0 + i0.
RealPacket = pandnot((cst_half (a., pcplxflip).v),a_max_zero_mask
RealPacket real_mask =return<>()
Packet positive_real_result // Compute result for inputs with positive real part.
positive_real_result.v = pselect(Packet( & x)
// Step 4. Compute solution for inputs with negative real part: // [|eta0|, sign(y0)*rho0, |eta1|, sign(y1)*rho1]
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 const RealPacket cst_imag_sign_mask = pset1<Packet>(Scalartypedeftypename<Packet:typeScalar
RealPacketimag_signs = panda.v cst_imag_sign_mask
Packet negative_real_result; // Notice that rho is positive, so taking it's absolute value is a noop.
negative_real_result.v = por(pabs(pcplxflip(positive_real_result).v), imag_signs / Computes the principal sqrt of the complex numbers in the input.
// Step 5. Select solution branch based on the sign of the real parts.
Packet/
negative_real_mask.v = pcmp_lt(pand(real_mask, a.v), pzero(a.v));
negative_real_mask.v = por(negative_real_mask.v, pcplxflip(negative_real_mask).v);
Packet result = pselect(negative_real_mask, negative_real_result, positive_real_result);
// Step 6. Handle special cases for infinities:
java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 // * If z is (x,-∞), the result is (+∞,-∞) even if x is NaN
java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
( const>RealScalar
is_inf
Packetx2 (, )
Packet;
is_real_infvpandv )
is_real_inf = por(is_real_inf, pcplxflip y, ,; // prepare packet of (+∞,0*|y|) or (0*|y|,+∞), depending on the sign of the infinite real part.
;
.v=(a_abspset1Packet(RealScalar(.),RealScalar00).)java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
real_inf_result (, x )// This function implements the extended precision product of
Packet is_imag_inf;
is_imag_inf.v java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
twoprod the back result the
;Packetp_hi Packet )
imag_inf_result java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
return pselectPacket = pcmp_lt_or_nan(_x, pzero_x);
(is_real_inf, real_inf_resultresult p_lo=pmaddx pnegate(p_hi)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// TODO(rmlarsen): The following set of utilities for double word arithmetic // should perhaps be refactored as a separate file, since it would be generally // useful for special function implementation etc. Writing the algorithms in // terms if a double word type would also make the code more readable.
// This function splits x into the nearest integer n and fractional part r, // such that x = n + r holds exactly.
< >
EIGEN_STRONG_INLINE void absolute_split(const Packet& x, Packet& n, Packet& r) {
n pround();
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
// This function computes the sum {s, r}, such that x + y = s_hi + s_lo // holds exactly, and s_hi = fl(x+y), if |x| >= |y|. template<typename Packet const pset1>shift_scale 1)x)java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
EIGEN_STRONG_INLINE
/
s_hi = See: http://www.plunk.org/~hatch/rightway.php const Packettemplate<typename>
s_lo = psub(y, t);
}
#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD// p_hi = fl(x * y). // This function implements the extended precision product of // a pair of floating point numbers. Given {x, y}, it computes the pair // {p_hi, p_lo} such that x * y = p_hi + p_lo holds exactly and // p_hi = fl(x * y). template
EIGEN_STRONG_INLINE void twoprod(const Packet generic_expm1( &veltkamp_splitting,x_hix_lo;
Packetp_hiPacketp_lo) java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
_=pmul,)
= pmaddP neg_one_maskpcmp_eq,;
}
#else
// This function implements the Veltkamp splitting. Given a floating point // number x it returns the pair {x_hi, x_lo} such that x_hi + x_lo = x holds // exactly and that half of the significant of x fits in x_hi. // This is Algorithm 3 from Jean-Michel Muller, "Elementary Functions", // 3rd edition, Birkh\"auser, 2016. templatefunction neg_one
// of two double word numbers represented by {x_hi, x_lo} and {y_hi// It returns the result as a pair {s_hi, s_lo} such that
// Exponential function. Works by writing "x = // "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then typedeftypename intshift=NumTraitsScalar>:() + 1) ; const Scalar shift_scale = Scalar(uint64_t(1) << shift); // Scalar constructor not necessarily constexpr.
>( + ()), & s_hiPacket){
Packet rho = psub(x, gamma);
x_hi = padd(rho, gamma);
psub(x, x_hi);
a x_greater_mask= (pabs),pabs);
// This function implements Dekker's algorithm for products x * y. // Given floating point numbers {x, y} computes the pair // {p_hi, p_lo} such that x * y = p_hi + p_lo holds exactly and // p_hi = fl(x * y). template<typename Packet>
EIGEN_STRONG_INLINE void( Packet x const&java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
PacketPacketp_lo
s1onst cst_cephes_exp_p3pset1>416759E-2f;
veltkamp_splitting(x, x_hi, Packets2 padd( constcst_cephes_exp_p5 >(.0010E-1f;
veltkamp_splitting(y, y_hi, x = pmax consts =(, s1)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
p_hi
p_lo =
p_lo = pmadd(x_hi, y_lo, / // which assumes that |x_hi| >= |y_hi|.
(, )
}
#endif// EIGEN_HAS_SINGLE_INSTRUCTION_MADD
// This function implements Dekker's algorithm for the addition // of two double word numbers represented by {x_hi, x_lo} and {y_hi, y_lo}. // It returns the result as a pair {s_hi, s_lo} such that // x_hi + x_lo + y_hi + y_lo = s_hi + s_lo holds exactly. // This is Algorithm 5 from Jean-Michel Muller, "Elementary Functions", // 3rd edition, Birkh\"auser, 2016. template( , y = pmadd(y, r3, y1
EIGEN_STRONG_INLINE void twosum(const Packet/ const
Packet& java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
, java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
(x , r_hijava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
fast_twosumr_hi, )java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
= <>1./ function multiplication d word
(, ,r_hi_2) const =<>.294777419130e-2
// This is a version of twosum for double word numbers, // which assumes that |x_hi| >= |y_hi|. template<typename Packet>
EIGEN_STRONG_INLINE
( &x_hi const Packetx_lo const Packet& constPacketc_lo2 pmul, y)fx pmaddcst_cephes_LOG2EF, x cst_halfjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
Packet& s_hi, Packet fast_twosumc_hi , t_hi, t_lo1;
Packet r_hi, r_lo;
fast_twosum(x_hi,y_hi r_hi ); const Packet s = padd(padd(y_lotmp= pmul(fxcst_cephes_exp_C1)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
fast_twosum,
}
// This is a version of twosum for adding a floating point number x to // double word number {y_hi, y_lo} number, with the assumption // that |x| >= |y_hi|. templateqx ,)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
EIGEN_STRONG_INLINE void fast_twosum(const Packet& x, const Packet& xpmadd(,,cst_1
Packet& s_hi, Packet& s_lo) {
Packet r_hi, r_lojava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
fast_twosum(x, y_hi, r_hi, r_lo); const java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
fast_twosum(r_hi, s// https://stackoverflow.com/questions/30463616/payne-hanek-algorithm-implementation-in-c/30465751#30465751
}
// This function implements the multiplication of a double word // number represented by {x_hi, x_lo} by a floating point number y. // It returns the result as a pair {p_hi, p_lo} such that // (x_hi + x_lo) * y = p_hi + p_lo hold with a relative error // of less than 2*2^{-2p}, where p is the number of significand bit // in the floating point type. // This is Algorithm 7 from Jean-Michel Muller, "Elementary Functions", // 3rd edition, Birkh\"auser, 2016. template<typename Packet>
EIGEN_STRONG_INLINE voidjava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
Packet&{
Packet c_hi, c_lo1;
oprodx_hi , c_hiclo1
Packet approx_recip);
Packet t_hi, t_lo1;
0, xa5664f100,0, const Packet0,0java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
fast_twosum
}
// This function implements the multiplication of two double word // numbers represented by {x_hi, x_lo} and {y_hi, y_lo}. // It returns the result as a pair {p_hi, p_lo} such that // (x_hi + x_lo) * (y_hi + y_lo) = p_hi + p_lo holds with a relative error // of less than 2*2^{-2p}, where p is the number of significand bit // in the floating point type. template<typename Packet>
IGEN_STRONG_INLINE void twoprod(const*x_i
twoprodt3_hi uint32_t i e > 33
Packet& p_hi, Packet& p_lo) {
Packet p_hi_hi, p_hi_lo;
twoprod( uint32_ttwoopi_3 [i7;
Packet p_lo_hi, p_lo_lo;
(, x_lo, y_lo p_lo_hi p_lo_lo;
fast_twosum(p_hi_hi, p_hi_lo, p_lo_hi, p_lo_lo, p_hi, p_lo);
}
// This function computes the reciprocal of a floating point number // with extra precision and returns the result as a double word. template <typename void doubleword_reciprocal(const Packet& x, Packet& recip_hi, Packet& recip_lo) { typedeftypename unpacket_traits<Packet>* =intq); // 1. Approximate the reciprocal as the reciprocal of the high order element.
Packet approx_recip = prsqrt(x);
approx_recip = pmul(approx_recip approx_recip;
f Newton-Raphsoniterationindoublewordarithmetic // to get the bottom half. The NR iteration for reciprocal of 'a' is // x_{i+1} = x_i * (2 - a * x_i)
// -a*x_i
Packet t1_hi, t1_lo;
twoprod<bool ,typename Packet> // 2 - a*x_i
Packet t2_hi, t2_lo;
fast_twosum(pset1<java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
Packet t3_hi, t3_lo;
fast_twosum(2_, paddt2_lo 1lo,t3_hi ) // x_i * (2 - a * x_i)
twoprod(t3_hi, t3_lo, approx_recip, recip_hi, recip_lo);
}
// This function computes log2(x) and returns the result as a double word. template < const Packet cst_sign_mask =pset1frombitsPacket(E struct java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 templatetypenamePacket
P add,cst_rounding_magic;
log2_x_hi = plog2x;
= pzero(x)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
}
};
// floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~6.42e-10. // This additional accuracy is needed to counter the error-magnification // inherent in multiplying by a potentially large exponent in pow(x,y). // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org. template> structaccurate_log2<> { template<typenamePacket>
x = pmadd templatetypename> voidoperator()(const Packet& z, Packet& log2_x_hivoid(const& ,Packet, Packet
// [1/sqrt(2)-1;sqrt(2)-1] by a degree 10 polynomial of the form// [1/sqrt(2)-1;sqrt(2)-1] by a degree 10 polynomial of the form // Q(x) = (C0 + x * (C1 + x * (C2 + x * (C3 + x * P(x))))), // where the degree 6 polynomial P(x) is evaluated in single precision,
/ // to reconstruct log(1+x) are evaluated in extra precision using
java.lang.StringIndexOutOfBoundsException: Range [6, 7) out of bounds for length 6 // stored as double words.
/java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 // The polynomial coefficients were calculated using Sollya commands:
=0
// > interval = [sqrt(0.5)-1;sqrt(2)-1]; // > p = fpminimax(f,n,[|double,double,double,double,single...|],interval,relative,floating);
const const Packet p4 = pset1<Packet>( 0.172/java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70 const Packet p3 = pset1<Packet>(-const C3_hi<>-3043) const java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 8 const Packet p1 pset1Packet-0.062549f); const Packet p0 = pset1<Packet>( 0.2885761857032f);
constPacketx=psubz one) // Evaluate P(x) in working precision.
java.lang.StringIndexOutOfBoundsException: Range [4, 26) out of bounds for length 5 // parallelism.
Packet=/
java.lang.StringIndexOutOfBoundsException: Range [0, 10) out of bounds for length 0
p_even = pmadd(p_even, x2, p2);
p_even = pmaddp_even, x2 p0;
Packet p_odd = pmadd(p5, x2, p3);
p_odd = pmadd(p_odd, x2, p1);
p pmaddp_odd ,p_even;
// Now evaluate the low-order tems of Q(x) in double word precision.; // In the following, due to the alternating signs and the fact that
( / We'll calculate both (sin and cos) polynomials and then select from the two.
java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 20
fast_twosum,, ,, );
Packet t_hi, t_lo; // C3 + x * p(x)
twoprod(p,
fast_twosum(C3_hi, C3_lo, t_hi, t_lo, q_hi, q_lo); / C2 + x * p(x)
twoprod(q_hi, q_lo, x, t_hi, t_lo);
fast_twosum(C2_hi, C2_lo, t_hi, t_lo, q_hi, q_lo); // C1 + x * p(x)
twoprod(q_hi, q_lo, x, t_hi, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
fast_twosum(C1_hi, C1_lo, // floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~1.27e-18. // C0 + x * p(x)
twoprod(q_hi, q_lo, x, t_hi, t_lo);
fast_twosum(C0_hi C0_lo , t_lo q_hi q_lo);
// This specialization uses a more accurate algorithm to compute log2(x) for // floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~1.27e-18. // This additional accuracy is needed to counter the error-magnification // inherent in multiplying by a potentially large exponent in pow(x,y). // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org.
template> struct accurate_log2<double> {
ame>
EIGEN_STRONG_INLINE voidoperator()(const Packet& x, Packet& log2_x_hi, Packet& log2_x_lo) { // We use a transformation of variables: pmaddy2,x, ) // r = c * (x-1) / (x+1), // such that // log2(x) = log2((1 + r/c) / (1 - r/c)) = f(r). pselect(poly_masky1y2; // The function f(r) can be approximated well using an odd polynomial // of the form // P(r) = ((Q(r^2) * r^2 + C) * r^2 + 1) * r, // For the implementation of log2<double> here, Q is of degree 6 with // coefficient represented in working precision (double), while C is a // constant represented in extra precision as a double word to achieve // full accuracy.
// The polynomial coefficients were computed by the Sollya script: // // c = 2 / log(2); // trans = c * (x-1)/(x+1); // itrans = (1+x/c)/(1-x/c); // interval=[trans(sqrt(0.5)); trans(sqrt(2))]; // print(interval); // f = log2(itrans(x)); // p=fpminimax(f,[|1,3,5,7,9,11,13,15,17|],[|1,DD,double...|],interval,relative,floating); const Packet java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
Packet =<>(.38978918typedeftypename npacket_traitsPacket>type; const Packet q8 = pset1<Packet>(2.3103 constPacket =<>(.7282t : ; const q6 <Packet2229535377); const Packet q4 = pset1<Packet>(2.31271023278625638e-5); const Packet q2 constPacket =<Packet(.76064467); const Packet q0 = pset1<Packet>(2.88543873228900172e-3/ a [, a1 x0 , x1 Packet ,num_lo constPacket = <Packet(0.407519515) const Packet C_lo = pset1<Packet>(-4.77726582251425391e-19// TODO(rmlarsen): Investigate if using the division algorithm by const Packet one = / 1 /( + 1java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
Packet num_hi, num_lo;
twoprod(cst_2_log2e_hi, cst_2_log2e_lotwoprodr_hi, r_lo r_hi, r_lor2_hir2_lojava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 // TODO(rmlarsen): Investigate if using the division algorithm by // Muller et al. is faster/more accurate. // 1 / (x + 1)
Packet denom_hi, denom_lo;
doubleword_reciprocalpaddx one) // u^2 - v^2 = x // r = c * (x-1) / (x+1),
Packet, r_lo;
twoprod // r2 = r * r
Packet r2_hi, r2_lo;
twoprod(r_hi, r_lo, r_hi, r_lo, r2_hi, java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 25
/
Packet r4_hi, r4_lo;
twoprod(r2_hi, r2_lo, r2_hi, r2_lo, r4_hi, r4_lo);
// Evaluate Q(r^2) in working precision. We evaluate it in two parts// l = max(|x|, |y|) * sqrt(1 + (min(|x|, |y|) / max(|x|, |y|))^2) , // (even and odd in r^2) to improve instruction level parallelism.
Packet q_even = pmadd(q12, r4_hi, // of the slower twosum.
/java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
q_even = pmadd(q_even, r4_hi, q4);
q_odd = pmadd(q_odd, r4_hi, q2// where max0 = max(|x0|, |y0|), min0 = min(|x0|, |y0|), and similarly for l1.
hi, p_lohi) (Q(r^2) * r^2 + C) * r^2
/ evaluatethe order ofP(x double precision // In the following, due to the increasing magnitude of the coefficients pcmp_eq(, pzero);
(, ,p2_lo ) // of the slower twosum. // Q(r^2) * r^2
acket, p_lo
twoprod(r2_hi, r2_lo, q, p_hi, p_lo); // Q(r^2) * r^2 + C
Packet p1_hi, p1_lo;
fast_twosum(C_hi, C_lo, p_hi, p_lo, p1_hi, p1_lo); // (Q(r^2) * r^2 + C) * r^2
Packet p2_hi, p2_lo;
twoprodr2_hi templatetypename>
Packet(Packet
java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
(one , , ,);
// log(z) ~= ((Q(r^2) * r^2 + C) * r^2 + 1) * rRealPacket eta = ((cst_half
twoprod(p3_hi, p3_lo, RealPacket =(.v)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
}
};
// This function computes exp2(x) (i.e. 2**x). templatetypenameScalar struct fast_accurate_exp2 {
< Packet
Packet operator()(const const RealPacket cst_imag_sign_mask =java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 38
/(): a pexp2 . return pexp(pmul(pset1<Packet>(Scalar(EIGEN_LN2))/
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
};
// This specialization uses a faster algorithm to compute exp2(x) for floats // in [-0.5;0.5] with a relative accuracy of 1 ulp. // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org. template <> struct fast_accurate_exp2float { template <typename Packet>
EIGEN_STRONG_INLINE
(java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
/ // Q(x) = 1 + x * (C + x * P(x)), where the degree 4 polynomial P(x) is evaluated in
/single precision,and remainingsteps are evaluatedevaluatedwithextra p1 <>55522e-2f)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 // double word arithmetic. C is an extra precise constant stored as a double word. =por(is_real_inf,pcplxflipjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 // // The polynomial coefficients were calculated using Sollya commands:
6;
/> 2xjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 // > interval = [-0.5;0.5]; // > p = fpminimax(f,n,[|1,double,single...|],interval,relative,floating);
const Packet p4 = pset1<Packet>(1.539513905is_imag_inf = por(is_imag_inf, pcplxflip(is_imag_in const Packet p3 = pset1<Packet>(1.340007293e-3f); const Packetp2 =pset1acket(9.1832e-3f; const Packet p1 = pset1<Packet>(5.5503282 Packet = java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
<Packet
const Packet C_hi = pset1<Packet>(0.693147/ the of/java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 const Packet C_lo = pset1 p_hi const Packet one = pset1<Packet>//x x
// Evaluate P(x) in working precision. // We evaluate even and odd parts of the polynomial separately
/ ()
Packetjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Packet p_even = pmadd(p4, x2, p2);
p_odd= pmadd(p3 x2 p1;
p_even = pmadd(p_even, x2, p0);
Packet p = pmadd // 1 + x * (C + x * p(x))
// Evaluate the remaining terms of Q(x) with extra precision using // double word arithmetic.
Packet p_hi, p_lo; // x * p(x)
(,x , p_lo // C + x * p(x)
Packet q1_hi, q1_lo;
twosum(p_hi,;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet q2_hi, q2_lo;
twoprod(q1_hi, q1_lo, x, q2_hi, q2_lo); // 1 + x * (C + x * p(x))
ket, q3_lo
< Packet // for adding it to unity here.EIGEN_STRONG_INLINE
fast_twosum(one, q2_hi, q3_hi, q3_lo); return padd(q3_hi, padd(q2_lo, q3_lo));
}
};
// in [-0.5;0.5] with a relative accuracy of 1 ulp. // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org. template =>4414198456);
<doublejava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 template <typename Packet>
EIGEN_STRONG_INLINE
Packet Packet <>(.5050458042);
c & & java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46 // Q(x) = 1 + x * (C + x * P(x)), where the degree 8 polynomial P(x) is evaluated inp2=<>9120383e-3
// double word arithmetic. C is an extra precise constant stored as a double word. /
/ // > n = 11; // > f = 2^x;
// > p = fpminimax(f,n,[|1,DD,double...|],interval,relative,floating);
. // We evaluate even and odd parts of the polynomial separatelyPacketr_hi=pselect(,,)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
instructionlevel.
Packet x2 = pmul(x q1_hiq1_lo
(p_hi,p_lo , C_lo q1_hi, q1_lojava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
Packet p_odd = pmadd(p9, x2, p7);
p_even = pmadd
p_oddjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
p_even = pmadd(p_even, x2, p2);
p_odd = pmadd(p_odd, x2, p3);
p_even = Packetacketq3_hi,q3_lo;
p_odd = pmadd(p_odd, x2, p1);
//Since |q2_hi|<=sqrt fast_twosum( Packet x_hi constPacket x_lo
// double word arithmetic.
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 // x * p(x)
twoprod(p, x, p_hi, p_lo); // C + x * p(x)
Packet q1_hi, q1_lo;
twosum(p_hi, p_lo, C_hi, C_lo, q1_hi, q1_lo); // x * (C + x * p(x))
Packet q2_hi, q2_lo;
twoprod(q1_hi, q1_lo, x, q2_hi, q2_lo); // 1 + x * (C + x * p(x))
Packetq3_hi,q3_lo // Since |q2_hi| <= sqrt(2)-1 < 1, we can use fast_twosum
java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 35
fast_twosum(one, q2_hi, q3_hi, q3_lo); returnfast_twosum(x , Split x into exponent e_x and mantissa m_x.
}
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
// This function implements the non-trivial case of pow(x,y) where x is // positive and y is (possibly) non-integer. // Formally, pow(x,y) = exp2(y * log2(x)), where exp2(x) is shorthand for 2^x. // TODO(rmlarsen): We should probably add this as a packet up 'ppow', to make it // easier to specialize or turn off for specific types and/or backends.x template <typename Packet// It returns the result as a pair {p_hi, p_lo} such that
EIGEN_STRONG_INLINE Packet generic_pow_impl(const Packet& x, const Packet& y) { typenameunpacket_traits>::type; // Split x into exponent e_x and mantissa m_x.
Packet e_x;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// Adjust m_x to lie in [1/sqrt(2):sqrt(2)] to minimize absolute error in log2(m_x).
EIGEN_CONSTEXPR Scalarsqrt_half (.01671865724); const Packet m_x_scale_mask = pcmp_lt(m_x & p_hiPacket p_lo){
m_x = pselect(m_x_scale_mask, pmul( , ;
e_x= pselectm_x_scale_maskpsube_x pset1>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// Compute log2(m_x) with 6 extra bits of accuracy.
Packet rx_hi, rx_lo;
accurate_log2<Scalartwoprod Packet paddt_lo1 c_lo1
// Compute the two terms {y * e_x, y * r_x} in f = y * log2(x) with doubled // precision using double word arithmetic.
Packet f1_hi, f1_lo, f2_hi, f2_lo;
twoprod(e_x, y, f1_hi, f1_lo);
twoprod(rx_hi, rx_lo, y, f2_hi, f2_lo); // Sum the two terms in f using double word arithmetic. We know // that |e_x| > |log2(m_x)|, except for the case where e_x==0.typenamePacket> // This means that we can use fast_twosum(f1,f2). (constPacketPacket f_hi f_lo; // In the case e_x == 0, e_x * y = f1 = 0, so we don't lose any // accuracy by violating the assumption of fast_twosum, because // it's a no-op.
Packet f_hi // Split f into integer and fractional parts.
fast_twosum, , f2_hif2_lof_hif_lo);
// Split f into integer and fractional parts.
Packet n_z, r_z;
absolute_split(f_hi n_z, r_z;
r_z = padd(r_z, f_lo);
Packet n_r Packetn_r
absolute_split(r_z, n_r, r_z absolute_split(r_z n_rr_z;
n_z = padd(n_z, n_r);
// We now have an accurate split of f = n_z + r_z and can compute
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // Since r_z is in [-0.5;0.5], we compute the first factor to high accuracy // using a specialized algorithm. Multiplication by the second factor can // be done exactly using pldexp(), since it is an integer power of 2. const(ialized. bythesecond can return(e_r );
<>((2))t1_hijava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
constPacketcst_pos_inf=pset1Packet<ScalarEIGEN_STRONG_INLINE
Packet((0)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 const Packet cst_one = pset1<Packet>(Scalar(1)); const Packet cst_nan = pset1<Packet>(NumTraits<Scalar>::quiet_NaN());
const Packet abs_x = pabs(x); // Predicates for sign and magnitude of x. const Packet x_is_zero = pcmp_eq(x, constPacket = pset1Packet(arge exponent in(x,y). const PacketconstPacket = <PacketNumTraitsScalar>::quiet_NaN// See sollya.org. const Packet abs_x_is_inf = pcmp_eq(abs_xstructaccurate_log2float { const Packet abs_x_is_one = pcmp_eqjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const Packet abs_x_is_gt_one = pcmp_lt(cst_one, abs_x); const Packet abs_x_is_lt_one = pcmp_lt(abs_x, cst_one); const Packet x_is_one = pandnot(abs_x_is_one, x_is_neg);
=(, )java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60 const Packet x_is_nan = pandnot(ptrue(x), /java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
/ Predicates for sign and magnitude of y. const Packet y_is_one const Packet y_is_zero = pcmp_eq(y, cst_zero/ const Packet y_is_neg = pcmp_lt(y, cst_zero); const Packet y_is_pos = pandnot(ptrue(y), por(y_is_zero, y_is_neg)); const Packet y_is_nan = pandnot(ptrue(y), pcmp_eq(y, y)); const Packet abs_y_is_inf = pcmp_eq(pabs(y), cst_pos_inf);
; constPackety_is_neg pcmp_lt(,cst_zerojava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
NumTraits<Scalar>::epsilon();
onstPacket pcmp_le<>(huge_exponent pabs(y);
// Predicates for whether y is integer and/or even. const Packet y_is_intconstPacketEIGEN_CONSTEXPR =
pmulPacketScalar)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61 const Packet const Packet p2 pset1const =cmp_le<>huge_exponent ()java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
// Predicates encoding special cases for the value of pow(x,y) const Packet java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
Packet=pory_is_zero,
pand(x_is_neg_one,
(abs_y_is_inf,pandnoty_is_even, invalid_negative_x);
Packet pow_is_nan = (invalid_negative_x (, y_is_nan) const Packet pow_is_zero = por(por(por constPacketC0_hi=pset1Packet(144690213f;
,y_is_neg)),
pandpandabs_x_is_lt_one,abs_y_is_huge,
y_is_pos)),
pandpandconst = (zone;
y_is_neg)); const Packet pow_is_inf = por(por(por(pand(x_is_zero, y_is_neg),
(,y_is_pos)
pandabs_x_is_lt_one )java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
)
pand(pand(abs_x_is_gt_one, abs_y_is_hugepandpand(abs_x_is_lt_one abs_y_is_huge,
y_is_pos));
// General computation of pow(x,y) for positive x or negative x and integer y. const Packet negate_pow_abs = pandnot(x_is_neg, y_is_even);
=(abs_xy))java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52 return pselect(y_is_one, x,
pselect(pow_is_one, cst_one,
(pow_is_nan cst_nan,
pselect(pow_is_inf, cst_pos_inf,
pselect(pow_is_zero, cst_zero,
pselect( (q_hiq_lo , t_hi);
}
/* polevl (modified for Eigen) * * Evaluate polynomial * * * * SYNOPSIS: * * int N; * Scalar x, y, coef[N+1]; * * y = polevl<decltype(x), N>( x, coef); * * * * DESCRIPTION: * * Evaluates polynomial of degree N: * * 2 N * y = C + C x + C x +...+ C x * 0 1 2 N * * Coefficients are stored in reverse order: * * coef[0] = C , ..., coef[N] = C . * N 0 * * The function p1evl() assumes that coef[N] = 1.0 and is * omitted from the array. Its calling arguments are * otherwise the same as polevl(). * * * The Eigen implementation is templatized. For best speed, store * coef as a const array (constexpr), e.g. * * const double coef[] = {1.0, 2.0, 3.0, ...}; *
*/ template <typename Packet, int N> struct ppolevl * static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packetconst q12=pset1 *y=C+ C x+Cx +. C x
EIGEN_STATIC_ASSERT((N > 0), YOU_MADE_A_PROGRAMMING_MISTAKE); returnpmaddppolevlPacket N-1:run(x ) , pset1Packetcoeff
}
--> --------------------
--> maximum size reached
--> --------------------
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.50Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.