Пример #1
0
NT2_TEST_CASE_TPL ( full_qr_solve_expr, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_integer<T, signed>::type itype_t;
  typedef nt2::table<T> t_t;
  typedef nt2::table<itype_t> it_t;

  T bc[25] =  {
    1.0, 2.0, 0., 0., 0.,
    0. , 2.0, 0., 0., 0.,
    1.,  100.,  10000., 4., 0.2,
    .01,  1.,  100., 0.2, 0.1,
    .0001,  .01,  1., 0., 0.000
  };

  int k = 0;
  t_t a(nt2::of_size(5, 5));
  for(int i=1; i <= 5; i++)
    {
      for(int j=1; j <= 5; j++)
        {
          a(i, j) = bc[k++];
        }

    }
  NT2_DISPLAY(a);
  t_t x, b =  nt2::ones(5, 1, nt2::meta::as_<T>());
  NT2_DISPLAY(b);
  int32_t r;
  nt2::tie(x, r) = nt2::full_qr_solve(a, b);
  NT2_DISPLAY(x);

  NT2_TEST_ULP_EQUAL(nt2::mtimes(a, x), b, T(15000.0));
  NT2_TEST_ULP_EQUAL(nt2::rank(a), r, T(256.0));
}
Пример #2
0
NT2_TEST_CASE_TPL ( vandermonde_2, NT2_REAL_TYPES)
{
  typedef std::complex<T> cT;
  nt2::table<cT> a0(nt2::of_size(1, 3));
  for(int i=1; i <= 3; i++)
  {
    a0(i) = cT(i);
  }
  NT2_DISPLAY(a0);
  nt2::table<cT> v  =  nt2::vandermonde(a0);
  nt2::display("vandermonde(a0)", v);
  nt2::display("vandermonde(a0)", nt2::vandermonde(a0));
  T bc[9] =  {
    1, 1, 1,
    4, 2, 1,
    9, 3, 1
  };
  int k = 0;
  nt2::table<cT> a(nt2::of_size(3, 3));
  for(int i=1; i <= 3; i++)
  {
    for(int j=1; j <= 3; j++)
    {
      a(i, j) = cT(bc[k++]);
    }

  }
  NT2_DISPLAY(a);
 NT2_TEST(nt2::isulpequal(a, v, 2.0));
}
Пример #3
0
NT2_TEST_CASE_TPL( from_diag_offset, NT2_TYPES )
{
    nt2::table<T> y( nt2::of_size(1,5) ), x;

    for(size_t i=1; i<=nt2::length(y); i++) y(i) = i;
    NT2_DISPLAY(y);

    x = nt2::from_diag(y, -2);
    NT2_DISPLAY(x);

    NT2_TEST_EQUAL( nt2::ndims(x) , 2u             );
    NT2_TEST_EQUAL( nt2::size(x,1), nt2::length(y)+2);
    NT2_TEST_EQUAL( nt2::size(x,2), nt2::length(y)+2);

    for(size_t i=1; i<=nt2::length(y); i++) NT2_TEST_EQUAL( x(i+2,i), y(i) );

    x = nt2::from_diag(y, +2);
    NT2_DISPLAY(x);

    NT2_TEST_EQUAL( nt2::ndims(x) , 2u             );
    NT2_TEST_EQUAL( nt2::size(x,1), nt2::length(y)+2);
    NT2_TEST_EQUAL( nt2::size(x,2), nt2::length(y)+2);

    for(size_t i=1; i<=nt2::length(y); i++) NT2_TEST_EQUAL( x(i,i+2), y(i) );
}
Пример #4
0
NT2_TEST_CASE_TPL ( chol_lower2, NT2_REAL_TYPES)
{
  typedef nt2::table<T> table_t;
  table_t a , b = nt2::ones(4, 4, nt2::meta::as_<T>())
                + T(10)*nt2::eye(4, 4, nt2::meta::as_<T>());

  a = nt2::chol(b, nt2::lower_);
  //  NT2_DISPLAY(chol(b, nt2::lower_));
  NT2_DISPLAY(a);

  table_t u = nt2::ones(4, 9, nt2::meta::as_<T>());
  NT2_DISPLAY(u);

  u(nt2::_(1,4),nt2::_(1,4)) = chol(b, nt2::lower_);
  NT2_DISPLAY(u);

  table_t x;
  x = chol(b, nt2::lower_) + b;
  NT2_DISPLAY(x);

  b = nt2::zeros(4, 4, nt2::meta::as_<T>());
  b(1,1) = 1;
  a = nt2::chol(b, nt2::lower_);
  NT2_DISPLAY(a);
}
Пример #5
0
NT2_TEST_CASE_TPL ( linsolve_expr, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_integer<T, signed>::type itype_t;
  typedef nt2::table<T> t_t;

  T bc[25] =  {
    1.0, 2.0, 0., 0., 0.,
    0. , 2.0, 0., 0., 0.,
    1.,  100.,  10000., 4., 0.2,
    .01,  1.,  100., 0.2, 0.1,
    .0001,  .01,  1., 0., 0.000
  };

  int k = 0;
  t_t a(nt2::of_size(5, 5));
  for(int i=1; i <= 5; i++)
    {
      for(int j=1; j <= 5; j++)
        {
          a(i, j) = bc[k++];
        }

    }
  NT2_DISPLAY(a);
  t_t x, b =  nt2::ones(5, 1, nt2::meta::as_<T>());
  NT2_DISPLAY(b);
  T r;
  nt2::tie(x, r) = nt2::linsolve(a, b);
  NT2_DISPLAY(x);
  std::cout << r << std::endl;
  t_t z = nt2::mtimes(a, x);
  NT2_DISPLAY(z);
  std::cout << nt2::globalmax(nt2::ulpdist(z, b)) << std::endl;
  NT2_TEST(nt2::isulpequal(nt2::mtimes(a, x), b, T(512.0)));
}
Пример #6
0
NT2_TEST_CASE_TPL ( rref, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_integer<T, signed>::type  itype_t;
  typedef nt2::table<itype_t> it_t;
  typedef nt2::table<T> table_t;
  T A[16] = {
   16,    2,    3,   13,
    5,   11,   10,    8,
    9,    7,    6,   12,
   4,   14,   15,    1};
  table_t b = nt2::ones(4, 4, nt2::meta::as_<T>())
                + T(10)*nt2::eye(4, 4, nt2::meta::as_<T>());
  table_t rref, l, u, p;
  table_t a(nt2::of_size(4, 4));
  int k = 0;
  for(int i=1; i <= 4; ++i)
    {
      for(int j=1; j <= 4; ++j)
        {
          a(i, j) = A[k++];
        }
    }
  NT2_DISPLAY(a);
  nt2::tie(rref) = nt2::rref(a);
  NT2_DISPLAY(rref);
  it_t jb;

  nt2::tie(rref, jb) = nt2::rref(a);
  NT2_DISPLAY(rref);
  NT2_DISPLAY(jb);
  NT2_TEST(nt2::isulpequal(rref(nt2::_(1, nt2::numel(jb)), jb), nt2::eye(nt2::numel(jb), nt2::meta::as_<T>())));

}
Пример #7
0
NT2_TEST_CASE_TPL ( chebspec, NT2_REAL_TYPES)
{

  nt2::table<T> c30 =
    nt2::trans(nt2::reshape(nt2::cons(
                              T(1.5),   T(-2.0), T(0.5),
                              T(0.5),   T(-0.0), T(-0.5),
                              T(-0.5),  T(2.0),  T(-1.5)
                              ), nt2::of_size(3, 3)));
  nt2::table<T> v =  nt2::chebspec( 3, 0);
  nt2::display("v", v);
  NT2_DISPLAY(v);
  NT2_DISPLAY(c30);
  NT2_TEST_EQUAL(v, c30);
  nt2::table<T> c31 =
    nt2::trans(nt2::reshape(nt2::cons(
                              T(-1.0),   T(-3.0),  T(1.0),
                              T(3.0),    T(1.0),   T(-3.0),
                              T(-4.0),   T(12.0),  T(-9.5)
                              ), nt2::of_size(3, 3)))/T(3);
  nt2::table<T> v1 =  nt2::chebspec( 3, 1);
  nt2::display("v1", v1);
  NT2_DISPLAY(c31);
  NT2_TEST_ULP_EQUAL(v1, c31, 2.0);
}
Пример #8
0
NT2_TEST_CASE_TPL( complexify3, BOOST_SIMD_REAL_TYPES )
{
  typedef typename nt2::meta::as_dry<T>::type dT;
  nt2::table<dT> a0 = nt2::ones(3, 3, nt2::meta::as_<dT>());
  //  NT2_DISPLAY(a0);
  NT2_DISPLAY(complexify(a0));
  NT2_DISPLAY(complexify(complexify(a0)));
  NT2_TEST_EQUAL(nt2::real(a0), nt2::real(complexify(a0)));
}
Пример #9
0
NT2_TEST_CASE_TPL ( cauchy_ints, NT2_REAL_TYPES)
{
  NT2_DISPLAY(nt2::cauchy(3, 3, nt2::meta::as_<T>()));
  nt2::table<T> a0 = nt2::_(T(1), 3);
  NT2_DISPLAY(nt2::cauchy(a0));

  nt2::table<T> v =  cauchy(a0);
  NT2_DISPLAY(v);
  nt2::table<T> z = nt2::rec(nt2::cif(3, nt2::meta::as_<T>())+nt2::rif(3, nt2::meta::as_<T>()));
  NT2_TEST_EQUAL(v, z);
}
Пример #10
0
NT2_TEST_CASE_TPL ( ris, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_<T> ta_t;
  nt2::table<T> m3 =nt2::trans(nt2::cons(nt2::of_size(3, 3),
                                         T( 3),   T(  5),   T( 15),
                                         T( 5),   T( 15),   T(-15),
                                         T(15),   T(-15),   T( -5))/T(15));
  NT2_DISPLAY(m3);
  NT2_DISPLAY(nt2::ris(3,ta_t()));
  NT2_TEST_ULP_EQUAL(nt2::ris(3,ta_t()), m3, 0.5);
  NT2_TEST_ULP_EQUAL(nt2::ris<T>(3), m3, 0.5);
  // NT2_TEST_ULP_EQUAL(nt2::cast<T>(nt2::ris(3)), m3, 0.5);
}
Пример #11
0
NT2_TEST_CASE_TPL ( toeplitzexpr, NT2_REAL_TYPES)
{

  nt2::table<T> v1 = nt2::cons(T(1), T(1), T(1));
  nt2::table<T> v2 = nt2::cons(T(1), T(1), T(0));
  nt2::table<T> v =  nt2::toeplitz(v1, v2);
  T delta =  T(0);
  BOOST_AUTO_TPL( vv, nt2::toeplitz(v1, v2)+delta*nt2::ones(3, 3, nt2::meta::as_<T>()));
  NT2_DISPLAY(v);
  NT2_DISPLAY(vv);
  NT2_DISPLAY( nt2::toeplitz(v1, v2));
  NT2_TEST_EQUAL(v, nt2::toeplitz(v1, v2));
}
Пример #12
0
NT2_TEST_CASE_TPL ( lotkin, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_<T> ta_t;
  nt2::table<T> l3 =nt2::trans(nt2::cons(nt2::of_size(3, 3),
                                         T(60),    T(60),    T(60),
                                         T(30),    T(20),    T(15),
                                         T(20),    T(15),    T(12))/T(60));
  NT2_DISPLAY(l3);
  NT2_DISPLAY(nt2::lotkin(3,ta_t()));
  NT2_TEST_ULP_EQUAL(nt2::lotkin(3,ta_t()), l3, 0.5);
  NT2_TEST_ULP_EQUAL(nt2::lotkin<T>(3), l3, 0.5);
  NT2_TEST_ULP_EQUAL(nt2::cast<T>(nt2::lotkin(3)), l3, 0.5);
}
Пример #13
0
NT2_TEST_CASE_TPL( tsxfun_4, NT2_TYPES)
{
  nt2::table<T> a = nt2::reshape(nt2::_(T(1), T(6)),2, 1, 3);
  nt2::table<T> b = nt2::reshape(nt2::_(T(7), T(12)),1, 2, 1, 3);
  nt2::table<T> c = nt2::reshape(nt2::_(T(7), T(12)),2, 1, 1, 3);
  NT2_DISPLAY(a);
  NT2_DISPLAY(b);
  NT2_DISPLAY(c);
  nt2::functor<nt2::tag::fma_> f;
  nt2::table<T> d = nt2::tsxfun(f,  a, b, c);
  NT2_DISPLAY(d);

}
Пример #14
0
NT2_TEST_CASE_TPL ( hilb, NT2_REAL_TYPES)
{
  nt2::table<T> h3 =
    nt2::trans(nt2::reshape(nt2::cons(
                              T(1.0),     T(0.5),     T(1.0/3.0),
                              T(0.5),     T(1.0/3.0), T(0.25),
                              T(1.0/3.0), T(0.25),    T(0.2)
                              ), nt2::of_size(3, 3)));
  nt2::table<T> v = nt2::hilb(3, nt2::meta::as_<T>());
  NT2_DISPLAY(v);
  NT2_DISPLAY(h3);
  NT2_TEST_ULP_EQUAL(v, h3, 1);
}
Пример #15
0
NT2_TEST_CASE_TPL ( pei, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_<T> ta_t;
  nt2::table<T> m3 =nt2::trans(nt2::cons(nt2::of_size(3, 3),
                                         T(2),     T(1),     T(1),
                                         T(1),     T(2),     T(1),
                                         T(1),     T(1),     T(2)));
  NT2_DISPLAY(m3);
  NT2_DISPLAY(nt2::pei(3,ta_t()));
  NT2_TEST_ULP_EQUAL(nt2::pei(3,ta_t()), m3, 0.5);
  NT2_TEST_ULP_EQUAL(nt2::pei(3,T(1)), m3, 0.5);
  NT2_TEST_ULP_EQUAL(nt2::pei<T>(3), m3, 0.5);
  NT2_TEST_ULP_EQUAL(nt2::cast<T>(nt2::pei(3)), m3, 0.5);
}
Пример #16
0
NT2_TEST_CASE_TPL ( grcar, NT2_REAL_TYPES)
{
  nt2::table<T> grcar4 =nt2::trans(nt2::reshape(nt2::cons(
                                                 T( 1),    T( 1),    T( 1),     T(1),
                                                 T(-1),    T( 1),    T( 1),     T(1),
                                                 T( 0),    T(-1),    T( 1),     T(1),
                                                 T( 0),    T( 0),    T(-1),     T(1)),
                                               nt2::of_size(4, 4)));
  NT2_DISPLAY(grcar4);
  nt2::table<T> v = nt2::grcar(4, nt2::meta::as_<T>());
  NT2_DISPLAY(v);
  NT2_TEST_EQUAL(v, grcar4);
  NT2_TEST_EQUAL(nt2::grcar(4,nt2::meta::as_<T>()), grcar4);
  NT2_TEST_EQUAL(nt2::grcar(4,3,nt2::meta::as_<T>()), grcar4);
}
Пример #17
0
NT2_TEST_CASE_TPL( complexify2, BOOST_SIMD_REAL_TYPES )
{
  typedef typename nt2::meta::as_complex<T>::type cT;
  nt2::table<T>   a00 = nt2::ones(3, 3, nt2::meta::as_<T>());
  NT2_DISPLAY(a00);
  nt2::table<cT> a0 = cT(0, 1)*a00;

  for(int i=1; i < 9; i++)
  {
    std::cout << a0(i) << std::endl;
  }
  NT2_DISPLAY(complexify(a0));
  NT2_DISPLAY(complexify(complexify(a0)));
  NT2_TEST_EQUAL(complexify(a0), nt2::complexify(complexify(a0)));
}
Пример #18
0
NT2_TEST_CASE_TPL ( prolate, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_<T> ta_t;
  nt2::table<T> m3 =nt2::trans(nt2::cons(nt2::of_size(3, 3),
                                         T(0.500000000000000),   T(0.318309886183791),  T(0.000000000000000),
                                         T(0.318309886183791),   T(0.500000000000000),  T(0.318309886183791),
                                         T(0.000000000000000),   T(0.318309886183791),  T(0.500000000000000)
                                        ));
  NT2_DISPLAY(m3);
  NT2_DISPLAY(nt2::prolate(3,ta_t()));
  NT2_TEST_ULP_EQUAL(nt2::prolate(3,ta_t()), m3, 5);
  NT2_TEST_ULP_EQUAL(nt2::prolate(3,T(0.25)), m3, 5);
  NT2_TEST_ULP_EQUAL(nt2::prolate<T>(3), m3, 5);
  NT2_TEST_ULP_EQUAL(nt2::cast<T>(nt2::prolate(3)), m3, 5);
}
Пример #19
0
NT2_TEST_CASE_TPL ( toeppd, NT2_REAL_TYPES)
{
  nt2::table<T> m3 =nt2::trans(nt2::cons(nt2::of_size(3, 3),
                                         T(6),     T(2),     T(6),
                                         T(2),     T(6),     T(2),
                                         T(6),     T(2),     T(6)
                                        ));
  NT2_DISPLAY(m3);
  NT2_DISPLAY( nt2::toeppd(3,nt2::_(T(1), T(3)),
                             nt2::linspace(T(0),T(1),3)) );
  NT2_TEST_ULP_EQUAL(nt2::toeppd(3,nt2::_(T(1), T(3)), nt2::linspace(T(0),T(1),3)),
                     m3, 0.5);
  NT2_DISPLAY(nt2::toeppd(3, 3, nt2::meta::as_<T>())); //these 3 matrices are random and so not tested but for the build
  NT2_DISPLAY(nt2::toeppd<T>(3));
  NT2_DISPLAY(nt2::toeppd<T>(3, 4));
}
Пример #20
0
NT2_TEST_CASE_TPL ( gearmat, NT2_REAL_TYPES)
{
  nt2::table<T> gear4 =nt2::trans(nt2::reshape(nt2::cons(
                                                 T( 0),    T(1),     T(0),     T(1),
                                                 T( 1),    T(0),     T(1),     T(0),
                                                 T( 0),    T(1),     T(0),     T(1),
                                                 T(-1),    T(0),     T(1),     T(0)
                                               ),  nt2::of_size(4, 4)));
  NT2_DISPLAY(gear4);
  nt2::table<T> v = nt2::gearmat(4, 4, -4, nt2::meta::as_<T>());
  NT2_DISPLAY(v);
  NT2_TEST_EQUAL(v, gear4);
  NT2_TEST_EQUAL(nt2::gearmat(4,nt2::meta::as_<T>()), gear4);
  NT2_TEST_EQUAL(nt2::gearmat(4,T(4)), gear4);
  NT2_TEST_EQUAL(nt2::gearmat(4,T(4), T(-4)), gear4);
}
Пример #21
0
NT2_TEST_CASE_TPL ( krylov, NT2_REAL_TYPES)
{
  nt2::table<T> a = nt2::_(T(1), T(3));
  nt2::table<T> t30 =nt2::trans(nt2::reshape(nt2::cons(
                                               T(0), T(1), T(0),
                                               T(2), T(0), T(2),
                                               T(0), T(1), T(0)),
                                             nt2::of_size(3, 3)));

  nt2::table<T> kt30 =nt2::trans(nt2::reshape(nt2::cons(
                                               T(1), T(1), T(4),
                                               T(1), T(4), T(4),
                                               T(1), T(1), T(4)),
                                             nt2::of_size(3, 3)));
  NT2_TEST_ULP_EQUAL(krylov(t30, nt2::ones(3, 1, nt2::meta::as_<T>()), 3), kt30, 0.5);
  nt2::table<T> z = krylov(t30, nt2::ones(3, 1, nt2::meta::as_<T>()));
  NT2_TEST_ULP_EQUAL(z, kt30, 0.5);
  nt2::table<T> z1 = krylov(t30);
  NT2_TEST_ULP_EQUAL(z1, kt30, 0.5);
  nt2::table<T> z2 = nt2::cast<T>(nt2::krylov(3));
  NT2_DISPLAY(z2);


  NT2_TEST_ULP_EQUAL(krylov(t30, nt2::ones(3, 1, nt2::meta::as_<T>()))   , kt30, 0.5);
  NT2_TEST_ULP_EQUAL(krylov(t30), kt30, 0.5);
}
Пример #22
0
NT2_TEST_CASE_TPL( from_diag, NT2_TYPES )
{
    nt2::table<T> x,y( nt2::of_size(1,8) );

    for(size_t i=1; i<=nt2::length(y); i++) y(i) = i;

    NT2_DISPLAY(y);
    x = nt2::from_diag(y);
    NT2_DISPLAY(x);

    NT2_TEST_EQUAL( nt2::ndims(x) , 2u             );
    NT2_TEST_EQUAL( nt2::size(x,1), nt2::length(y));
    NT2_TEST_EQUAL( nt2::size(x,2), nt2::length(y));

    for(size_t i=1; i<=nt2::length(y); i++) NT2_TEST_EQUAL( x(i,i), y(i) );
}
Пример #23
0
NT2_TEST_CASE_TPL( globalsumc, NT2_REAL_TYPES )
{
  typedef std::complex<T> cT;
  nt2::table<cT> a = nt2::reshape(nt2::ones(1, 9, nt2::meta::as_<cT>()), 3, 3);
  NT2_DISPLAY(a);
  NT2_TEST_EQUAL( nt2::globalsum(a), cT(9));
  NT2_TEST_EQUAL( nt2::globalsum(cT(0)), cT(0));
}
Пример #24
0
NT2_TEST_CASE_TPL( complexify1, BOOST_SIMD_REAL_TYPES )
{
  nt2::table<T> a0 = nt2::_(T(1), T(3));
  NT2_DISPLAY(complexify(a0));
  NT2_DISPLAY(complexify(complexify(a0)));
  NT2_DISPLAY(complexify(nt2::_(T(1), T(3))));
  typedef typename nt2::meta::as_real<T>::type                          real_type;


  NT2_DISPLAY(nt2::complexify(nt2::_(real_type( 11)
                                     , real_type(-1)
                                     , real_type(0)
                                )));
  a0 = nt2::ones(3, 3, nt2::meta::as_<T>());
  NT2_TEST_EQUAL(a0, nt2::real(complexify(a0)));

}
Пример #25
0
NT2_TEST_CASE_TPL ( randhess, NT2_REAL_TYPES)
{
  nt2::table<T> r6 =nt2::trans(nt2::cons(nt2::of_size(5, 5),
    T( 5.403023058681398e-01),    T(-3.501754883740146e-01),    T(-7.574901860152801e-01),    T(-7.057887429219221e-02),    T(-8.171772273977561e-02),
    T(-8.414709848078965e-01),    T(-2.248450953661529e-01),    T(-4.863788550831339e-01),    T(-4.531817402397399e-02),    T(-5.247034636217886e-02),
    T(                     0),    T(-9.092974268256817e-01),    T( 4.119822456656830e-01),    T( 3.838629683166185e-02),    T( 4.444447142228624e-02),
    T(                     0),    T(                     0),    T(-1.411200080598672e-01),    T( 6.471022801057221e-01),    T( 7.492287917633427e-01),
    T(                     0),    T(                     0),    T(                     0),    T( 7.568024953079282e-01),    T(-6.536436208636119e-01))) ;
  NT2_DISPLAY(r6);
  NT2_DISPLAY( nt2::randhess(nt2::_(T(1), T(5))));
  NT2_TEST_ULP_EQUAL(nt2::randhess(nt2::_(T(1), T(5))),
                     r6, 1);
  NT2_DISPLAY( nt2::randhess(nt2::_(T(1), T(5))));
//   NT2_DISPLAY(nt2::randhess(5, nt2::meta::as_<T>())); //these 2 matrices are random and so not tested but for the build
//   NT2_DISPLAY(nt2::randhess<T>(5));

}
Пример #26
0
NT2_TEST_CASE_TPL ( tr_solve_expr, NT2_REAL_TYPES)
{
  typedef typename nt2::meta::as_integer<T, signed>::type itype_t;
  typedef nt2::table<T> t_t;
  typedef nt2::table<itype_t> it_t;

  t_t a(nt2::of_size(5, 5));
  for(int i=1; i <= 5; i++)
    {
      for(int j=1; j <= 5; j++)
        {
          a(i, j) =i >= j;
        }

    }
  NT2_DISPLAY(a);
  t_t x, b =  nt2::rif(5, 1, nt2::meta::as_<T>());
  NT2_DISPLAY(b);
  x = nt2::tr_solve(nt2::tril(a), b, 'L', 'N', 'N');
  NT2_DISPLAY(x);
  x = nt2::tr_solve(a, b, 'L', 'N', 'N');
  NT2_DISPLAY(x);
  x = nt2::tr_solve(nt2::triu(a), b, 'L', 'N', 'N');
  NT2_DISPLAY(x);
  x = nt2::tr_solve(a, b, 'U', 'N', 'N');
  NT2_DISPLAY(x);
  t_t z = nt2::mtimes(nt2::triu(a), x);
  NT2_DISPLAY(z);
  std::cout << nt2::globalmax(nt2::ulpdist(z, b)) << std::endl; 
  NT2_TEST(nt2::isulpequal(nt2::mtimes(nt2::triu(a), x), b, T(1.0)));


}
Пример #27
0
int main()
{
  nt2::table<double> I;

  // Generates 1 3 5 7
  I = nt2::colon(1., 2.,  7.);
  NT2_DISPLAY(I);

  // Generates 0. 0.1 ... 1.
  I = nt2::colon(0., 0.1, 1.);
  NT2_DISPLAY(I);

  nt2::table<int> U;

  // generates 4 ... -4
  U = nt2::colon(4, -2, -4);
  NT2_DISPLAY(U);
}
Пример #28
0
Файл: qr.cpp Проект: KWMalik/nt2
NT2_TEST_CASE_TPL ( qr2, NT2_REAL_TYPES)
{
  typedef nt2::table<T> table_t;
  table_t b = nt2::ones(4, 4, nt2::meta::as_<T>())
                + T(15)*nt2::eye(4, 4, nt2::meta::as_<T>());
  table_t qr, q, r, p;
  q = b;
  r = b;
  p =  b; 
  nt2::tie(q, r, p) = nt2::qr(b);
  NT2_DISPLAY(q);
  NT2_DISPLAY(r);
  NT2_DISPLAY(p);
  table_t zz = nt2::mtimes(nt2::trans(p), nt2::mtimes(q, r));
  NT2_DISPLAY(b);
  NT2_DISPLAY(zz); 
  std::cout <<        nt2::globalmax(nt2::ulpdist(b, zz)) << std::endl;
  NT2_TEST(nt2::isulpequal(zz, b, T(6.0)));
}
Пример #29
0
NT2_TEST_CASE_TPL ( cauchy_ints_2, NT2_REAL_TYPES)
{
  nt2::table<T> m3 =nt2::trans(nt2::cons(nt2::of_size(3, 3),
                                         T(90), T(-90), T(-30),
                                         T(30), T( 90), T(-90),
                                         T(18), T( 30), T( 90))/T(45));
  nt2::table<T> v =  nt2::cauchy(nt2::_(T(1.5), T(3.5)), -nt2::_(T(1), T(3)));
  NT2_DISPLAY(v);
  NT2_TEST_ULP_EQUAL(v, m3, 1);
}
Пример #30
0
NT2_TEST_CASE_TPL ( chol_upper, NT2_REAL_TYPES)
{
  typedef nt2::table<T> table_t;
  table_t a, z, b = nt2::ones(4, 4, nt2::meta::as_<T>())
                + T(10)*nt2::eye(4, 4, nt2::meta::as_<T>());
  int p = 999;

  nt2::tie(z) = nt2::chol(b);
  NT2_DISPLAY(z);

  nt2::tie(a,p) = nt2::chol(b, nt2::upper_);
  NT2_DISPLAY(a);
  NT2_TEST_EQUAL(p, 0u);

  b = nt2::zeros(4, 4, nt2::meta::as_<T>());
  b(1,1) = 1;
  nt2::tie(a,p) = nt2::chol(b,nt2::upper_);
  NT2_DISPLAY(a);
  NT2_TEST_EQUAL(p, 2u);
}