예제 #1
0
void
test_vmul(length_type size)
{
  typedef impl::Layout<1, row1_type, impl::Stride_unit_dense, ComplexFmt>
		LP;
  typedef impl::Fast_block<1, T, LP> block_type;

  Vector<T, block_type> A(size, T(3));
  Vector<T, block_type> B(size, T(4));
  Vector<T, block_type> Z(size);

  Rand<T> gen(0, 0);
  A = gen.randu(size);
  B = gen.randu(size);

  Z = A * B;
  for (index_type i=0; i<size; ++i)
  {
    // Note: almost_equal is necessary for Cbe since SPE and PPE will not
    //       compute idential results.
#if VERBOSE
    if (!almost_equal(Z(i), A(i) * B(i)))
    {
      std::cout << "Z(i)        = " << Z(i) << std::endl;
      std::cout << "A(i) * B(i) = " << A(i) * B(i) << std::endl;
    }
#endif
    test_assert(almost_equal(Z.get(i), A(i) * B(i)));
  }
}
예제 #2
0
void
test_ukernel(length_type size)
{
  Id1 cuk;

  Ukernel<Id1> uk(cuk);

  Vector<T> in(size);
  Vector<T> out(size);

  in = ramp<T>(0, 0.1, size);

  uk(in, out);

  for (index_type i=0; i<size; ++i)
  {
    if (!equal(out.get(i), in.get(i) + T(i)))
    {
      std::cout << i << ": " << out.get(i) << " != "
		<< in.get(i) << " + " << T(i)
		<< std::endl;
    }
    test_assert(equal(out.get(i), in.get(i) + T(i)));
  }
}
예제 #3
0
void
test_view_cast(length_type size)
{
  Vector<T1> src(size);
  Vector<T2> dst(size);

  Rand<T1> rand(0);

  src = T1(100) * rand.randu(size);

  dst = vsip_csl::view_cast<T2>(src);

  for (index_type i=0; i<size; ++i)
    test_assert(equal(dst.get(i),
		      static_cast<T2>(src.get(i))));

  src = ramp(T1(0), T1(1), size);

  dst = vsip_csl::view_cast<T2>(src);

  T1 src_sum = expect_vector<T1>(src);
  T2 dst_sum = expect_vector<T2>(vsip_csl::view_cast<T2>(src));

  for (index_type i=0; i<size; ++i)
    test_assert(equal(dst.get(i),
		      static_cast<T2>(src.get(i))));

  test_assert(equal(dst_sum, static_cast<T2>(src_sum)));
}
예제 #4
0
void
test_funcall()
{
  length_type const len = 10;
  Vector<T> v1(len, T());
  Vector<T> v2(len, T());
  Vector<T> v3(len, T());

  v1.put(1, T(1));
  v2.put(1, T(2));
  v3.put(1, T(3));

  T s1 = sum(v1);

  T s2 = sum(t_add(v1, v2));

  const_Vector<T, expr::Binary<expr::op::Add, Dense<1, T>, Dense<1, T>, true> const> vx(t_add(v1, v2));
  T s3 = sum(vx);

  T s4 = sum(t_add(t_mul(v2, v3), t_neg(t_add(v1, v3))));

#if ILLEGALCASE == 1
  // It should not be possible to pass an expression template (which is
  // a const_Vector) to a function expecting a Vector.
  T s5 = vector_sum(t_add(t_mul(v2, v3), t_neg(t_add(v1, v3))));
#endif

  test_assert(equal(s1, T(1)));
  test_assert(equal(s2, T(3)));
  test_assert(equal(s3, T(3)));
  test_assert(equal(s4, T(2)));
}
예제 #5
0
void
test_expr()
{
  length_type const len = 10;
  Vector<T> v1(len, T());
  Vector<T> v2(len, T());
  Vector<T> v3(len, T());

  Vector<T> z1(len);

  v1.put(1, T(1));
  v2.put(1, T(2));
  v3.put(1, T(3));

  z1           = t_add(v1, t_add(v2, v3));
  Vector<T> z2 = t_add(t_neg(v1), t_add(v2, v3));
  Vector<T> z3 = t_add(v1, t_neg(t_add(v2, v3)));
  Vector<T> z4 = t_add(t_mul(v2, v3), t_neg(t_add(v1, v3)));

  Vector<T> z5(len);
  z5           = t_mul(v2, v3);

  test_assert(equal(z1.get(1), T(6)));
  test_assert(equal(z2.get(1), T(4)));
  test_assert(equal(z3.get(1), T(-4)));
  test_assert(equal(z4.get(1), T(2)));

}
void
test_transpose_readonly(MatrixT view)
{
  typedef typename MatrixT::value_type T;

  // Check that view is initialized
  check_matrix(view, 0);

  length_type const size1 = view.size(1);

  typename MatrixT::const_transpose_type trans = view.transpose();

  test_assert(trans.size(0) == view.size(1));
  test_assert(trans.size(1) == view.size(0));

  for (index_type idx0=0; idx0<trans.size(0); ++idx0)
    for (index_type idx1=0; idx1<trans.size(1); ++idx1)
    {
      T expected = T(idx1 * size1 + idx0 + 0);
      test_assert(equal(trans.get(idx0, idx1), expected));
      test_assert(equal(trans.get(idx0,  idx1),
		   view. get(idx1, idx0)));
      }

  // Check that view is unchanged
  check_matrix(view, 0);
}
예제 #7
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))));
  }
}
예제 #8
0
  void operator()(length_type size, length_type loop, float& time)
  {
    Vector<T>   A(size, T());
    Vector<T>   Z(size);

#if 0
    // int const no_times = 0; // FFTW_PATIENT
    int const no_times = 15; // not > 12 = FFT_MEASURE

    typedef Fft<const_Vector, T, T, fft_fwd, by_reference, no_times, alg_time>
      fft_type;
#else
    typedef ErsatzFFT<-1, T> fft_type;
#endif

    fft_type fft(Domain<1>(size), 1.f);

    A = T(1);
    
    vsip::impl::profile::Timer t1;
    
    t1.start();
    for (index_type l=0; l<loop; ++l)
      fft(A, Z);
    t1.stop();
    
    if (!equal(Z(0), T(size)))
    {
      std::cout << "t_fft: ERROR" << std::endl;
      abort();
    }
    
    time = t1.delta();
  }
예제 #9
0
void
test_fftm_op_align(
  length_type rows,
  length_type size,
  length_type gap,
  length_type align)
{
#if VERBOSE
  std::cout << "fftm_op_align(" << rows << " x " << size
	    << ", gap " << gap
	    << ", align " << align << ")\n";
#endif

  typedef impl::Stride_unit_dense sud_type;
  typedef impl::Layout<2, row2_type, sud_type, ComplexFmt> lp_type;

  typedef impl::Fast_block<2, T, lp_type> block_type;

  typedef Fftm<T, T, row, fft_fwd, by_reference, 1, alg_space> fftm_type;

  fftm_type fftm(Domain<2>(rows, size), 1.f);

  Matrix<T, block_type> in (rows, size + gap);
  Matrix<T, block_type> out(rows, size + gap);

  for (index_type i=0; i<rows; ++i)
    in.row(i) = T(i+1);

  fftm(in (Domain<2>(rows, Domain<1>(align, 1, size))),
       out(Domain<2>(rows, Domain<1>(align, 1, size))));

  for (index_type i=0; i<rows; ++i)
  {
    T got = out.get(i, align);
#if VERBOSE
    if (!equal(got, T((i+1)*size)))
    {
      std::cout << "Error: row " << i << std::endl
		<< "     : expected " << T((i+1)*size) << std::endl
		<< "     : got      " << got << std::endl
		<< "     : got      " << out.get(i, align) << std::endl
	;
    }
#endif
    test_assert(equal(got, T((i+1)*size)));
  }
}
예제 #10
0
bool
check_interleaved_array(
  T*                 data,
  Domain<Dim> const& dom,
  Func               fun)
{
  Length<Dim> ext = impl::extent(dom);
  for (Index<Dim> idx; valid(ext,idx); next(ext, idx))
  {
    index_type i = to_index<Order>(ext, idx);
    complex<T> val = fun(i);
    if (!equal(data[2*i+0], val.real()) ||
	!equal(data[2*i+1], val.imag()))
      return false;
  }
  return true;
}
예제 #11
0
파일: extdata.cpp 프로젝트: bambang/vsipl
void
test_1_low()
{
  length_type const size = 10;

  typedef typename Block::value_type value_type;

  Block block(size, 0.0);

  value_type val0 =  1.0f;
  value_type val1 =  2.78f;
  value_type val2 =  3.14f;
  value_type val3 = -1.5f;

  // Place values in block.
  block.put(0, val0);
  block.put(1, val1);

  {
    vsip::dda::impl::Accessor<Block,
      typename Block::layout_type,
      AccessTag>
      raw(block);

    // Check properties of LLDI.
    test_assert(raw.stride(&block, 0) == 1);
    test_assert(raw.size(&block, 0) == size);

    float* data = raw.ptr(&block);
    raw.begin(&block, true);

    // Check that block values are reflected.
    test_assert(equal(data[0], val0));
    test_assert(equal(data[1], val1));

    // Place values in raw data.
    data[1] = val2;
    data[2] = val3;

    raw.end(&block, true);
  }

  // Check that raw data values are reflected.
  test_assert(equal(block.get(1), val2));
  test_assert(equal(block.get(2), val3));
}
예제 #12
0
파일: extdata.cpp 프로젝트: bambang/vsipl
void
test_block_sum()
{
  length_type const size = 10;

  Dense<1, float> block(size,   0.f);
  impl::Strided<1, float> pb(size, 0.f);

  block.put(0, 1.f);
  block.put(1, 3.14f);
  block.put(2, 2.78f);

  pb.put(0, 1.f);
  pb.put(1, 3.14f);
  pb.put(2, 2.78f);

  float sum = 1.f + 3.14f + 2.78f;

  test_assert(equal(sum, raw_sum(block)));
  test_assert(equal(sum, ext_sum(block)));
  test_assert(equal(sum, blk_sum(block)));

  test_assert(equal(sum, gen_ext_sum(block)));
  test_assert(equal(sum, gen_blk_sum(block)));
  test_assert(equal(sum, gen_ext_sum(pb)));
  test_assert(equal(sum, gen_blk_sum(pb)));
}
예제 #13
0
bool
check_split_array(
  T*                 real,
  T*                 imag,
  Domain<Dim> const& dom,
  Func               fun)
{
  Length<Dim> ext = impl::extent(dom);
  for (Index<Dim> idx; valid(ext,idx); next(ext, idx))
  {
    index_type i = to_index<Order>(ext, idx);
    complex<T> val = fun(i);
    if (!equal(real[i], val.real()) ||
	!equal(imag[i], val.imag()))
      return false;
  }
  return true;
}
예제 #14
0
  void exec(length_type rows, length_type cols, length_type loop, float& time)
  {
    Matrix<T1, src_block_t>   A(rows, cols);
    Matrix<T2, dst_block_t>   Z(rows, cols, T2());
    for (index_type i = 0; i < rows; ++i)
      for (index_type j = 0; j < cols; ++j)
        A.put(i, j, T1(i * cols + j, -0.5));

    // Scoping is used to control the lifetime of Ext_data<> objects.  These 
    // must be destroyed before accessing data through the view again.
    {     
      impl::cuda::Device_memory<src_block_t const> dev_a(A.block());
      impl::cuda::Device_memory<dst_block_t> dev_z(Z.block());
      T1 const* pA = dev_a.data();
      T2* pZ = dev_z.data();

      // Benchmark the operation
      vsip::impl::profile::Timer t1;
      t1.start();
      for (index_type l = 0; l < loop; ++l)
      {
        this->functor_(pA, pZ, rows, cols);
        cudaThreadSynchronize();
      }
      t1.stop();
      time = t1.delta();
    }

    // validate results
    for (index_type i = 0; i < rows; ++i)
      for (index_type j = 0; j < cols; ++j)
      {
#if DEBUG
        if (!equal(F::apply(A.get(i, j)), Z.get(i, j)))
        {
          cout << "ERROR: at location " << i << ", " << j << endl
                    << "       expected: " << F::apply(A.get(i, j)) << endl
                    << "       got     : " << Z.get(i, j) << endl;
        }
#endif
        test_assert(equal(F::apply(A.get(i, j)), Z.get(i, j)));
      }
  }
예제 #15
0
void
test_real_subview_vector_freqswap( length_type m )
{
  Vector<complex<T> > a(m);

  a.real() = ramp<T>(0, 1, m);
  a.imag() = T(0);

  Vector<T> b(m);
  Vector<complex<T> > c(m, T());
  b = vsip::freqswap(a.real());
  c.real() = a.real(); c.real() = vsip::freqswap(c.real());

  for ( index_type i = 0; i < m; i++ )
  {
    test_assert(equal( b.get(i), a.real().get(((m+1)/2 + i) % m ) ));
    test_assert(equal( c.real().get(i), a.real().get(((m+1)/2 + i) % m ) ));
  }
}
예제 #16
0
void
test_vector_freqswap( length_type m )
{
  Vector<T> a(m);

  Rand<T> rgen(0);
  a = rgen.randu(m);

  Vector<T> b(m);
  Vector<T> c(m);
  b = vsip::freqswap(a);
  c = a; c = vsip::freqswap(c);

  for ( index_type i = 0; i < m; i++ )
  {
    test_assert(equal( b.get(i), a.get(((m+1)/2 + i) % m ) ));
    test_assert(equal( c.get(i), a.get(((m+1)/2 + i) % m ) ));
  }
}
예제 #17
0
  void operator()(length_type size, length_type loop, float& time)
  {
    using namespace vsip::impl;

    typedef Dense<1,T,row1_type,MapT> block_type;
    typedef reduction_op_eval<Max_value,T,block_type,1,Tag> eval;

    create_test_vector_helper<MapT,Vector,float,Dense<1,T,row1_type,MapT> >
      ctvh(size);

    T                      val = T();
    Index<1>               idx;

    Rand<T>     gen(0, 0);

    if (init_ == 0)
      ctvh.assign_view(gen.randu(size));
    else if (init_ == 1)
      ctvh.assign_view(ramp(T(0), T(1), size));
    else if (init_ == 2)
      ctvh.assign_view(ramp(T(size-1), T(-1), size));
   
    vsip::impl::profile::Timer t1;
    
    t1.start();
    for (index_type l=0; l<loop; ++l)
      eval::exec(val, ctvh.view.block(), idx);
    t1.stop();

    if (init_ == 1)
    {
      test_assert(equal(val, T(size-1)));
      test_assert(idx == size-1);
    }
    else if (init_ == 2)
    {
      test_assert(equal(val, T(size-1)));
      test_assert(idx == 0);
    }
    
    time = t1.delta();
  }
예제 #18
0
void
test_cvjdot_rand(length_type m)
{
  typedef typename Promotion<T0, T1>::type return_type;
  typedef typename vsip::impl::Scalar_of<return_type>::type scalar_type;

  Vector<T0> a(m);
  Vector<T1> b(m);

  randv(a);
  randv(b);

  // Test vector-vector prod
  return_type val  = cvjdot(a, b);
  return_type chk1 = dot(a, conj(b));
  return_type chk2 = ref::dot(a, conj(b));

  test_assert(equal(val, chk1));
  test_assert(equal(val, chk2));
}
예제 #19
0
void
test_ukernel(length_type rows, length_type cols)
{
  Madd_kernel obj;

  vsip_csl::ukernel::Ukernel<Madd_kernel> madd_uk(obj);

  Matrix<T1> in0(rows, cols);
  Matrix<T2> in1(rows, cols);
  Matrix<T2> in2(rows, cols);
  Matrix<T2> out(rows, cols);

  Rand<T1> gen1(0, 0);
  in0 = gen1.randu(rows, cols);

  Rand<T2> gen2(1, 0);
  in1 = gen2.randu(rows, cols);
  in2 = gen2.randu(rows, cols);

  madd_uk(in0, in1, in2, out);


  for (index_type i=0; i < rows; ++i)
    for (index_type j=0; j < cols; ++j)
    {
      T2 madd = in0.get(i, j) * in1.get(i, j) + in2.get(i, j);
      if (!equal(madd, out.get(i, j)))
      {
        std::cout << "index " << i << ", " << j << " : "
                  << in0.get(i, j) << " * "
                  << in1.get(i, j) << " + "
                  << in2.get(i, j) << " = "
                  << in0.get(i, j) * in1.get(i, j) + in2.get(i, j) << "  vs  "
                  << out.get(i, j)
                  << std::endl;
      }
      test_assert(equal(
          in0.get(i, j) * in1.get(i, j) + in2.get(i, j), 
          out.get(i, j)));
    }
}
예제 #20
0
파일: extdata.cpp 프로젝트: bambang/vsipl
void
test_view_functions()
{
  length_type size = 10;
  Vector<float> view1(size);
  Vector<float> view2(size);
  
  for (index_type i=0; i<size; ++i)
  {
    view1.put(i, float(i+1));
    view2.put(i, float(2*i+1));
  }

  test_assert(equal(sum_view(view1), sum_ext(view1)));
  test_assert(equal(sum_view(view2), sum_ext(view2)));

  float prod_v = dotp_view(view1, view2);
  float prod_e  = dotp_ext(view1, view2);

  test_assert(equal(prod_v, prod_e));
}
예제 #21
0
void
test_mag()
{
  Storage<Dim, T1> Z;
  Storage<Dim, T2> A;

  put_nth(A.view, 0, T2(-3));

  Z.view = vsip::mag(A.view);

  test_assert(equal(get_nth(Z.view, 0), T1(3)));
}
예제 #22
0
void
check_block(Block& blk, int k)
{
  typedef typename Block::value_type value_type;

  Length<Dim> ex = extent<Dim>(blk);
  for (Index<Dim> idx; valid(ex,idx); next(ex, idx))
  {
    test_assert(equal( get(blk, idx),
		  identity<value_type>(ex, idx, k)));
  }
}
예제 #23
0
파일: extdata.cpp 프로젝트: bambang/vsipl
void
test_1_ext()
{
  length_type const size = 10;

  typedef typename Block::value_type value_type;

  Block block(size, 0.0);

  value_type val0 =  1.0f;
  value_type val1 =  2.78f;
  value_type val2 =  3.14f;
  value_type val3 = -1.5f;

  // Place values in block.
  block.put(0, val0);
  block.put(1, val1);

  {
    vsip::dda::Data<Block, dda::inout> raw(block);

    // Check properties of DDI.
    test_assert(raw.stride(0) == 1);
    test_assert(raw.size(0) == size);

    float* data = raw.ptr();

    // Check that block values are reflected.
    test_assert(equal(data[0], val0));
    test_assert(equal(data[1], val1));

    // Place values in raw data.
    data[1] = val2;
    data[2] = val3;
  }

  // Check that raw data values are reflected.
  test_assert(equal(block.get(1), val2));
  test_assert(equal(block.get(2), val3));
}
예제 #24
0
void
test_matrix_freqswap( length_type m, length_type n )
{
  Matrix<T> a(m, n);

  Rand<T> rgen(0);
  a = rgen.randu(m, n);

  Matrix<T> b(m, n);
  Matrix<T> c(m, n);
  b = vsip::freqswap(a);
  c = a; c = vsip::freqswap(c);

  for ( index_type i = 0; i < m; i++ )
    for ( index_type j = 0; j < n; j++ )
    {
      test_assert(equal( b.get(i, j),
               a.get(((m+1)/2 + i) % m, ((n+1)/2 + j) % n ) ));
      test_assert(equal( c.get(i, j),
               a.get(((m+1)/2 + i) % m, ((n+1)/2 + j) % n ) ));
    }
}
void
check_matrix(MatrixT view, int offset=0)
{
  typedef typename MatrixT::value_type T;

  length_type const size1 = view.size(1);

  for (index_type idx0=0; idx0<view.size(0); ++idx0)
    for (index_type idx1=0; idx1<view.size(1); ++idx1)
    {
      test_assert(equal(view.get(idx0, idx1),
		   T(idx0 * size1 + idx1 + offset)));
    }
}
예제 #26
0
void
test_arg()
{
  Storage<Dim, T1> Z;
  Storage<Dim, T2> A;

  T2 input(3., 6.);

  put_nth(A.view, 0, input);

  Z.view = vsip::arg(A.view);

  test_assert(equal(get_nth(Z.view, 0), std::arg(input)));
}
예제 #27
0
void
test_maxmgsq()
{
  Storage<Dim, T1> Z;
  Storage<Dim, T2> A;
  Storage<Dim, T3> B;

  put_nth(A.view, 0, T2(-3));
  put_nth(B.view, 0, T3(-4));

  Z.view = vsip::maxmgsq(A.view, B.view);

  test_assert(equal(get_nth(Z.view, 0), T1(4*4)));
}
예제 #28
0
bool
check_array(
  T*                 data,
  Domain<Dim> const& dom,
  Func               fun)
{
  Length<Dim> ext = impl::extent(dom);
  for (Index<Dim> idx; valid(ext,idx); next(ext, idx))
  {
    index_type i = to_index<Order>(ext, idx);
    if (!equal(data[i], fun(i)))
      return false;
  }
  return true;
}
예제 #29
0
bool
check_block(
  Block&             block,
  Domain<Dim> const& dom,
  Func               fun)
{
  Length<Dim> ext = impl::extent(dom);
  for (Index<Dim> idx; valid(ext,idx); next(ext, idx))
  {
    index_type i = to_index<Order>(ext, idx);
    if (!equal(get(block, idx), fun(i)))
      return false;
  }
  return true;
}
예제 #30
0
void 
Test_sub( T a, T b)
{
  // unit strides
  {
    Vector<T> v1(10, a);
    Vector<T> v2(10, b);
    Vector<T> result(10, T());
    
    // subtract them
    result = v1 - v2;
    
    // check the result
    for ( index_type i = 0; i < result.size(); ++i )
      assert( equal( result.get(i), a - b ) );
  }

  // non-unit strides
  {
    typedef typename Vector<T>::subview_type vector_subview_type;

    Vector<T> v1_(20, a);
    Vector<T> v2_(30, b);
    Vector<T> result_(50, T());
    vector_subview_type v1 = v1_(Domain<1>(0, 2, 10));
    vector_subview_type v2 = v2_(Domain<1>(0, 3, 10));
    vector_subview_type result = result_(Domain<1>(0, 5, 10));

    // subtract them
    result = v1 - v2;

    // check the result
    for ( index_type i = 0; i < result.size(); ++i )
      assert( equal( result.get(i), a - b ) );
  }
}