Beispiel #1
0
 template < class S > void compute(const size_t & n, const S& t, S& r) const
 {
   typedef typename S::value_type v_type;
   if (nt2::isdiagonal(t))
   {
     r = nt2::from_diag(nt2::sqrt(nt2::diag_of(t)));
   }
   else
   {
     // Compute upper triangular square root R of T, a column at a time.
     r = nt2::zeros(n, n, meta::as_<v_type>());
     for (size_t j=1; j <= n; ++j)
     {
       r(j,j) = nt2::sqrt(t(j,j));
       for (size_t i=j-1; i >= 1; --i)
       {
         //itab_ k = _(i+1, j-1);
         v_type s = nt2::globalsum(nt2::multiplies(colvect(r(i,_(i+1, j-1))),
                                                   colvect(r(_(i+1, j-1),j))));
         //                  value_type s = nt2::mtimes(r(i,_(i+1, j-1)), r(_(i+1, j-1),j));
         r(i,j) = (t(i,j) - s)/(r(i,i) + r(j,j));
       }
     }
   }
 }
Beispiel #2
0
 static void evenx2(A0& out, std::size_t n)
 {
   value_type nn = n;
   BOOST_AUTO_TPL(p, nt2::_(value_type(1), nn));
   BOOST_AUTO_TPL(j, nt2::trunc(nt2::mod(p,nt2::Four<value_type>())*nt2::Half<value_type>()));
   BOOST_AUTO_TPL(k, nt2::sx(nt2::tag::is_equal_(), j, nt2::colvect(j)));
   BOOST_AUTO_TPL(p1, colvect(nt2::_(value_type(1), nn, nt2::sqr(nn))));
   out =  nt2::sx(nt2::tag::plus_(),p1,nt2::minusone(p));
   out(k) = nt2::oneplus(sqr(nn)) - out(k);
 }
Beispiel #3
0
 template <class XPR> vtab_t eval(const XPR & xxi){
   vtab_t xi =  rowvect(xxi);
   itab_t index = nt2::bsearch (breaks, xi);
   vtab_t val   = coefs(index, 1);
   for(size_t i=2; i <= order; ++i){
     val = mul(colvect(xi-breaks(index)), val) + coefs(index,i);
   }
   val = nt2::reshape(val, size(xxi));
   return val; 
 }
Beispiel #4
0
      BOOST_AUTO_TPL(p, nt2::_(value_type(1), nn));
      BOOST_AUTO_TPL(j, nt2::trunc(nt2::mod(p,nt2::Four<value_type>())*nt2::Half<value_type>()));
      BOOST_AUTO_TPL(k, nt2::sx(nt2::tag::is_equal_(), j, nt2::colvect(j)));
      BOOST_AUTO_TPL(p1, colvect(nt2::_(value_type(1), nn, nt2::sqr(nn))));
      out =  nt2::sx(nt2::tag::plus_(),p1,nt2::minusone(p));
      out(k) = nt2::oneplus(sqr(nn)) - out(k);
    }

    static void evenx1(A0& out, std::size_t n)
    {
      std::size_t m = n >> 1;   //m is odd.
      oddOrderMagicSquare(out, m);
      value_type m2 = sqr(m);
      container::table<value_type> t =  nt2::catv(cath(out, out+Two<value_type>()*m2),
                                                  cath(out+Three<value_type>()*m2, out+m2));
      BOOST_AUTO_TPL(i,  colvect(nt2::_(1, m)));
      std::size_t k = (n-2) >> 2;
      BOOST_AUTO_TPL(j, nt2::cath(nt2::_(std::size_t(1), k), nt2::_(n-k+2, n)));
      swap_lines(t, i, i+m, j);
      std::size_t k1 = k+1;
      BOOST_AUTO_TPL(ii, nt2::_(k1, k1));
      BOOST_AUTO_TPL(jj, nt2::_(std::size_t(1), k+1));
      swap_lines(t, ii, ii+m, jj);
      out =  t;
    }

    template < class M, class I1, class I2, class IDX > static
    void swap_lines(M& m, I1 i1, I2 i2, const IDX & j)
    {
      container::table<value_type> tmp = m(i1, j);//buggy if i1 i2 are integers
      m(i1, j) = m(i2, j);