Пример #1
0
void exercise_assignment(SU_vector& source, SU_vector& dest, double expectedVal){
	try{
		alloc_counting::reset_allocation_counters();
		dest=std::move(source);
		auto allocated=alloc_counting::mem_allocated;
		std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
		//check the number of components
		auto components=dest.GetComponents();
		std::cout << components.size() << " components stored" << '\n';
		//check that all components are initialized to the correct value
		std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==expectedVal); })?
		 "are":"are not") << " correctly set\n";
		std::cout << "source dimension: " << source.Dim() << '\n';
		//check that memory is not aliased
		if(source.Dim()){
			source[0]=5;
			std::cout << "Memory aliasing: " << (dest[0]==source[0]) << '\n';
		}
	}catch(std::runtime_error& e){
		std::cout << "Assignment failed: " << e.what() << '\n';
	}
}
Пример #2
0
void test_fused_assign_add(unsigned int dim, SU_vector& dest, const std::string& dStoreType){
	const double d1=4.97, d2=2.14, sum=d1+d2;
	SU_vector v1(dim), v2(dim);
	std::cout << "Assigning sum of vectors with sizes " << v1.Dim() << " and " << v2.Dim()
		<< " to vector with size " << dest.Dim() << " (" << dStoreType << ")\n";
	v1.SetAllComponents(d1);
	v2.SetAllComponents(d2);
	try{
		alloc_counting::reset_allocation_counters();
		dest=v1+v2;
		auto allocated=alloc_counting::mem_allocated;
		std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
		check_all_components_equal(dest,sum);
	} catch(std::runtime_error& err){
		std::cout << "Exception: " << err.what() << '\n';
	}
}