ScalarType diff(ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType> & v2) { ublas::vector<ScalarType> v2_cpu(v2.size()); viennacl::backend::finish(); viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin()); for (unsigned int i=0;i<v1.size(); ++i) { if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 ) { //if (std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) < 1e-10 ) //absolute tolerance (avoid round-off issues) // v2_cpu[i] = 0; //else v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ); } else v2_cpu[i] = 0.0; if (v2_cpu[i] > 0.0001) { //std::cout << "Neighbor: " << i-1 << ": " << v1[i-1] << " vs. " << v2_cpu[i-1] << std::endl; std::cout << "Error at entry " << i << ": " << v1[i] << " vs. " << v2_cpu[i] << std::endl; //std::cout << "Neighbor: " << i+1 << ": " << v1[i+1] << " vs. " << v2_cpu[i+1] << std::endl; exit(EXIT_FAILURE); } } return norm_inf(v2_cpu); }
NumericT diff(std::vector<NumericT> const & v1, viennacl::vector<NumericT> const & v2) { std::vector<NumericT> v2_cpu(v2.size()); viennacl::backend::finish(); viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin()); for (std::size_t i=0;i<v1.size(); ++i) { if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 ) v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ); else v2_cpu[i] = 0.0; if (v2_cpu[i] > 0.0001) { //std::cout << "Neighbor: " << i-1 << ": " << v1[i-1] << " vs. " << v2_cpu[i-1] << std::endl; std::cout << "Error at entry " << i << ": " << v1[i] << " vs. " << v2[i] << std::endl; //std::cout << "Neighbor: " << i+1 << ": " << v1[i+1] << " vs. " << v2_cpu[i+1] << std::endl; exit(EXIT_FAILURE); } } NumericT inf_norm = 0; for (std::size_t i=0;i<v2_cpu.size(); ++i) inf_norm = std::max<NumericT>(inf_norm, std::fabs(v2_cpu[i])); return inf_norm; }
ScalarType diff_2(ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType> & v2) { ublas::vector<ScalarType> v2_cpu(v2.size()); viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin()); return norm_2(v1 - v2_cpu) / norm_2(v1); }
ScalarType diff ( ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType,Alignment> & v2 ) { ublas::vector<ScalarType> v2_cpu ( v2.size() ); viennacl::copy( v2.begin(), v2.end(), v2_cpu.begin() ); for ( unsigned int i=0; i<v1.size(); ++i ) { if ( std::max ( fabs ( v2_cpu[i] ), fabs ( v1[i] ) ) > 0 ) v2_cpu[i] = fabs ( v2_cpu[i] - v1[i] ) / std::max ( fabs ( v2_cpu[i] ), fabs ( v1[i] ) ); else v2_cpu[i] = 0.0; } return norm_inf ( v2_cpu ); }
ScalarType diff(ublas::vector<ScalarType> & v1, viennacl::vector<ScalarType> & v2) { ublas::vector<ScalarType> v2_cpu(v2.size()); viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8) viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin()); for (std::size_t i=0;i<v1.size(); ++i) { if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 ) v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ); else v2_cpu[i] = 0.0; } return norm_inf(v2_cpu); }