Skip to content

Instantly share code, notes, and snippets.

Created May 31, 2013 14:20
Show Gist options
  • Select an option

  • Save anonymous/5685297 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/5685297 to your computer and use it in GitHub Desktop.
//==============================================================================
// Copyright 2003 - 2012 LASMEA UMR 6602 CNRS/Univ. Clermont II
// Copyright 2009 - 2012 LRI UMR 8623 CNRS/Univ Paris Sud XI
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#define NT2_UNIT_MODULE "nt2 arithmetic toolbox - abs/simd Mode"
//////////////////////////////////////////////////////////////////////////////
// cover test behavior of arithmetic components in simd mode
//////////////////////////////////////////////////////////////////////////////
/// created by jt the 30/11/2010
///
#include <nt2/arithmetic/include/functions/abs.hpp>
#include <vector>
#include <nt2/include/constants/valmin.hpp>
#include <nt2/include/constants/valmax.hpp>
#include <nt2/sdk/unit/tests.hpp>
#include <nt2/sdk/unit/tests/ulp.hpp>
#include <nt2/sdk/unit/module.hpp>
#include <boost/simd/sdk/simd/native.hpp>
#include <nt2/sdk/meta/cardinal_of.hpp>
#include <nt2/include/functions/load.hpp>
#include <nt2/include/functions/store.hpp>
#include <boost/simd/sdk/simd/io.hpp>
NT2_TEST_CASE_TPL ( abs_real__1_0, NT2_SIMD_TYPES)
{
using nt2::abs;
using nt2::tag::abs_;
using boost::simd::native;
typedef NT2_SIMD_DEFAULT_EXTENSION ext_t;
typedef native<T,ext_t> nT;
typedef typename nt2::meta::call<abs_(T)>::type sr_t;
typedef typename nt2::meta::call<abs_(nT)>::type r_t;
// random verifications
nt2::uint32_t K = nt2::meta::cardinal_of<nT>::value;
nt2::uint32_t NR = NT2_NB_RANDOM_TEST;
nt2::uint32_t NRE = NR*K;
std::vector<T> in(NRE);
nt2::roll(in, nt2::Valmin<T>()/2, nt2::Valmax<T>()/2);
std::vector<r_t> out(NR), ref(NR);
std::vector<sr_t> sref(NRE);
for(nt2::uint32_t i=0; i < NRE ; ++i)
{
sref[i] = abs(in[i]);
}
for(nt2::uint32_t i=0; i < NR ; ++i)
{
ref[i] = nt2::load<nT>(&sref[K*i]);
out[i] = abs( nt2::load<nT>(&in[K*i]));
}
NT2_TEST_ULP_EQUAL(out, ref, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment