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;
  }
}
Example #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;
}
Example #3
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);
}
Example #4
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;
}
Example #5
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;
}
Example #6
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;
  }
}
Example #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;
}
Example #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;
}
Example #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;
}
Example #10
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));
  }
  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_);
  }
Example #12
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;
}
Example #13
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;
  }
Example #14
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);
 }
Example #15
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;
  }
Example #16
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();
  }
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))));
  }
}
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);
}
Example #19
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;
}
Example #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)));
  }
}
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
}
Example #22
0
void
test_vector(const_Vector<T, Block> vec, int k)
{
  for (index_type i=0; i<vec.size(0); ++i)
    test_assert(equal(vec.get(i), T(k*i+1)));
}
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);
  }
}