示例#1
0
文件: dist.cpp 项目: pesterie/nt2
NT2_TEST_CASE_TPL ( dist_unsigned_int__2_0,  NT2_UNSIGNED_TYPES)
{

    using nt2::dist;
    using nt2::tag::dist_;
    typedef typename nt2::meta::as_integer<T>::type iT;
    typedef typename nt2::meta::call<dist_(T,T)>::type r_t;
    typedef typename nt2::meta::scalar_of<r_t>::type ssr_t;
    typedef typename nt2::meta::upgrade<T>::type u_t;
    typedef typename boost::result_of<nt2::meta::arithmetic(T,T)>::type wished_r_t;


    // return type conformity test
    NT2_TEST( (boost::is_same < r_t, wished_r_t >::value) );
    std::cout << std::endl;
    double ulpd;
    ulpd=0.0;


    // specific values tests
    NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(), nt2::One<T>()), nt2::Zero<T>(), 0);
    NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(),nt2::Two<T>()), nt2::One<T>(), 0);
    NT2_TEST_ULP_EQUAL(dist(nt2::Two<T>(),nt2::One<T>()), nt2::One<T>(), 0);
    NT2_TEST_ULP_EQUAL(dist(nt2::Zero<T>(), nt2::Zero<T>()), nt2::Zero<T>(), 0);
} // end of test for unsigned_int_
示例#2
0
文件: dist.cpp 项目: fpelliccioni/nt2
NT2_TEST_CASE_TPL ( dist_real__2_0,  BOOST_SIMD_REAL_TYPES)
{

  using nt2::dist;
  using nt2::tag::dist_;
  typedef std::complex<T> cT;
  typedef typename boost::dispatch::meta::as_integer<T>::type iT;
  typedef typename boost::dispatch::meta::call<dist_(cT, cT)>::type r_t;
  typedef typename nt2::meta::scalar_of<r_t>::type sr_t;
  typedef typename nt2::meta::scalar_of<r_t>::type ssr_t;
  typedef nt2::imaginary<T> ciT;
  typedef nt2::dry<T> dT;
  typedef T wished_r_t;

  // return type conformity test
  NT2_TEST( (boost::is_same < r_t, wished_r_t >::value) );

  // specific values tests
  NT2_TEST_EQUAL(dist(cT(nt2::Inf<T>()), cT(nt2::Inf<T>())), nt2::Nan<T>());
  NT2_TEST_EQUAL(dist(cT(nt2::One<T>()), cT(nt2::Zero<T>())), nt2::One<T>());
  NT2_TEST_EQUAL(dist(cT(nt2::Zero<T>()), cT(nt2::Zero<T>())),nt2::Zero<T>());
  NT2_TEST_ULP_EQUAL(dist(cT(0, 1), cT(1, 0)), nt2::Sqrt_2<T>(), 0.5);
  NT2_TEST_ULP_EQUAL(dist(cT(0, nt2::Inf<T>()), cT(nt2::Inf<T>(), 0)), nt2::Inf<T>(), 0.5);
  NT2_TEST_ULP_EQUAL(dist(nt2::Inf<dT>(),nt2::Inf<dT>()), nt2::Nan<T>(), 0.5);
  NT2_TEST_EQUAL(dist(cT(1, 0), cT(1, 0)), nt2::Zero<T>());
  NT2_TEST_EQUAL(dist(cT(2, 1), ciT(1)), nt2::Two<T>());
  NT2_TEST_EQUAL(dist(ciT(1), ciT(0)), nt2::One<T>());
  NT2_TEST_EQUAL(dist(ciT(1), T(0)), nt2::One<T>());
} // end of test for floating_
示例#3
0
文件: dist.cpp 项目: caocuongngo/nt2
NT2_TEST_CASE_TPL ( dist_signed_int__2_0,  NT2_INTEGRAL_SIGNED_TYPES)
{

  using nt2::dist;
  using nt2::tag::dist_;
  typedef typename nt2::meta::as_integer<T>::type iT;
  typedef typename nt2::meta::call<dist_(T,T)>::type r_t;
  typedef typename nt2::meta::scalar_of<r_t>::type ssr_t;
  typedef typename nt2::meta::upgrade<T>::type u_t;
  typedef typename boost::common_type<T,T>::type wished_r_t;


  // return type conformity test
  NT2_TEST( (boost::is_same < r_t, wished_r_t >::value) );
  std::cout << std::endl;



  // specific values tests
  NT2_TEST_ULP_EQUAL(dist(nt2::Mone<T>(), nt2::Mone<T>()), nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(), nt2::One<T>()), nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(),nt2::Two<T>()), nt2::One<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Two<T>(),nt2::One<T>()), nt2::One<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Zero<T>(), nt2::Zero<T>()), nt2::Zero<T>(), 0);
} // end of test for signed_int_
示例#4
0
文件: dist.cpp 项目: KWMalik/nt2
NT2_TEST_CASE_TPL ( dist_real__2_0,  NT2_SIMD_REAL_TYPES)
{
  using nt2::dist;
  using nt2::tag::dist_;
  using nt2::load; 
  using boost::simd::native;
  using nt2::meta::cardinal_of;
  typedef NT2_SIMD_DEFAULT_EXTENSION  ext_t;
  typedef typename nt2::meta::upgrade<T>::type   u_t;
  typedef native<T,ext_t>                        n_t;
  typedef n_t                                     vT;
  typedef typename nt2::meta::as_integer<T>::type iT;
  typedef native<iT,ext_t>                       ivT;
  typedef typename nt2::meta::call<dist_(vT,vT)>::type r_t;
  typedef typename nt2::meta::call<dist_(T,T)>::type sr_t;
  typedef typename nt2::meta::scalar_of<r_t>::type ssr_t;
  double ulpd;
  ulpd=0.0;


  // specific values tests
  NT2_TEST_ULP_EQUAL(dist(nt2::Inf<vT>(), nt2::Inf<vT>())[0], nt2::Nan<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Inf<vT>(),nt2::Minf<vT>())[0], nt2::Inf<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Minf<vT>(), nt2::Minf<vT>())[0], nt2::Nan<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Mone<vT>(), nt2::Mone<vT>())[0], nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Nan<vT>(), nt2::Nan<vT>())[0], nt2::Nan<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<vT>(), nt2::One<vT>())[0], nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<vT>(),nt2::Two<vT>())[0], nt2::One<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Two<vT>(),nt2::One<vT>())[0], nt2::One<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Zero<vT>(), nt2::Zero<vT>())[0], nt2::Zero<T>(), 0);
} // end of test for floating_
示例#5
0
文件: dist.cpp 项目: fpelliccioni/nt2
NT2_TEST_CASE_TPL ( dist_real__2_0,  NT2_REAL_TYPES)
{

  using nt2::dist;
  using nt2::tag::dist_;
  typedef typename nt2::meta::as_integer<T>::type iT;
  typedef typename nt2::meta::call<dist_(T,T)>::type r_t;
  typedef typename nt2::meta::scalar_of<r_t>::type ssr_t;
  typedef typename nt2::meta::upgrade<T>::type u_t;
  typedef typename boost::common_type<T,T>::type wished_r_t;


  // return type conformity test
  NT2_TEST( (boost::is_same < r_t, wished_r_t >::value) );
  std::cout << std::endl;
  double ulpd;
  ulpd=0.0;


  // specific values tests
  NT2_TEST_ULP_EQUAL(dist(nt2::Inf<T>(), nt2::Inf<T>()), nt2::Nan<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Inf<T>(),nt2::Minf<T>()), nt2::Inf<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Minf<T>(), nt2::Minf<T>()), nt2::Nan<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Mone<T>(), nt2::Mone<T>()), nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Nan<T>(), nt2::Nan<T>()), nt2::Nan<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(), nt2::One<T>()), nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(),nt2::Two<T>()), nt2::One<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Two<T>(),nt2::One<T>()), nt2::One<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Zero<T>(), nt2::Zero<T>()), nt2::Zero<T>(), 0);
} // end of test for floating_
示例#6
0
文件: dist.cpp 项目: sschaetz/nt2
NT2_TEST_CASE_TPL ( dist_real__2_0,  BOOST_SIMD_REAL_TYPES)
{
  using nt2::dist;
  using nt2::tag::dist_;

  typedef nt2::dry<T> dT;
  typedef std::complex<T> cT;

  // return type conformity test
  NT2_TEST_TYPE_IS( typename boost::dispatch::meta::call<dist_(cT, cT)>::type
                  , T
                  );

  NT2_TEST_TYPE_IS( typename boost::dispatch::meta::call<dist_(dT, dT)>::type
                  , T
                  );

  // specific values tests
  NT2_TEST_EQUAL(dist(cT(nt2::Inf<T>()), cT(nt2::Inf<T>())), nt2::Nan<T>());
  NT2_TEST_EQUAL(dist(cT(nt2::One<T>()), cT(nt2::Zero<T>())), nt2::One<T>());
  NT2_TEST_EQUAL(dist(cT(nt2::Zero<T>()), cT(nt2::Zero<T>())),nt2::Zero<T>());
  NT2_TEST_ULP_EQUAL(dist(cT(0, 1), cT(1, 0)), nt2::Sqrt_2<T>(), 0.5);
  NT2_TEST_ULP_EQUAL(dist(cT(0, nt2::Inf<T>()), cT(nt2::Inf<T>(), 0)), nt2::Inf<T>(), 0.5);
  NT2_TEST_ULP_EQUAL(dist(nt2::Inf<dT>(),nt2::Inf<dT>()), nt2::Nan<T>(), 0.5);
  NT2_TEST_EQUAL(dist(cT(1, 0), cT(1, 0)), nt2::Zero<T>());
} // end of test for floating_
示例#7
0
NT2_TEST_CASE_TPL ( dist_integer_ui,  BOOST_SIMD_SIMD_UNSIGNED_TYPES)
{
  using nt2::dist;
  using nt2::tag::dist_;
  using boost::simd::native;

  typedef BOOST_SIMD_DEFAULT_EXTENSION  ext_t;
  typedef native<T,ext_t>                  vT;

  NT2_TEST_TYPE_IS( typename boost::dispatch::meta::call<dist_(vT,vT)>::type
                  , vT
                  );

  NT2_TEST_EQUAL(dist(nt2::Zero<vT>(), nt2::Zero<vT>()), nt2::Zero<vT>());
  NT2_TEST_EQUAL(dist(nt2::One<vT>(), nt2::Three<vT>()), nt2::Two<vT>());
  NT2_TEST_EQUAL(dist(nt2::Valmax<vT>(), nt2::Zero<vT>()), nt2::Valmax<vT>());
  NT2_TEST_EQUAL(dist(nt2::Zero<vT>(), nt2::Valmax<vT>()), nt2::Valmax<vT>());
}
示例#8
0
NT2_TEST_CASE_TPL ( dist_signed_int__2_0,  NT2_INTEGRAL_SIGNED_TYPES)
{
  
  using nt2::dist;
  using nt2::tag::dist_;
  typedef typename nt2::meta::as_integer<T>::type iT;
  typedef typename nt2::meta::call<dist_(T,T)>::type r_t;
  typedef typename nt2::meta::upgrade<T>::type u_t;
  typedef typename boost::result_of<nt2::meta::arithmetic(T,T)>::type wished_r_t;


  // return type conformity test 
  NT2_TEST( (boost::is_same < r_t, wished_r_t >::value) );
  std::cout << std::endl; 
  double ulpd;
  ulpd=0.0;


  // specific values tests
  NT2_TEST_ULP_EQUAL(dist(nt2::Mone<T>(), nt2::Mone<T>()), nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::One<T>(), nt2::One<T>()), nt2::Zero<T>(), 0);
  NT2_TEST_ULP_EQUAL(dist(nt2::Zero<T>(), nt2::Zero<T>()), nt2::Zero<T>(), 0);
  // random verifications
  static const uint32_t NR = NT2_NB_RANDOM_TEST;
  {
    NT2_CREATE_BUF(tab_a0,T, NR, nt2::Valmin<T>()/2, nt2::Valmax<T>()/2);
    NT2_CREATE_BUF(tab_a1,T, NR, nt2::Valmin<T>(), nt2::Valmax<T>());
    double ulp0, ulpd ; ulpd=ulp0=0.0;
    T a0;
    T a1;
    for (uint32_t j =0; j < NR; ++j )
      {
        std::cout << "for params "
                  << "  a0 = "<< u_t(a0 = tab_a0[j])
                  << ", a1 = "<< u_t(a1 = tab_a1[j])
                  << std::endl;
        NT2_TEST_ULP_EQUAL( nt2::dist(a0,a1),a0>a1 ? a0-a1 : a1-a0,0);
        ulp0=nt2::max(ulpd,ulp0);
     }
     std::cout << "max ulp found is: " << ulp0 << std::endl;
   }
} // end of test for signed_int_
示例#9
0
文件: dist.cpp 项目: fpelliccioni/nt2
NT2_TEST_CASE_TPL ( dist_real__2_0,  NT2_SIMD_REAL_TYPES)
{
  using nt2::dist;
  using nt2::tag::dist_;
  using nt2::load;
  using boost::simd::native;
  using nt2::meta::cardinal_of;
  typedef NT2_SIMD_DEFAULT_EXTENSION  ext_t;
  typedef typename nt2::meta::upgrade<T>::type   u_t;
  typedef native<T,ext_t>                        n_t;
  typedef n_t                                     vT;
  typedef typename nt2::meta::as_integer<T>::type iT;
  typedef native<iT,ext_t>                       ivT;
  typedef typename nt2::meta::call<dist_(vT,vT)>::type r_t;
  typedef typename nt2::meta::call<dist_(T,T)>::type sr_t;
  typedef typename nt2::meta::scalar_of<r_t>::type ssr_t;
  double ulpd;
  ulpd=0.0;

  // random verifications
  static const nt2::uint32_t NR = NT2_NB_RANDOM_TEST;
  {
    NT2_CREATE_BUF(tab_a0,T, NR, -10.0, 10.0);
    NT2_CREATE_BUF(tab_a1,T, NR, -10.0, 10.0);
    double ulp0, ulpd ; ulpd=ulp0=0.0;
    for(nt2::uint32_t j = 0; j < NR;j+=cardinal_of<n_t>::value)
      {
        vT a0 = load<vT>(&tab_a0[0],j);
        vT a1 = load<vT>(&tab_a1[0],j);
        r_t v = dist(a0,a1);
        for(nt2::uint32_t i = 0; i< cardinal_of<n_t>::value; i++)
        {

          NT2_TEST_ULP_EQUAL( v[i],ssr_t(nt2::dist (a0[i],a1[i])), 2.5);
          ulp0 = nt2::max(ulpd,ulp0);
        }
      }
    std::cout << "max ulp found is: " << ulp0 << std::endl;
  }
} // end of test for floating_
示例#10
0
NT2_TEST_CASE_TPL ( dist_real,  BOOST_SIMD_SIMD_REAL_TYPES)
{
  using nt2::dist;
  using nt2::tag::dist_;
  using boost::simd::native;

  typedef BOOST_SIMD_DEFAULT_EXTENSION  ext_t;
  typedef native<T,ext_t>                  vT;

  NT2_TEST_TYPE_IS( typename boost::dispatch::meta::call<dist_(vT,vT)>::type
                  , vT
                  );

#ifndef BOOST_SIMD_NO_INVALIDS
  NT2_TEST_EQUAL(dist(nt2::Inf<vT>() , nt2::Inf<vT>()) , nt2::Nan<vT>());
  NT2_TEST_EQUAL(dist(nt2::Minf<vT>(), nt2::Minf<vT>()), nt2::Nan<vT>());
  NT2_TEST_EQUAL(dist(nt2::Nan<vT>() , nt2::Nan<vT>()) , nt2::Nan<vT>());
#endif

  NT2_TEST_EQUAL(dist(nt2::Zero<vT>(), nt2::Zero<vT>()), nt2::Zero<vT>());
  NT2_TEST_EQUAL(dist(nt2::Mone<vT>(), nt2::One<vT>()), nt2::Two<vT>());
  NT2_TEST_EQUAL(dist(nt2::One<vT>(), nt2::Three<vT>()), nt2::Two<vT>());
}
示例#11
0
文件: dist.cpp 项目: Mathieu-/nt2
#include <nt2/sdk/functor/meta/call.hpp>
#include <nt2/sdk/meta/as_unsigned.hpp>
#include <boost/type_traits/is_same.hpp>
#include <nt2/toolbox/arithmetic/include/dist.hpp>
#include <nt2/sdk/unit/tests.hpp>
#include <nt2/sdk/unit/module.hpp>

//////////////////////////////////////////////////////////////////////////////
// Test behavior of arithmetic components using NT2_TEST_CASE
//////////////////////////////////////////////////////////////////////////////


NT2_TEST_CASE_TPL ( dist,  (double)(nt2::uint64_t)(nt2::int64_t) 
                          (float)(nt2::uint32_t)(nt2::int32_t)  
                          (nt2::uint16_t)(nt2::int16_t)         
                          (nt2::uint8_t)(nt2::int8_t)
                  )
{
  using nt2::dist;
  using nt2::functors::dist_;

  NT2_TEST( (boost::is_same < typename nt2::meta::call<dist_(T, T)>::type
	     , typename boost::result_of<nt2::meta::arithmetic(T, T)>::type
              >::value)
           );
  NT2_TEST_EQUAL(  dist( T(42), T(12)), T(30) );
  NT2_TEST_EQUAL(  dist( T(12), T(42) ), T(30) );

}