Beispiel #1
0
 static inline A0 asin(const  A0& a0)
 {
   A0 sign, x, z;
   //    bf::tie(sign, x) = sign_and_abs(a0);
   x = nt2::abs(a0);
   sign = bitofsign(a0);
   if ((x < single_constant<A0,0x38d1b717>())) return a0;
   if ((x >  One<A0>())) return Nan<A0>();
   bool bx_larger_05    = (x > Half<A0>());
   if (bx_larger_05)
     {
       z = Half<A0>()*oneminus(x);
       x =  sqrt(z);
     }
   else
     {
       z = sqr(x);
     }
   A0 z1 = madd(z,  single_constant<A0,0x3d2cb352>(),
                single_constant<A0,0x3cc617e3>());
   z1 = madd(z1, z, single_constant<A0,0x3d3a3ec7>());
   z1 = madd(z1, z, single_constant<A0,0x3d9980f6>());
   z1 = madd(z1, z, single_constant<A0,0x3e2aaae4>());
   z1 = madd(z1, z*x, x);
   if(bx_larger_05)
     {
       z1 = z1+z1;
       z1 = Pio_2<A0>()-z1;
     }
   return b_xor(z1, sign);
 }
 static inline A0 finalize(const A0& a0, const A0& x,
                           const A0& c, const A0 & k,
                           const A0& ,const A0& )
 {
   A0 y = oneminus(((-(x*c)/(Two<A0>()-c))-x));
   return fast_ldexp(y, fast_toint(k));
 }
Beispiel #3
0
 result_type operator()(A0& yi, A1& inputs) const
 {
   yi.resize(inputs.extent());
   const child0 & x   =  boost::proto::child_c<0>(inputs);
   if (numel(x) <=  1)
     BOOST_ASSERT_MSG(numel(x) >  1, "Interpolation requires at least two sample points in each dimension.");
   else
   {
     BOOST_ASSERT_MSG(issorted(x, 'a'), "for 'linear' interpolation x values must be sorted in ascending order");
     const child1 & y   =  boost::proto::child_c<1>(inputs);
     BOOST_ASSERT_MSG(numel(x) == numel(y), "The grid vectors do not define a grid of points that match the given values.");
     const child2 & xi  =  boost::proto::child_c<2>(inputs);
     bool extrap = false;
     value_type extrapval = Nan<value_type>();
     choices(inputs, extrap, extrapval, N1());
     table<index_type>   index = bsearch (x, xi);
     table<value_type>  dx    =  xi-x(index);
     yi =  fma(oneminus(dx), y(index), dx*y(oneplus(index)));
     value_type  b =  value_type(x(begin_));
     value_type  e =  value_type(x(end_));
     if (!extrap) yi = nt2::if_else(nt2::logical_or(boost::simd::is_nge(xi, b),
                                                    boost::simd::is_nle(xi, e)), extrapval, yi);
   }
   return yi;
 }
Beispiel #4
0
 static inline A0_n asin(const A0_n a0_n)
 {
   const A0 a0 = { a0_n };
   A0 sign, x;
   x = nt2::abs(a0);
   sign = bitofsign(a0);
   const bA0 x_smaller_1e_4 = lt(x, single_constant<A0, 0x38d1b717>()); //1.0e-4f;
   const bA0 x_larger_05    = gt(x, Half<A0>());
   const bA0 x_else         = logical_or(x_smaller_1e_4, x_larger_05);
   A0 a = if_else_zero(x_smaller_1e_4, x);
   const A0 b = if_else_zero(x_larger_05, Half<A0>()*oneminus(x));
   A0 z = b_or(b_or(if_zero_else(x_else, sqr(x)), a), b);
   x = if_zero_else(x_else, x);
   a = if_else_zero(x_larger_05, sqrt(z));
   x = b_or(a, x);
   A0 z1 = madd(z,  single_constant<A0, 0x3d2cb352>(), single_constant<A0, 0x3cc617e3>());
   z1 = madd(z1, z, single_constant<A0, 0x3d3a3ec7>());
   z1 = madd(z1, z, single_constant<A0, 0x3d9980f6>());
   z1 = madd(z1, z, single_constant<A0, 0x3e2aaae4>());
   z1 = madd(z1, z*x, x);
   z = select(x_smaller_1e_4, z, z1);
   z1 = z+z;
   z1 = Pio_2<A0>()-z1;
   z = select(x_larger_05, z1, z);
   return b_xor(z, sign);
 }
Beispiel #5
0
	static inline A0 finalize(const A0&, const A0& x,
				  const A0& c, const A0 & k,
				  const A0& hi,const A0& lo)
	{
	  A0 y =   oneminus(((lo-(x*c)/(Two<A0>()-c))-hi));
	  return fast_ldexp(y, toint(k));
	}
Beispiel #6
0
	static inline A0 asin(const  A0& a0)
	{
	  A0 sign, x;
	  //	bf::tie(sign, x) = sign_and_abs(a0);
	  x = abs(a0);
	  sign = bitofsign(a0);
	  A0 x_smaller_1e_4 = lt(x, single_constant<A0, 0x38d1b717>()); //1.0e-4f;
	  A0 x_larger_05    = gt(x, Half<A0>());
	  A0 x_else         = b_or(x_smaller_1e_4, x_larger_05);
	  A0 a = b_and(x, x_smaller_1e_4);
	  A0 b = b_and(Half<A0>()*oneminus(x), x_larger_05);
	  A0 z = b_or(b_or(b_notand(x_else, sqr(x)), a), b);
	  x = b_notand(x_else, x);
	  a = b_and(sqrt(z), x_larger_05);
	  x = b_or(a, x);
	  A0 z1 = madd(z,  single_constant<A0, 0x3d2cb352>(), single_constant<A0, 0x3cc617e3>());
	  z1 = madd(z1, z, single_constant<A0, 0x3d3a3ec7>());
	  z1 = madd(z1, z, single_constant<A0, 0x3d9980f6>());
	  z1 = madd(z1, z, single_constant<A0, 0x3e2aaae4>());
	  z1 = madd(z1, z*x, x);
	  z = select(x_smaller_1e_4, z, z1);
	  z1 = z+z;
	  z1 = Pio_2<A0>()-z1;
	  z = select(x_larger_05, z1, z);
	  return b_xor(z, sign);
	}
Beispiel #7
0
 static inline A0_n asin(const A0_n a0_n)
 {
   const A0 a0 = { a0_n };
   typedef typename meta::scalar_of<A0>::type sA0;
   A0 x = nt2::abs(a0);
   const A0 pio4 =  Pio_4<A0>();
   const bA0 small=  lt(x, Sqrteps<A0>());
   const A0 morebits = double_constant<A0, 0xbc91a62633145c07ll>();
   const A0 ct1      = double_constant<A0, 0x3fe4000000000000ll>();
   A0 zz1 = oneminus(x);
   const A0 vp = zz1*horner< NT2_HORNER_COEFF_T(sA0, 5,
                                                (0x3f684fc3988e9f08ll,
                                                 0xbfe2079259f9290fll,
                                                 0x401bdff5baf33e6all,
                                                 0xc03991aaac01ab68ll,
                                                 0x403c896240f3081dll)
                                                )>(zz1)/
                   horner< NT2_HORNER_COEFF_T(sA0, 5,
                                              (0x3ff0000000000000ll,
                                               0xc035f2a2b6bf5d8cll,
                                               0x40626219af6a7f42ll,
                                               0xc077fe08959063eell,
                                               0x40756709b0b644bell)
                                              )>(zz1);
   zz1 =  sqrt(zz1+zz1);
   A0 z = pio4-zz1;
   zz1 = fma(zz1, vp, morebits);
   z =  z-zz1;
   zz1 = z+pio4;
   A0 zz2 = sqr(a0);
   z = zz2*horner< NT2_HORNER_COEFF_T(sA0, 6,
                                  (0x3f716b9b0bd48ad3ll,
                                   0xbfe34341333e5c16ll,
                                   0x4015c74b178a2dd9ll,
                                   0xc0304331de27907bll,
                                   0x40339007da779259ll,
                                   0xc020656c06ceafd5ll)
                                  )>(zz2)/
         horner< NT2_HORNER_COEFF_T(sA0, 6,
                                  (0x3ff0000000000000ll,
                                   0xc02d7b590b5e0eabll,
                                   0x40519fc025fe9054ll,
                                   0xc06265bb6d3576d7ll,
                                   0x4061705684ffbf9dll,
                                   0xc04898220a3607acll)
                                  )>(zz2);
   zz2 = x*z+x;
   return if_nan_else( gt(x, One<A0>())
                     , b_xor ( select( small
                                     , x
                                     , select( gt(x, ct1)
                                             , zz1
                                             , zz2
                                             )
                                     )
                             , bitofsign(a0)
                             )
                     );
 }
Beispiel #8
0
 static inline A0 acos(const  A0& a0)
 {
   if (a0 < Mhalf<A0>())
     return Pi<A0>()-asin( nt2::sqrt(oneplus(a0)*Half<A0>()))*Two<A0>();
   else if (a0 > Half<A0>())
     return asin( nt2::sqrt(oneminus(a0)*Half<A0>()))*Two<A0>();
   return (Pio_2<A0>()-asin(a0));
 }
Beispiel #9
0
	static inline A0 finalize(const A0& a0, const A0& x,
				  const A0& c, const A0 & k,
				  const A0& ,const A0& )
	{
	  details::ignore_unused(a0);
	  A0 y = oneminus(((-(x*c)/(Two<A0>()-c))-x));
	  return fast_ldexp(y, toint(k));
	}
 static inline A0 finalize(const A0& a0, const A0& x,
                           const A0& c, const A0 & k,
                           const A0& ,const A0& )
 {
   A0 y = oneminus(((-(x*c)/(Two<A0>()-c))-x));
   y = fast_ldexp(y, fast_toint(k));
   // adjust for 2^n n flint
   return where(isflint(a0), round(y), y);
 }
Beispiel #11
0
	static inline A0 finalize(const A0& a0, const A0& x,
				  const A0& c, const A0 & k,
				  const A0& ,const A0& )
	{
	  A0 y = oneminus(((-(x*c)/(Two<A0>()-c))-x));
	  y = fast_ldexp(y, toint(k));
	  // adjust for 2^n n flint
	  return  sel(b_and(is_gtz(a0), is_flint(a0)),  round2even(y), y);
	}
Beispiel #12
0
 static inline A0 cos_eval(const A0& z)
 {
   const A0 y = horner< NT2_HORNER_COEFF_T(stype, 7, (0x3da8ff831ad9b219ll,
                                                     0xbe21eea7c1e514d4ll,
                                                     0x3e927e4f8e06d9a5ll,
                                                     0xbefa01a019ddbcd9ll,
                                                     0x3f56c16c16c15d47ll,
                                                     0xbfa5555555555551ll,
                                                     0x3fe0000000000000ll) ) > (z);
   return oneminus(y*z);
 }
Beispiel #13
0
	static inline A0 asin(const  A0& a0)
	{
	  A0 x = nt2::abs(a0);
	  if ((x >  One<A0>())) return Nan<A0>();
	  if ((x <  Sqrteps<A0>())) return a0;
	  A0 zz;
	  if((x >  double_constant<double,0x3fe4000000000000ll> ())) //0.625;
	    {
	      zz = oneminus(x);
	      const A0 vp = zz*horner< NT2_HORNER_COEFF_T(stype, 5,
                   (0x3f684fc3988e9f08ll,
                    0xbfe2079259f9290fll,
                    0x401bdff5baf33e6all,
                    0xc03991aaac01ab68ll,
                    0x403c896240f3081dll)
                   )>(zz)/
		horner< NT2_HORNER_COEFF_T(stype, 5,
                   (0x3ff0000000000000ll,
                    0xc035f2a2b6bf5d8cll,
                    0x40626219af6a7f42ll,
                    0xc077fe08959063eell,
                    0x40756709b0b644bell)
                     )>(zz);
	      zz =  sqrt(zz+zz);
	      A0 z = Pio_4<A0>()-zz;
	      zz = madd(zz, vp, double_constant<double,0xbc91a62633145c07ll>());
	      z =  z-zz;
	      zz = z+Pio_4<A0>();
	    }
	  else
	    {
	      zz = sqr(x);
	      A0 z = zz*horner< NT2_HORNER_COEFF_T(stype, 6,
               (0x3f716b9b0bd48ad3ll,
                0xbfe34341333e5c16ll,
                0x4015c74b178a2dd9ll,
                0xc0304331de27907bll,
                0x40339007da779259ll,
                0xc020656c06ceafd5ll)
               )>(zz)/
             horner< NT2_HORNER_COEFF_T(stype, 6,
               (0x3ff0000000000000ll,
                0xc02d7b590b5e0eabll,
                0x40519fc025fe9054ll,
                0xc06265bb6d3576d7ll,
                0x4061705684ffbf9dll,
                0xc04898220a3607acll)
               )>(zz);
	      zz = x*z+x;
	    }
	  return b_xor(bitofsign(a0), zz);
	}
Beispiel #14
0
    BOOST_FORCEINLINE static void conf_bounds(const A0& a0, A1& a1,
                                              const M2x2 pcov,
                                              const value_type& normz,
                                              Out0 & p)
    {
      typedef typename boost::proto::result_of::child_c<A1&,1>::type         Out1;
      typedef typename boost::proto::result_of::child_c<A1&,2>::type         Out2;

      //      NT2_DISPLAY(a0.extent());   NT2_DISPLAY(a1.extent());
      p.resize(a0.extent());
      const In0& x  = boost::proto::child_c<0>(a0);
      //      NT2_DISPLAY(x);
      const In1& a = boost::proto::child_c<1>(a0);
      //      NT2_DISPLAY(a);
      const In2& b = boost::proto::child_c<2>(a0);
      //       NT2_DISPLAY(b);
      BOOST_AUTO_TPL(z, x/b);
      //       NT2_DISPLAY(z);
      //       NT2_DISPLAY(nt2::gammainc(z, a));
      //       NT2_DISPLAY(size(p));
      p =  nt2::exp(z); //nt2::gammainc(z, a);
      //       NT2_DISPLAY(p);
      //      Out0& p = boost::proto::child_c<0>(a1);
      //      NT2_DISPLAY(p);
      BOOST_AUTO_TPL(itp, (p/nt2::oneminus(p)));
      //       NT2_DISPLAY(itp);
      BOOST_AUTO_TPL(dp, nt2::rec(p*oneminus(p))); // derivative of logit(p) w.r.t. p
      //       NT2_DISPLAY(dp);
      BOOST_AUTO_TPL(da, dgammainc(z,a)*dp);       // dlogitp/da = dp/da * dlogitp/dp
      //       NT2_DISPLAY(da);
      BOOST_AUTO_TPL(db, -nt2::exp(a*nt2::log(z)-z-nt2::gammaln(a)-nt2::log(b))* dp); // dlogitp/db = dp/db * dlogitp/dp
      //      NT2_DISPLAY(db);
      BOOST_AUTO_TPL(varLogitp, pcov(1,1)*sqr(da) + (Two<value_type>()*pcov(1,2)*da + pcov(2,2)*db)*db);
      //       NT2_DISPLAY(varLogitp);
      //       NT2_DISPLAY(normz);
      BOOST_AUTO_TPL(exp_halfwidth, nt2::exp(normz*nt2::sqrt(varLogitp)));
      //       NT2_DISPLAY(exp_halfwidth);
      Out1 & plo = boost::proto::child_c<1>(a1);
      Out2 & pup = boost::proto::child_c<2>(a1);
      plo.resize(a0.extent());
      pup.resize(a0.extent());
      //      std::cout << "1" << std::endl;
      plo = itp*exp_halfwidth;
      //      std::cout << "2" << std::endl;
      pup = itp/exp_halfwidth;
      //      std::cout << "3" << std::endl;
      plo /= nt2::oneplus(plo);
      //      std::cout << "4" << std::endl;
      pup /= nt2::oneplus(pup);
      //      std::cout << "5" << std::endl;
    }
Beispiel #15
0
	static inline A0 acos(const  A0& a0)
	{
	  A0 x = abs(a0);
	  A0 z2 = asin(a0);
	  A0 isgtxh = gt(x, Half<A0>());
	  if (any(isgtxh))
	    {
	      A0 z1 = asin(sqrt(oneminus(x)*Half<A0>()))*Two<A0>();
	      z2 = select(isgtxh, z1, z2);
	    }
	  z2 = select(lt(a0, -Half<A0>()), Pi<A0>()-z2, z2);
	  return select(isgtxh, z2, Pio_2<A0>()-z2);
	  //	return Pi_o_2<A0>()-asin(a0); 
	}
Beispiel #16
0
 static inline A0_n acos(const A0_n a0_n)
 {
   const A0 a0 = { a0_n };
   A0 x = nt2::abs(a0);
   A0 z2 = {asin(a0)};
   bA0 isgtxh = gt(x, Half<A0>());
   if (nt2::any(isgtxh))
     {
       const A0 as = {asin(sqrt(oneminus(x)*Half<A0>()))};
       const A0 z1 = as*Two<A0>(); 
       z2 = select(isgtxh, z1, z2);
     }
   z2 = select(lt(a0, -Half<A0>()), Pi<A0>()-z2, z2);
   return select(isgtxh, z2, Pio_2<A0>()-z2);
 }