Exemplo n.º 1
0
void
test_vadd(
  length_type len,
  length_type offset1,
  length_type offset2,
  length_type offset3)
{
  Rand<T> gen(0, 0);

  Vector<T> big_A(len + offset1);
  Vector<T> big_B(len + offset2);
  Vector<T> big_Z(len + offset3);

  typename Vector<T>::subview_type A = big_A(Domain<1>(offset1, 1, len));
  typename Vector<T>::subview_type B = big_B(Domain<1>(offset2, 1, len));
  typename Vector<T>::subview_type Z = big_Z(Domain<1>(offset3, 1, len));

  A = gen.randu(len);
  B = gen.randu(len);

  Z = A + B;

  for (index_type i=0; i<len; ++i)
  {
    test_assert(equal(Z.get(i), A.get(i) + B.get(i)));
  }
}
Exemplo n.º 2
0
void
test_vma_cSC(
  length_type len,
  length_type offset1,
  length_type offset2,
  length_type offset3)
{
  typedef typename scalar_of<T>::type ST;

  Rand<ST> rgen(0, 0);
  Rand<T>  cgen(0, 0);

  Vector<ST> big_B(len + offset1);
  Vector<T>  big_C(len + offset2);
  Vector<T>  big_Z(len + offset3);

  T a = 2.0;
  typename Vector<ST>::subview_type B = big_B(Domain<1>(offset1, 1, len));
  typename Vector<T>::subview_type  C = big_C(Domain<1>(offset2, 1, len));
  typename Vector<T>::subview_type  Z = big_Z(Domain<1>(offset3, 1, len));

  B = rgen.randu(len);
  C = cgen.randu(len);

  Z = a * B + C;

  for (index_type i=0; i<len; ++i)
  {
    test_assert(equal(Z.get(i), a * B.get(i) + C.get(i)));
  }
}
Exemplo n.º 3
0
void
test_vthresh(
  length_type len,
  length_type offset1,
  length_type offset2,
  length_type offset3)
{
  Rand<T> gen(0, 0);

  Vector<T> big_A(len + offset1);
  Vector<T> big_B(len + offset2);
  Vector<T> big_Z(len + offset3);

  typename Vector<T>::subview_type A = big_A(Domain<1>(offset1, 1, len));
  typename Vector<T>::subview_type B = big_B(Domain<1>(offset2, 1, len));
  typename Vector<T>::subview_type Z = big_Z(Domain<1>(offset3, 1, len));
  T                                k = 0.5;

  A = gen.randu(len);
  B = gen.randu(len);

  Z = ite(A > B, A, k);

  for (index_type i=0; i<len; ++i)
  {
    test_assert(equal(Z.get(i), A.get(i) > B.get(i) ? A.get(i) : k));
  }
}
Exemplo n.º 4
0
void
tc_subview(Domain<1> const& dom, Domain<1> const& sub)
{
  Vector<T> view(dom[0].length());

  fill_vector(view, 2);

  typename Vector<T>::subview_type        subv = view(sub);
  typename Vector<T>::const_subview_type csubv = view.get(sub);

  for (index_type i=0; i<sub.length(); ++i)
  {
    index_type parent_i = sub.impl_nth(i);

    test_assert(view.get(parent_i) ==  subv.get(i));
    test_assert(view.get(parent_i) == csubv.get(i));

    view.put(parent_i, view.get(parent_i) + T(1));

    test_assert(view.get(parent_i) ==  subv.get(i));
    test_assert(view.get(parent_i) == csubv.get(i));

    subv.put(i, subv.get(i) + T(1));

    test_assert(view.get(parent_i) ==  subv.get(i));
    test_assert(view.get(parent_i) == csubv.get(i));
  }
}
Exemplo n.º 5
0
void
test_vmul(
  length_type len,
  length_type offset1,
  length_type offset2,
  length_type offset3)
{
  Rand<T> gen(0, 0);

  Vector<T> big_A(len + offset1);
  Vector<T> big_B(len + offset2);
  Vector<T> big_Z(len + offset3);

  typename Vector<T>::subview_type A = big_A(Domain<1>(offset1, 1, len));
  typename Vector<T>::subview_type B = big_B(Domain<1>(offset2, 1, len));
  typename Vector<T>::subview_type Z = big_Z(Domain<1>(offset3, 1, len));

  A = gen.randu(len);
  B = gen.randu(len);

  Z = A * B;

  for (index_type i=0; i<len; ++i)
  {
#if VERBOSE
    if (!equal(Z.get(i), A.get(i) * B.get(i)))
    {
      std::cout << "Z(" << i << ")        = " << Z(i) << std::endl;
      std::cout << "A(" << i << ") * B(" << i << ") = "
		<< A(i) * B(i) << std::endl;
    }
#endif
    test_assert(equal(Z.get(i), A.get(i) * B.get(i)));
  }
}