本文整理汇总了C++中nt2类的典型用法代码示例。如果您正苦于以下问题:C++ nt2类的具体用法?C++ nt2怎么用?C++ nt2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了nt2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( seladd_real__2_0, NT2_REAL_TYPES)
{
using nt2::seladd;
using nt2::tag::seladd_;
using nt2::logical;
typedef std::complex<T> cT;
NT2_TEST_TYPE_IS( typename nt2::meta::call<seladd_(logical<T>, cT, cT)>::type
, cT
);
// specific values tests
NT2_TEST_EQUAL(seladd(nt2::False< logical<T> >(), cT(1), cT(0, 1)), cT(1));
NT2_TEST_EQUAL(seladd(nt2::True< logical<T> >(),cT(1),cT(0, 1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Inf<cT>(), cT(1),cT(0, 1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Minf<cT>(), cT(1),cT(0, 1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Nan<cT>(), cT(1),cT(0, 1)) , cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Zero<cT>(), cT(1),cT(0, 1)), cT(1));
NT2_TEST_EQUAL(seladd(nt2::False< logical<T> >(), T(1), cT(0, 1)), cT(1));
NT2_TEST_EQUAL(seladd(nt2::True< logical<T> >(),T(1),cT(0, 1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Inf<cT>(), T(1),cT(0, 1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Minf<cT>(), T(1),cT(0, 1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Nan<cT>(), T(1),cT(0, 1)) , cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Zero<cT>(), T(1),cT(0, 1)), cT(1));
NT2_TEST_EQUAL(seladd(nt2::False< logical<T> >(),cT(0, 1), T(1)), cT(0, 1));
NT2_TEST_EQUAL(seladd(nt2::True< logical<T> >(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Inf<cT>(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Minf<cT>(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Nan<cT>(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Zero<cT>(), cT(0, 1), T(1)), cT(0, 1));
NT2_TEST_EQUAL(seladd(nt2::Inf<T>(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Minf<T>(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Nan<T>(), cT(0, 1), T(1)), cT(1, 1));
NT2_TEST_EQUAL(seladd(nt2::Zero<T>(), cT(0, 1), T(1)), cT(0, 1));
} // end of test for floating_
示例2: NT2_TEST_EQUAL
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<firstbitset_(vT)>::type r_t;
typedef typename nt2::meta::call<firstbitset_(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_EQUAL(firstbitset(nt2::Inf<vT>())[0], 8388608u);
NT2_TEST_EQUAL(firstbitset(nt2::Minf<vT>())[0], 8388608u);
NT2_TEST_EQUAL(firstbitset(nt2::Nan<vT>())[0], nt2::One<sr_t>());
NT2_TEST_EQUAL(firstbitset(nt2::Signmask<vT>())[0], nt2::One<sr_t>()+nt2::Valmax<sr_t>()/2);
NT2_TEST_EQUAL(firstbitset(nt2::Zero<vT>())[0], nt2::Zero<sr_t>());
} // end of test for float
NT2_TEST_CASE_TPL ( firstbitset_double_1_0, (double))
{
using nt2::firstbitset;
using nt2::tag::firstbitset_;
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;
示例3: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( fast_sincosd_unsigned_int__1_0, NT2_UNSIGNED_TYPES)
{
using nt2::fast_sincosd;
using nt2::tag::fast_sincosd_;
typedef typename boost::result_of<nt2::meta::floating(T)>::type ftype;
typedef typename nt2::meta::as_integer<T>::type iT;
typedef typename nt2::meta::call<fast_sincosd_(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 boost::fusion::tuple<ftype,ftype> 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
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,0>::type>::type r_t0;
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,1>::type>::type r_t1;
{
r_t res = fast_sincosd(nt2::Zero<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Zero<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::One<r_t0>(), 0.75);
}
{
r_t res = fast_sincosd(nt2::_45<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
}
// specific values tests
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,0>::type>::type r_t0;
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,1>::type>::type r_t1;
{
r_t res = fast_sincosd(nt2::Zero<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Zero<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::One<r_t0>(), 0.75);
}
{
r_t res = fast_sincosd(nt2::_45<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
}
// specific values tests
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,0>::type>::type r_t0;
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,1>::type>::type r_t1;
{
r_t res = fast_sincosd(nt2::Zero<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Zero<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::One<r_t0>(), 0.75);
}
{
r_t res = fast_sincosd(nt2::_45<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
}
// specific values tests
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,0>::type>::type r_t0;
typedef typename nt2::meta::strip<typename boost::fusion::result_of::at_c<r_t,1>::type>::type r_t1;
{
r_t res = fast_sincosd(nt2::Zero<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Zero<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::One<r_t0>(), 0.75);
}
{
r_t res = fast_sincosd(nt2::_45<T>());
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<0>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
NT2_TEST_TUPLE_ULP_EQUAL( boost::fusion::get<1>(res), nt2::Sqrt_2o_2<r_t0>(), 0.75);
}
} // end of test for unsigned_int_
示例4: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( cscpi_real__1_0, NT2_REAL_TYPES)
{
using nt2::cscpi;
using nt2::tag::cscpi_;
typedef typename nt2::meta::as_integer<T>::type iT;
typedef typename nt2::meta::call<cscpi_(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::dispatch::meta::as_floating<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(cscpi(-nt2::Quarter<T>()), -nt2::Sqrt_2<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(-nt2::Zero<T>()), nt2::Minf<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Half<T>()), nt2::One<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Inf<T>()), nt2::Nan<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Mhalf<T>()), nt2::Mone<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Minf<T>()), nt2::Nan<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Mone<T>()), nt2::Nan<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Nan<T>()), nt2::Nan<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::One<T>()), nt2::Nan<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Quarter<T>()), nt2::Sqrt_2<r_t>(), 0.5);
NT2_TEST_ULP_EQUAL(cscpi(nt2::Zero<T>()), nt2::Inf<r_t>(), 0.5);
} // end of test for floating_
示例5: NT2_TEST_CASE_TPL
, (T)
);
}
NT2_TEST_CASE_TPL( ind2sub, (double)(float)(int) )
{
using nt2::table;
using nt2::ind2sub;
using nt2::of_size;
using nt2::tie;
using nt2::cons;
using nt2::ones;
table<T> inds,x,y,z,w;
table<T> rx = cons(T(1),T(2),T(1),T(2),T(1),T(2),T(1),T(2));
table<T> ry = cons(T(1),T(1),T(2),T(2),T(3),T(3),T(4),T(4));
table<T> rz = cons(T(1),T(1),T(1),T(1),T(2),T(2),T(2),T(2));
inds = cons(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8));
x = ind2sub(of_size(2,2,2), inds);
NT2_TEST_EQUAL(x, inds);
NT2_TEST_EQUAL(x.extent(), inds.extent());
nt2::tie(x,y) = ind2sub(of_size(2,4), inds);
NT2_TEST_EQUAL(x, rx);
NT2_TEST_EQUAL(x.extent(), inds.extent());
NT2_TEST_EQUAL(y, ry);
NT2_TEST_EQUAL(y.extent(), inds.extent());
示例6: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( iround_real__1_0, NT2_REAL_TYPES)
{
using nt2::iround;
using nt2::tag::iround_;
using nt2::load;
using nt2::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<iround_(vT)>::type r_t;
typedef typename nt2::meta::call<iround_(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(iround(nt2::splat<vT>(1.4))[0], 1, 0);
NT2_TEST_ULP_EQUAL(iround(nt2::splat<vT>(1.5))[0], 2, 0);
NT2_TEST_ULP_EQUAL(iround(nt2::splat<vT>(1.6))[0], 2, 0);
NT2_TEST_ULP_EQUAL(iround(nt2::splat<vT>(2.5))[0], 2, 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Half<vT>())[0], nt2::Zero<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Inf<vT>())[0], nt2::Inf<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Mhalf<vT>())[0], nt2::Zero<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Minf<vT>())[0], nt2::Minf<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Mone<vT>())[0], nt2::Mone<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Nan<vT>())[0], nt2::Zero<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::One<vT>())[0], nt2::One<sr_t>(), 0);
NT2_TEST_ULP_EQUAL(iround(nt2::Zero<vT>())[0], nt2::Zero<sr_t>(), 0);
} // end of test for real_
示例7: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( lcm_real__2_0, NT2_REAL_TYPES)
{
using nt2::lcm;
using nt2::tag::lcm_;
typedef typename nt2::meta::as_integer<T>::type iT;
typedef typename nt2::meta::call<lcm_(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)>::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(lcm(T(120),T(80)), T(240), 0);
NT2_TEST_ULP_EQUAL(lcm(T(3),T(15)), T(15), 0);
NT2_TEST_ULP_EQUAL(lcm(T(3),T(5)), T(15), 0);
NT2_TEST_ULP_EQUAL(lcm(T(6),T(15)), T(30), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::Inf<T>(), nt2::Inf<T>()), nt2::Nan<T>(), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::Inf<T>(),T(5)), nt2::Nan<T>(), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::Minf<T>(), nt2::Minf<T>()), nt2::Nan<T>(), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::Mone<T>(), nt2::Mone<T>()), nt2::One<T>(), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::Nan<T>(), nt2::Nan<T>()), nt2::Nan<T>(), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::One<T>(), nt2::One<T>()), nt2::One<T>(), 0);
NT2_TEST_ULP_EQUAL(lcm(nt2::Zero<T>(), nt2::Zero<T>()), nt2::Nan<T>(), 0);
} // end of test for floating_
示例8: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( is_negative_real__1_0, NT2_REAL_TYPES)
{
using nt2::is_negative;
using nt2::tag::is_negative_;
typedef typename nt2::meta::as_integer<T>::type iT;
typedef typename nt2::meta::call<is_negative_(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 nt2::meta::as_logical<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_EQUAL(is_negative((-nt2::Zero<T>())), nt2::True<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Half<T>()), nt2::False<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Inf<T>()), nt2::False<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Minf<T>()), nt2::True<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Mone<T>()), nt2::True<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Mzero<T>()), nt2::True<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Nan<T>()), nt2::True<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::One<T>()), nt2::False<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Quarter<T>()), nt2::False<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Two<T>()), nt2::False<r_t>());
NT2_TEST_EQUAL(is_negative(nt2::Zero<T>()), nt2::False<r_t>());
} // end of test for floating_
示例9: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL( cumtrapz_mat, NT2_REAL_TYPES )
{
using nt2::table;
using nt2::of_size;
using nt2::cumtrapz;
using nt2::reshape;
using nt2::trans;
using nt2::cons;
using nt2::_;
using nt2::_2D;
using nt2::meta::as_;
table<T> y = reshape(_(T(1), T(15)), 3, 5); // test fails if y is _2D
table<T, _2D> r1= trans(reshape(cons(
T(0 ), T(0 ), T(0 ), T(0 ),T( 0 ),
T(1.5), T(4.5), T(7.5), T(10.5),T( 13.5),
T(4.0), T(10.), T(16.0),T(22.0),T( 28.0)
), 5, 3));
table<T, _2D> r2= trans(reshape(cons(
T(0), T(2.5), T( 8.0), T(16.5), T(28.0),
T(0), T(3.5), T(10.0), T(19.5), T(32.0),
T(0), T(4.5), T(12.0), T(22.5), T(36.0)
), 5, 3));
table<T, _2D> r3 = nt2::zeros(3, 5, as_<T>());
table<T, _2D> v1 = cumtrapz(y, 1);
NT2_TEST_EQUAL(v1, r1);
table<T, _2D> v2 = cumtrapz(y, 2);
NT2_TEST_EQUAL(v2, r2);
table<T, _2D> v3 = cumtrapz(y, 3);
NT2_TEST_EQUAL(v3, r3);
}
示例10: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( oneplus_real__1_0, BOOST_SIMD_REAL_TYPES)
{
using nt2::oneplus;
using nt2::tag::oneplus_;
typedef typename boost::dispatch::meta::as_integer<T>::type iT;
typedef typename boost::dispatch::meta::call<oneplus_(T)>::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 typename boost::dispatch::meta::upgrade<T>::type u_t;
typedef typename boost::common_type<T>::type wished_r_t;
typedef typename std::complex<T> cT;
typedef typename nt2::meta::as_imaginary<T>::type ciT;
typedef typename nt2::meta::as_dry<T>::type dT;
// 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_EQUAL(oneplus(cT(nt2::Inf<T>(), nt2::Inf<T>() )) , cT(nt2::Inf<cT>(),nt2::Inf<T>()));
NT2_TEST_EQUAL(oneplus(cT(nt2::Minf<T>(),nt2::Minf<T>())) , cT(nt2::Minf<cT>(),nt2::Minf<T>()));
NT2_TEST_EQUAL(oneplus(cT(nt2::Mone<T>(),nt2::Mone<T>())) , cT(nt2::Zero<cT>(),nt2::Mone<T>()));
NT2_TEST_EQUAL(oneplus(cT(nt2::Nan<T>() ,nt2::Nan<T>() )) , cT(nt2::Nan<cT>(),nt2::Nan<T>()));
NT2_TEST_EQUAL(oneplus(cT(nt2::One<T>() ,nt2::One<T>() )) , cT(nt2::Two<cT>(),nt2::One<T>()));
NT2_TEST_EQUAL(oneplus(cT(nt2::Zero<T>(),nt2::Zero<T>())) , cT(nt2::One<cT>(),nt2::Zero<T>()));
NT2_TEST_EQUAL(oneplus(nt2::Inf<cT>()), nt2::Inf<cT>());
NT2_TEST_EQUAL(oneplus(nt2::Minf<cT>()), nt2::Minf<cT>());
NT2_TEST_EQUAL(oneplus(nt2::Mone<cT>()), nt2::Zero<cT>());
NT2_TEST_EQUAL(oneplus(nt2::Nan<cT>()), nt2::Nan<cT>());
NT2_TEST_EQUAL(oneplus(nt2::One<cT>()), nt2::Two<cT>());
NT2_TEST_EQUAL(oneplus(nt2::Zero<cT>()), nt2::One<cT>());
} // end of test for floating_
示例11: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL(norm, NT2_REAL_TYPES)
{
typedef typename nt2::meta::as_complex<T>::type cT;
using nt2::norm;
using nt2::tag::norm_;
nt2::table<cT> n = nt2::ones(10, 1, nt2::meta::as_<cT>());
NT2_TEST_ULP_EQUAL(norm(n, 1), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(n, 2), nt2::sqrt(nt2::Ten<T>()), 0);
NT2_TEST_ULP_EQUAL(norm(n) , nt2::sqrt(nt2::Ten<T>()), 0);
NT2_TEST_ULP_EQUAL(norm(n, 3), nt2::pow(nt2::Ten<T>(), 1/T(3)), 0);
NT2_TEST_ULP_EQUAL(norm(n, nt2::Inf<T>()), nt2::One<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(n, nt2::Minf<T>()), nt2::One<T>(), 0);
nt2::table<cT> a = nt2::ones(10, 10, nt2::meta::as_<cT>());
NT2_TEST_ULP_EQUAL(norm(a, 1), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a, 2), norm(a), 0);
NT2_TEST_ULP_EQUAL(norm(a, nt2::Inf<T>()), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a, 'I'), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a, '1'), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a, 'f'), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a, "fro"), nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, 1), 2*nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, 2), norm(a+a), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, nt2::Inf<T>()), 2*nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, 'I'), 2*nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, '1'), 2*nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, 'f'), 2*nt2::Ten<T>(), 0);
NT2_TEST_ULP_EQUAL(norm(a+a, "fro"), 2*nt2::Ten<T>(), 0);
}
示例12: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( round_real__1_0, NT2_REAL_TYPES)
{
using nt2::round;
using nt2::tag::round_;
typedef typename nt2::meta::call<round_(T)>::type r_t;
typedef T wished_r_t;
// return type conformity test
NT2_TEST_TYPE_IS( r_t, wished_r_t );
// specific values tests
NT2_TEST_ULP_EQUAL(round(T(1.4)), r_t(1), 0);
NT2_TEST_ULP_EQUAL(round(T(1.5)), r_t(2), 0);
NT2_TEST_ULP_EQUAL(round(T(1.6)), r_t(2), 0);
NT2_TEST_ULP_EQUAL(round(T(2.5)), r_t(3), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Half<T>()), nt2::One<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Inf<T>()), nt2::Inf<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Mhalf<T>()), nt2::Mone<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Minf<T>()), nt2::Minf<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Mone<T>()), nt2::Mone<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Nan<T>()), nt2::Nan<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::One<T>()), nt2::One<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Zero<T>()), nt2::Zero<r_t>(), 0);
} // end of test for floating_
示例13: NT2_TEST_CASE_TPL
#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) );
}
示例14: NT2_TEST_CASE_TPL
NT2_TEST_CASE_TPL ( round_real__1_0, NT2_REAL_TYPES)
{
using nt2::round;
using nt2::tag::round_;
typedef typename nt2::meta::as_integer<T>::type iT;
typedef typename nt2::meta::call<round_(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 T 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(round(T(1.4)), 1, 0);
NT2_TEST_ULP_EQUAL(round(T(1.5)), 2, 0);
NT2_TEST_ULP_EQUAL(round(T(1.6)), 2, 0);
NT2_TEST_ULP_EQUAL(round(T(2.5)), 2, 0);
NT2_TEST_ULP_EQUAL(round(nt2::Half<T>()), nt2::Zero<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Inf<T>()), nt2::Inf<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Mhalf<T>()), nt2::Zero<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Minf<T>()), nt2::Minf<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Mone<T>()), nt2::Mone<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Nan<T>()), nt2::Nan<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::One<T>()), nt2::One<r_t>(), 0);
NT2_TEST_ULP_EQUAL(round(nt2::Zero<T>()), nt2::Zero<r_t>(), 0);
} // end of test for floating_
示例15: NT2_TEST_CASE_TPL
#include <nt2/sdk/functor/meta/call.hpp>
#include <boost/type_traits/is_same.hpp>
#include <nt2/toolbox/arithmetic/include/rem.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 ( rem, (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::rem;
using nt2::functors::rem_;
NT2_TEST( (boost::is_same < typename nt2::meta::call<rem_(T, T)>::type
, typename boost::result_of<nt2::meta::arithmetic(T, T)>::type
>::value)
);
NT2_TEST_EQUAL( rem( T(4), T(3)), 1 );
NT2_TEST_EQUAL( rem( T(5), T(3)), 2);
NT2_TEST_EQUAL( rem( T(6), T(3)), 0 );
}