Ejemplo n.º 1
0
void
vector_add(
  const_Vector<T, Block1> res,
  const_Vector<T, Block2> op1,
  const_Vector<T, Block3> op2)
{
  vsip::dda::Data<Block1, vsip::dda::out> raw_res(res.block());
  float*   p_raw   = raw_res.ptr();
  stride_type str_raw = raw_res.stride(0);

  vsip::dda::Data<Block2, vsip::dda::in> raw1(op1.block());
  float const *p1   = raw1.ptr();
  stride_type str1 = raw1.stride(0);

  vsip::dda::Data<Block3, vsip::dda::in> raw2(op2.block());
  float const *p2   = raw2.ptr();
  stride_type str2 = raw2.stride(0);

  for (index_type i=0; i<res.size(); ++i)
  {
    *p_raw = *p1 + *p2;

    p1    += str1;
    p2    += str2;
    p_raw += str_raw;
  }
}
Ejemplo n.º 2
0
typename Promotion<T1, T2>::type
dotp_ext(
  const_Vector<T1, Block1> op1,
  const_Vector<T2, Block2> op2)
{
  typedef typename Promotion<T1, T2>::type value_type;

  test_assert(op1.size() == op2.size());

  vsip::dda::Data<Block1, dda::in> raw1(op1.block());
  T1 const *p1   = raw1.ptr();
  stride_type str1 = raw1.stride(0);

  vsip::dda::Data<Block2, dda::in> raw2(op2.block());
  T2 const *p2   = raw2.ptr();
  stride_type str2 = raw2.stride(0);

  value_type sum = value_type();
  
  for (index_type i=0; i<op1.size(); ++i)
  {
    sum  += *p1 * *p2;
    p1 += str1;
    p2 += str2;
  }

  return sum;
}
Ejemplo n.º 3
0
void
check_replicated_map(
  Replicated_map<Dim> const&          map,
  const_Vector<processor_type, Block> pset)
{
  typedef Replicated_map<Dim> map_type;
  typedef typename map_type::processor_iterator iterator;

  // Check num_processors()
  test_assert(map.num_processors() == pset.size());

  // Check processor_set()
  Vector<processor_type> map_pset = map.processor_set();

  test_assert(map_pset.size() == pset.size());
  for (index_type i=0; i<map_pset.size(); ++i)
    test_assert(map_pset(i) == pset(i));

  // Check processor_begin(), processor_end()
  iterator begin = map.processor_begin(0);
  iterator end   = map.processor_end(0);

  assert(static_cast<length_type>(end - begin) == pset.size());

  iterator cur = begin;
  while (cur != end)
  {
    index_type i = cur - begin;
    test_assert(*cur == pset(i));
    ++cur;
  }
}
Ejemplo n.º 4
0
double
error_db(const_Vector<T1, Block1> v1,
	 const_Vector<T2, Block2> v2)
{
  double refmax = 0.0;
  double maxsum = -250;
  double sum;

  Index<1> idx;

  refmax = maxval(magsq(v1), idx);

  for (index_type i=0; i<v1.size(); ++i)
  {
    double val = magsq(v1.get(i) - v2.get(i));

    if (val < 1.e-20)
      sum = -201.;
    else
      sum = 10.0 * log10(val/(2.0*refmax));

    if (sum > maxsum)
      maxsum = sum;
  }

  return maxsum;
}
Ejemplo n.º 5
0
void
check_length(const_Vector<T, Block> vec, length_type len)
{
  test_assert(vec.length() == len);
  test_assert(vec.size() == len);
  test_assert(vec.size(0) == len);
}
Ejemplo n.º 6
0
inline bool equal(const_Vector<T1, B1> v, const_Vector<T2, B2> w)
{
  if (v.size() != w.size()) return false;
  for (length_type i = 0; i != v.size(); ++i)
    if (!equal(v.get(i), w.get(i)))
      return false;
  return true;
}
Ejemplo n.º 7
0
bool
check_vector(const_Vector<T, Block> vec, int k)
{
  for (index_type i=0; i<vec.size(0); ++i)
    if (!equal(vec.get(i), T(k*i+1)))
      return false;
  return true;
}
Ejemplo n.º 8
0
T
sum_view(const_Vector<T, Block> view)
{
  T sum = T();
  for (index_type i=0; i<view.size(); ++i)
    sum += view.get(i);
  return sum;
}
Ejemplo n.º 9
0
T
tc_sum_const(const_Vector<T, Block> vec)
{
  T sumval = T();
  for (index_type i=0; i<vec.size(0); ++i)
    sumval += vec.get(i);
  return sumval;
}
Ejemplo n.º 10
0
  void operator()(
    char const *            str,
    const_Vector<T, Block1> vin,
    Vector      <T, Block2> vout)
  {
    typedef vsip::impl::Layout<1, row1_type,
      vsip::impl::Stride_unit, vsip::impl::Cmplx_split_fmt>
		LP;
    typedef vsip::impl::Ext_data<Block1, LP> layout1;
    typedef vsip::impl::Ext_data<Block2, LP> layout2;

    // PROFILE: Check sizes, check layout costs.

    // Important to check size.  If vectors are too large, our
    // buffers will overflow.
    test_assert(vin.size()  == size_);
    test_assert(vout.size() == size_);

    if (verbose_)
    {
      cout << "Test_FFT_split: " << str << endl;
      cout << "Block_layout<Block1>:\n";
      print_layout<typename vsip::impl::Block_layout<Block1>::layout_type>(cout);
      cout << endl;
      
      cout << "LP:\n";
      print_layout<LP>(cout);
      cout << endl;
      
      cout << "  access_type<LP>(vin.block()) = "
	   <<    access_type<LP>(vin.block()) << endl;
      cout << "  access_type<LP>(vout.block()) = "
	   <<    access_type<LP>(vout.block()) << endl;
      
      cout << "  mem_required<LP>(vin.block()) = "
	   <<    vsip::impl::mem_required<LP>(vin.block()) << endl;
      cout << "  mem_required<LP>(vout.block()) = "
	   <<    vsip::impl::mem_required<LP>(vout.block()) << endl;
    }

    test_assert(vsip::impl::mem_required<LP>(vin.block())  <= sizeof(T)*size_);
    test_assert(vsip::impl::mem_required<LP>(vout.block()) <= sizeof(T)*size_);

    layout1 rin (vin.block(),  vsip::impl::SYNC_IN,  
		 make_pair(buffer_ + 0, buffer_ + size_));
    layout2 rout(vout.block(), vsip::impl::SYNC_OUT,
		 make_pair(buffer_ + 2*size_, buffer_ + 3*size_));

    test_assert(rin.stride(0) == 1);
    test_assert(rin.size(0) == size_);

    test_assert(rout.stride(0) == 1);
    test_assert(rout.size(0) == size_);

    fft_unit_stride_split(rin.data().first,  rin.data().second,
			  rout.data().first, rout.data().second,
			  size_);
  }
Ejemplo n.º 11
0
T
sum(const_Vector<T, Block> v)
{
  // std::cout << "sum(" << Block_name<Block>::name() << ")\n";
  T total = T();
  for (index_type i=0; i<v.length(); ++i)
    total += v.get(i);
  return total;
}
Ejemplo n.º 12
0
inline
const_Vector<typename Promotion<T1, T2>::type,
	     expr::Binary<expr::op::Mult, Block1, Block2, true> const>
t_mul(const_Vector<T1, Block1> v1, const_Vector<T2, Block2> v2)
{
  typedef typename Promotion<T1, T2>::type RT;
  typedef expr::Binary<expr::op::Mult, Block1, Block2, true> block_t;

  return const_Vector<RT, const block_t>(block_t(v1.block(), v2.block()));
}
Ejemplo n.º 13
0
void
test_view(const_Vector<complex<T>, Block> vec, int k)
{
  for (index_type i=0; i<vec.size(0); ++i)
  {
    if (!equal(vec.get(i), complex<T>(T(k*i+1), T(k*i+2))))
    {
      cout << "ERROR: i        = " << i << endl
	   << "       Got      = " << vec.get(i) << endl
	   << "       expected = " << vec.get(i) << endl;
    }
    test_assert(equal(vec.get(i), complex<T>(T(k*i+1), T(k*i+2))));
  }
}
Ejemplo n.º 14
0
lazy_Vector<T, Unary<Scale, BlockType> const>
scale(const_Vector<T, BlockType> input, T value)
{
  Scale<BlockType> s(input.block(), value);
  Unary<Scale, BlockType> block(s);
  return lazy_Vector<T, Unary<Scale, BlockType> const>(block);
}
Ejemplo n.º 15
0
T
sum_ext(const_Vector<T, Block> view)
{
  vsip::dda::Data<Block, dda::in> raw(view.block());
  float const *data   = raw.ptr();
  stride_type stride = raw.stride(0);

  T sum = T();
  
  for (index_type i=0; i<view.size(); ++i)
  {
    sum  += *data;
    data += stride;
  }

  return sum;
}
Ejemplo n.º 16
0
const_Vector<T, Unary<Scale, BlockType> const>
scale(const_Vector<T, BlockType> input, T value)
{
  typedef Unary<Scale, BlockType> block_type;
  Scale<BlockType> s(input.block(), value);
  block_type block(s);
  return const_Vector<T, Unary<Scale, BlockType> const>(block);
}
Ejemplo n.º 17
0
  void 
  operator()(
    const_Vector<cscalar_f, Block1> in, 
    const_Vector<cscalar_f, Block2> coefficients,
    Vector<cscalar_f, Block3> out)
  {
    if((size() != in.size()) ||
       (size() != coefficients.size()) ||
       (size() != out.size()))
    {
      std::cout << "Error (class Filter): "
                << "all input and output views must be element-conformant" << std::endl;
      return;
    }

    out = i_fft_(coefficients * f_fft_(in));
  }
Ejemplo n.º 18
0
inline
const_Vector<T, expr::Unary<expr::op::Minus, Block, true> const>
t_neg(const_Vector<T, Block> v1)
{
  typedef expr::Unary<expr::op::Minus, Block, true> block_t;

  return const_Vector<T, const block_t>(block_t(v1.block()));
}
Ejemplo n.º 19
0
typename Promotion<T1, T2>::type
dotp_view(
  const_Vector<T1, Block1> op1,
  const_Vector<T2, Block2> op2)
{
  typedef typename Promotion<T1, T2>::type value_type;

  test_assert(op1.size() == op2.size());

  value_type sum = value_type();
  
  for (index_type i=0; i<op1.size(); ++i)
  {
    sum  += op1.get(i) * op2.get(i);
  }

  return sum;
}
Ejemplo n.º 20
0
void 
scaled_interpolate(Vector<T, ResultBlockType> result,
                   const_Vector<T, ArgumentBlockType> argument,
                   T scale, length_type new_size)
{
  length_type old_size = argument.size();
  float stretch = static_cast<float>(new_size)/old_size;
  for (index_type i = 0; i != new_size; ++i)
  {
    float pos = i / stretch;
    index_type j = static_cast<index_type>(pos);
    float alpha = pos - j;
    if (j + 1 == old_size)
      result.put(i, scale * (argument.get(j) * alpha));
    else
      result.put(i, scale * (argument.get(j) * alpha + argument.get(j + 1) * (1 - alpha)));
  }
}
Ejemplo n.º 21
0
  Vector<T>
  operator()(const_Vector<scalar_f> time, scalar_f start = 0.0)
  {
    length_type N = time.size();
    Vector<T> out(N, T());

    for (index_type i = 0; i < N; ++i)
      out(i) = (time(i) < (duration_ + start) && time(i) >= start) ? T(amplitude_) : T();

    return out;
  }
Ejemplo n.º 22
0
 void 
 operator()(
   const_Vector<cscalar_f, Block1> in, 
   const_Vector<cscalar_f, Block2> coefficients,
   Vector<cscalar_f, Block3> out)
 {
   if (filter_.get() == 0)
   {
     std::cout << "Error (class Dynamic_filter): "
               << "reconfigure() not called prior to processing input data" << std::endl;
   }
   else if((filter_->size() != in.size()) ||
      (filter_->size() != coefficients.size()) ||
      (filter_->size() != out.size()))
   {
     std::cout << "Error (class Dynamic_filter): "
               << "all input and output views must be element-conformant" << std::endl;
   }
   else
     (*filter_)(in, coefficients, out);
 }
Ejemplo n.º 23
0
void
generic_prod(
  const_Vector<T0, Block0> a,
  const_Matrix<T1, Block1> b,
  Vector<T2, Block2>       r)
{
  using namespace vsip_csl::dispatcher;

  assert(r.size() == b.size(1));
  assert(a.size() == b.size(0));

#ifdef VSIP_IMPL_REF_IMPL
  Evaluator<op::prod_vm, dispatcher::be::cvsip,
    void(Block2&, Block0 const&, Block1 const&)>::exec
    (r.block(), a.block(), b.block());
#else
  vsip_csl::dispatch<op::prod_vm, void,
    Block2&, Block0 const&, Block1 const&>
    (r.block(), a.block(), b.block());
#endif
}
Ejemplo n.º 24
0
  Vector<T>
  operator()(const_Vector<scalar_f> time, scalar_f start = 0.0)
  {
    length_type N = time.size();
    Vector<T> out(N, T());
    Vector<T> phase(N, T());

    phase.imag() = -2.f * OVXX_PI * frequency_rate_ * (time - start) * (time - start);
    out = exp(phase);

    return out;
  }
Ejemplo n.º 25
0
  // Overload operator() to allow the use of a weighting function
  Vector<scalar_f>
  operator()(const_Vector<scalar_f> time,
             const_Vector<scalar_f> weights,
             scalar_f start = 0.0)
  {
    length_type N = time.size();
    Vector<cscalar_f> out(N, cscalar_f());
    Vector<cscalar_f> phase(N, cscalar_f());

    phase.imag() = -2.f * OVXX_PI * frequency_rate_ * (time - start) * (time - start);
    out = weights * exp(phase);

    return out.real();
  }
Ejemplo n.º 26
0
void
test_conv(
  length_type              N,		// input size
  length_type              D,		// decimation
  const_Vector<T1, Block1> coeff,	// coefficients
  length_type const        n_loop = 2)
{
  length_type M = expected_kernel_size(symmetry, coeff.size());
  length_type P = expected_output_size(support, M, N, D);

  Vector<T> in(N);
  Vector<T> out(P, T(100));

  test_conv_base<symmetry, support>(in, out, coeff, D, n_loop);
}
Ejemplo n.º 27
0
  void
  operator()(const_Vector<T, Block1> in, Vector<T, Block2> out)
  {
    typedef impl::Layout<1, row1_type, impl::Stride_unit, impl::Cmplx_inter_fmt> layout_t;

    impl::Ext_data<Block1, layout_t> in_ext (in.block(), impl::SYNC_IN);
    impl::Ext_data<Block2, layout_t> out_ext(out.block(), impl::SYNC_OUT);

    assert(in_ext.stride(0) == 1);
    assert(out_ext.stride(0) == 1);

    if (Dir == -1)
      IppFFT<T>::forward(fft_, in_ext.data(), out_ext.data(), buffer_);
    else
      IppFFT<T>::inverse(fft_, in_ext.data(), out_ext.data(), buffer_);
  }
Ejemplo n.º 28
0
  void out_of_place(BE *backend,
		    const_Vector<InT, Block0>& in,
		    Vector<OutT, Block1>& out)
  {
    {
      dda::Data<Block0, dda::in> in_data(in.block());
      dda::Data<Block1, dda::out> out_data(out.block());

      backend->out_of_place(in_data.ptr(),  in_data.stride(0),
			    out_data.ptr(), out_data.stride(0),
			    select_fft_size<InT, OutT>(in_data.size(0), out_data.size(0)));
    }

    // Scale the data if not already done by the backend.
    if (!backend->supports_scale() && !almost_equal(scale_, scalar_type(1.)))
      out *= scale_;
  }
Ejemplo n.º 29
0
  void by_reference(BE *backend,
		    const_Vector<InT, Block0>& in,
		    Vector<OutT, Block1>& out)
  {
    {
      Ext_data<Block0> in_ext (in.block(),  SYNC_IN);
      Ext_data<Block1> out_ext(out.block(), SYNC_OUT);

      backend->by_reference(
		in_ext.data(),  in_ext.stride(0),
		out_ext.data(), out_ext.stride(0),
		select_fft_size<InT, OutT>(in_ext.size(0), out_ext.size(0)));
    }

    // Scale the data if not already done by the backend.
    if (!backend->supports_scale() && !almost_equal(scale_, scalar_type(1.)))
      out *= scale_;
  }
Ejemplo n.º 30
0
void
test_conv_base(
  Vector<T, Block1>        in,
  Vector<T, Block2>        out,
  const_Vector<T, Block3>  coeff,	// coefficients
  length_type              D,		// decimation
  length_type const        n_loop = 2)
{
  using vsip::impl::ITE_Type;
  using vsip::impl::Is_global_map;
  using vsip::impl::As_type;

  typedef Convolution<const_Vector, symmetry, support, T> conv_type;

  length_type M = expected_kernel_size(symmetry, coeff.size());
  length_type N = in.size();
  length_type P = out.size();

  length_type expected_P = expected_output_size(support, M, N, D);

  test_assert(P == expected_P);

  conv_type conv(coeff, Domain<1>(N), D);

  test_assert(conv.symmetry() == symmetry);
  test_assert(conv.support()  == support);

  test_assert(conv.kernel_size().size()  == M);
  test_assert(conv.filter_order().size() == M);
  test_assert(conv.input_size().size()   == N);
  test_assert(conv.output_size().size()  == P);

  // Determine type of map to use for expected result.
  // If 'out's map is global, make it global_map.
  // Otherwise, make it a local_map.
  typedef typename
          ITE_Type<Is_global_map<typename Block2::map_type>::value,
                   As_type<Global_map<1> >,
                   As_type<Local_map> >::type
          map_type;
  typedef Dense<1, T, row1_type, map_type> block_type;

  Vector<T, block_type> exp(P);

  for (index_type loop=0; loop<n_loop; ++loop)
  {
    for (index_type i=0; i<N; ++i)
      in(i) = T(3*loop+i);

    conv(in, out);

    ref::conv(symmetry, support, coeff, in, exp, D);

    // Check result
    Index<1> idx;
    double error   = error_db(out, exp);
    double maxdiff = maxval(magsq(out - exp), idx);

#if VERBOSE
    std::cout << "error: " << error
	      << "  M/N/P " << M << "/" << N << "/" << P
	      << (symmetry == vsip::sym_even_len_odd  ? " odd"  :
	          symmetry == vsip::sym_even_len_even ? " even" :
	          symmetry == vsip::nonsym            ? " nonsym" :
		                                        " *unknown*" )
	      << (support == vsip::support_full  ? " full"  :
	          support == vsip::support_same  ? " same"  :
	          support == vsip::support_min   ? " min"   :
		                                   " *unknown*" )
	      << std::endl;

    if (error > ERROR_THRESH)
    {
      cout << "exp = \n" << exp;
      cout << "out = \n" << out;
      cout << "diff = \n" << mag(exp-out);
    }
#endif

    test_assert(error < ERROR_THRESH || maxdiff < 1e-4);
  }
}