// Calculates dot product of two AD<double> vectors and two TapeDouble vectors. // Vectors are declared as independent. void performanceTestWithTape() { std::cout << std::endl << "Test performance for dot product calculation with tape recording" << std::endl; std::vector<CppAD::AD<double>> leftAD = vectorCast<CppAD::AD<double>>(leftVector); std::vector<CppAD::AD<double>> rightAD = vectorCast<CppAD::AD<double>>(rightVector); std::vector<cl::TapeDouble> leftTapeDouble = vectorCast<cl::TapeDouble>(leftVector); std::vector<cl::TapeDouble> rightTapeDouble = vectorCast<cl::TapeDouble>(rightVector); CppAD::AD<double> ADResult = 0; cl::TapeDouble TapeDoubleResult = 0; CppAD::Independent(leftAD); boost::timer timer; ADResult = dotProduct<CppAD::AD<double>>(leftAD, rightAD); CppAD::ADFun<double> adfun(leftAD, std::vector<CppAD::AD<double>>({ ADResult })); double ADtime = timer.elapsed(); cl::Independent(leftTapeDouble); timer.restart(); TapeDoubleResult = dotProduct<cl::TapeDouble >(leftTapeDouble, rightTapeDouble); cl::TapeFunction<double> fcl(leftTapeDouble, std::vector<cl::TapeDouble>({ TapeDoubleResult })); double CppTime = timer.elapsed(); std::cout << "\tTime for AD<double> " << ADtime << " s" << std::endl; std::cout << "\tTime for TapeDouble " << CppTime << " s" << std::endl; std::cout << "\tThe relative difference " << 1.0 * std::abs(CppTime - ADtime) / std::max(CppTime, ADtime) << std::endl ; }
// Calculates dot product of two AD<double> vectors and two tape_double vectors. // Vectors are declared as independent. void performanceTestWithTape() { std::ofstream out("..\\..\\..\\..\\..\\..\\..\\output\\en-us\\Tape\\CppAD\\Tests\\DotProductTest\\Log.csv", std::ofstream::out | std::ofstream::app); out << std::endl << "Test performance for dot product calculation with tape recording" << std::endl; out << "Dot product of two vectors (size " << dimension << " ) is being calculated" << std::endl; std::vector<CppAD::AD<double>> leftAD = vectorCast<CppAD::AD<double>>(leftVector); std::vector<CppAD::AD<double>> rightAD = vectorCast<CppAD::AD<double>>(rightVector); std::vector<cl::tape_double> lefttape_double = vectorCast<cl::tape_double>(leftVector); std::vector<cl::tape_double> righttape_double = vectorCast<cl::tape_double>(rightVector); CppAD::AD<double> ADResult = 0; cl::tape_double tape_doubleResult = 0; CppAD::Independent(leftAD); out << "Start of calculating: " << currentTime() << std::endl; boost::timer timer; ADResult = dotProduct<CppAD::AD<double>>(leftAD, rightAD); CppAD::ADFun<double> adfun(leftAD, std::vector<CppAD::AD<double>>({ ADResult })); double ADtime = timer.elapsed(); cl::Independent(lefttape_double); timer.restart(); tape_doubleResult = dotProduct<cl::tape_double >(lefttape_double, righttape_double); cl::tape_function<double> fcl(lefttape_double, std::vector<cl::tape_double>({ tape_doubleResult })); double CppTime = timer.elapsed(); out << "End of calculating" << std::endl; out << "\tTime for AD<double> " << ADtime << " s" << std::endl; out << "\tTime for tape_double " << CppTime << " s" << std::endl; out << "\tThe relative difference " << 1.0 * std::abs(CppTime - ADtime) / std::max(CppTime, ADtime) << std::endl ; }