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; }
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; }
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)))); } }
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; }
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; }
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; }
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))); } }
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; }
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; }
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))); }