static inline A0 finalize(const A0& a0, const A0& , const A0& c , const A0& k, const A0& , const A0& ) { A0 y = fast_ldexp(c, toint(k)); //adjust for 10^n n flint return sel(b_and(is_gtz(a0), is_flint(a0)), round2even(y), y); }
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); }
result_type operator()(A0& out, const A1& in) const { size_t n = boost::proto::child_c<0>(in); value_type fn = value_type(n); table<value_type> ns = nt2::cons(of_size(1, 3), fn, fn/12, fn/20); table<i_type> ee(nt2::of_size(1, 3)); table<value_type> ff(nt2::of_size(1, 3)); // nt2::frexp(ns, ff, ee); nt2::frexp(ns(1), ff(1), ee(1)); nt2::frexp(ns(2), ff(2), ee(2)); nt2::frexp(ns(3), ff(3), ee(3)); BOOST_AUTO_TPL(kk, nt2::find(nt2::logical_and(eq(ff, nt2::Half<value_type>()), is_gtz(ee)))); BOOST_ASSERT_MSG(!nt2::isempty(kk), "n must be of form 2^m or 12*2^m or 20*2^m"); size_t k = kk(1); i_type e = nt2::minusone(ee(k)); out.resize(nt2::of_size(n, n)); table<value_type> h; if (k == 1) // n = 1 * 2^e; { h = nt2::One<value_type>(); } else if ( k == 2) // N = 12 * 2^e; { h = nt2::vertcat(nt2::ones(1,12,meta::as_<value_type>()), nt2::horzcat(nt2::ones(11,1,meta::as_<value_type>()), nt2::toeplitz(cons<value_type>(of_size(1, 11), -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1), cons<value_type>(of_size(1, 11), -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1) ) ) ); } else if ( k == 3) // N = 20 * 2^e; { h = vertcat(nt2::ones(1,20,meta::as_<value_type>()), nt2::horzcat(nt2::ones(19,1,meta::as_<value_type>()), nt2::hankel(cons<value_type>(of_size(1, 19),-1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1), cons<value_type>(of_size(1, 19),1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, -1, -1) ) ) ); } // Kronecker product construction. for (i_type i = 1; i <= e; ++i) { table<value_type> h1 = nt2::vertcat(nt2::horzcat(h, h), nt2::horzcat(h, -h)); h = h1; //ALIASING } out = h; return out; }
static inline void split(const X& x, size_t minsubs, XX& xx, L & pathlen) { // Split subintervals in the interval vector X so that, to working // precision, no subinterval is longer than 1/minsubs times the // total path length. Removes subintervals of zero length, except // that the resulting X will always has at least two elements on // return, i.e., if the total path length is zero, X will be // collapsed into a single interval of zero length. Also returns // the integration path length. typedef typename X::value_type itype_t; typedef typename meta::as_logical<itype_t> btype_t; typedef typename meta::as_integer<itype_t, signed> iitype_t; typedef typename container::table<itype_t> itab_t; typedef typename meta::as_real<itype_t>::type rtype_t; typedef typename container::table<rtype_t> rtab_t; typedef typename container::table<ptrdiff_t> ptab_t; rtab_t absdx = nt2::abs(nt2::diff(x)); pathlen = nt2::globalasum1(absdx); xx = x; if (pathlen > 0) { rtype_t udelta = minsubs/pathlen; rtab_t tmp_nnew = nt2::minusone(nt2::ceil(absdx*udelta)); //BOOST_AUTO_TPL(tmp_nnew, nt2::minusone(nt2::ceil(absdx*udelta))); ptab_t idxnew = nt2::rowvect(nt2::find(is_gtz(tmp_nnew))); rtab_t nnew = tmp_nnew(idxnew); for (size_t j = nt2::numel(idxnew); j >= 1; --j) { ptrdiff_t k = idxnew(j); rtype_t nnj = nnew(j); //Calculate new points. itab_t newpts = x(k)+(nt2::_(One<rtype_t>(), nnj)/oneplus(nnj))*(x(k+1)-x(k)); // newpts = newpts+x(k); // Insert the new points. itab_t xx1 = nt2::cath(nt2::cath(xx(nt2::_(begin_, k)),newpts),xx(nt2::_(k+1, end_))); xx = xx1; } } // Remove useless subintervals. itab_t xx1 = xx(nt2::cath(nt2::One<ptrdiff_t>(), nt2::oneplus(nt2::rowvect(nt2::find(nt2::is_nez(nt2::diff(xx))))))); if (nt2::isscalar(xx1)) xx = nt2::repnum(xx(begin_), 2, 1); else xx = xx1; }
BOOST_FORCEINLINE result_type operator()(const A0& a0, const A1&, const A2&) const { BOOST_ASSERT_MSG(is_gtz(a0), "Matrix must be positive definite"); return nt2::sqrt(a0); }