void test_svd(const std::string & fn, ScalarType EPS) { std::size_t sz1, sz2; //read matrix // sz1 = 2048, sz2 = 2048; // std::vector<ScalarType> in(sz1 * sz2); // random_fill(in); // read file std::fstream f(fn.c_str(), std::fstream::in); //read size of input matrix read_matrix_size(f, sz1, sz2); std::size_t to = std::min(sz1, sz2); viennacl::matrix<ScalarType> Ai(sz1, sz2), Aref(sz1, sz2), QL(sz1, sz1), QR(sz2, sz2); read_matrix_body(f, Ai); std::vector<ScalarType> sigma_ref(to); read_vector_body(f, sigma_ref); f.close(); // viennacl::fast_copy(&in[0], &in[0] + in.size(), Ai); Aref = Ai; Timer timer; timer.start(); viennacl::linalg::svd(Ai, QL, QR); viennacl::backend::finish(); double time_spend = timer.get(); viennacl::matrix<ScalarType> result1(sz1, sz2), result2(sz1, sz2); result1 = viennacl::linalg::prod(QL, Ai); result2 = viennacl::linalg::prod(result1, trans(QR)); ScalarType sigma_diff = sigmas_compare(Ai, sigma_ref); ScalarType prods_diff = matrix_compare(result2, Aref); bool sigma_ok = (fabs(sigma_diff) < EPS) && (fabs(prods_diff) < std::sqrt(EPS)); //note: computing the product is not accurate down to 10^{-16}, so we allow for a higher tolerance here printf("%6s [%dx%d] %40s sigma_diff = %.6f; prod_diff = %.6f; time = %.6f\n", sigma_ok?"[[OK]]":"[FAIL]", (int)Aref.size1(), (int)Aref.size2(), fn.c_str(), sigma_diff, prods_diff, time_spend); }
void tst_QPlaceProposedSearchResult::constructorTest() { QPlaceProposedSearchResult result; QCOMPARE(result.type(), QPlaceSearchResult::ProposedSearchResult); result.setTitle(QStringLiteral("title")); QPlaceIcon icon; QVariantMap parameters; parameters.insert(QStringLiteral("paramKey"), QStringLiteral("paramValue")); icon.setParameters(parameters); result.setIcon(icon); QPlaceSearchRequest searchRequest; searchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/place-search"))); result.setSearchRequest(searchRequest); //check copy constructor QPlaceProposedSearchResult result2(result); QCOMPARE(result2.title(), QStringLiteral("title")); QCOMPARE(result2.icon(), icon); QCOMPARE(result2.searchRequest(), searchRequest); QVERIFY(QLocationTestUtils::compareEquality(result, result2)); //check results are the same after detachment of underlying shared data pointer result2.setTitle(QStringLiteral("title")); QVERIFY(QLocationTestUtils::compareEquality(result, result2)); //check construction of SearchResult using a ProposedSearchResult QPlaceSearchResult searchResult(result); QCOMPARE(searchResult.title(), QStringLiteral("title")); QCOMPARE(searchResult.icon(), icon); QVERIFY(QLocationTestUtils::compareEquality(searchResult, result)); QVERIFY(searchResult.type() == QPlaceSearchResult::ProposedSearchResult); result2 = searchResult; QVERIFY(QLocationTestUtils::compareEquality(result, result2)); //check construction of a SearchResult using a SearchResult //that is actually a PlaceResult underneath QPlaceSearchResult searchResult2(searchResult); QCOMPARE(searchResult2.title(), QStringLiteral("title")); QCOMPARE(searchResult2.icon(), icon); QVERIFY(QLocationTestUtils::compareEquality(searchResult2, result)); QVERIFY(QLocationTestUtils::compareEquality(searchResult, searchResult2)); QVERIFY(searchResult2.type() == QPlaceSearchResult::ProposedSearchResult); result2 = searchResult2; QVERIFY(QLocationTestUtils::compareEquality(result, result2)); }
TEUCHOS_UNIT_TEST( Stokhos_MatrixFreeOperator, ApplyUnitTest ) { // Test Apply() Epetra_Vector input(*setup.sg_x_map), result1(*setup.sg_f_map), result2(*setup.sg_f_map), diff(*setup.sg_f_map); input.Random(); setup.mat_free_op->Apply(input, result1); setup.assembled_op->Apply(input, result2); diff.Update(1.0, result1, -1.0, result2, 0.0); double nrm; diff.NormInf(&nrm); success = std::abs(nrm < setup.tol); out << "Apply infinity norm of difference: " << nrm << std::endl; out << "Matrix-free result = " << std::endl << result1 << std::endl << "Assebled result = " << std::endl << result2 << std::endl; }
void pullClasses_functionReturnsTheTwoDifferentInputtedClasses_pointersComparesEqualToInputs() { m_lua->register_class<Stub1>(); m_lua->register_class<Stub2>(); Stub1 input1; Stub1* result1(0); Stub2 input2; Stub2* result2(0); m_lua->run_chunk("return function(...) return ... end"); m_lua->call(1, &input1, &input2); OOLUA::pull(*m_lua, result2); OOLUA::pull(*m_lua, result1); CPPUNIT_ASSERT_EQUAL_MESSAGE("input2 is incorrect", &input2, result2); CPPUNIT_ASSERT_EQUAL_MESSAGE("input1 is incorrect", &input1, result1); }
vector<int> maxSumOfThreeSubarrays(vector<int>& nums, int k) { vector<int> sum(nums.size() + 1); sum[0] = 0; for(int i=0; i<nums.size(); i++) sum[i+1] = sum[i] + nums[i]; vector<int> sum1(nums.size(), 0), sum2(nums.size(), 0), sum3(nums.size(), 0); vector<vector<int>> result1(nums.size()), result2(nums.size()), result3(nums.size()); for(int i=k-1; i < (nums.size() - (2 * k)); i++) { if(sum1[i-1] < sum[i+1] - sum[i-k+1]) { sum1[i] = sum[i+1] - sum[i-k+1]; result1[i].push_back(i-k+1); } else { sum1[i] = sum1[i-1]; result1[i] = result1[i-1]; } //sum1[i] = max(sum1[i-1], sum[i+1] - sum[i-k+1]); } for(int i=(2*k)-1; i < (nums.size() - k); i++) { if(sum2[i-1] < sum1[i-k] + sum[i+1] - sum[i-k+1]) { sum2[i] = sum1[i-k] + sum[i+1] - sum[i-k+1]; result2[i] = result1[i-k]; result2[i].push_back(i-k+1); } else { sum2[i] = sum2[i-1]; result2[i] = result2[i-1]; } //sum2[i] = max(sum2[i-1], sum1[i-k] + sum[i+1] - sum[i-k+1]); } for(int i=(3*k)-1; i < nums.size(); i++) { if(sum3[i-1] < sum2[i-k] + sum[i+1] - sum[i-k+1]) { sum3[i] = sum2[i-k] + sum[i+1] - sum[i-k+1]; result3[i] = result2[i-k]; result3[i].push_back(i-k+1); } else { sum3[i] = sum3[i-1]; result3[i] = result3[i-1]; } //sum3[i] = max(sum3[i-1], sum2[i-k] + sum[i+1] - sum[i-k+1]); } return result3[nums.size()-1]; }
/** @SYMTestCaseID UIF-ETUL-0008 @SYMREQ 7736 @SYMTestCaseDesc Test to search for email addresses in the string and verifies their positions. @SYMTestPriority High @SYMTestStatus Implemented @SYMTestActions Constructs CTulAddressStringTokenizer object with CTulAddressStringTokenizer::EFindItemSearchMailAddressBin|EFindItemSearchURLBin \n which parses the given string and creates an item array consisting of all the Email addresses and URL's\n API Calls:\n CTulAddressStringTokenizer::NewL(const TDesC& aText, TInt aSearchCases);\n CTulAddressStringTokenizer::Item(SFoundItem& aItem); \n CTulAddressStringTokenizer::NextItem(SFoundItem& aItem);\n CTulAddressStringTokenizer::ResetPosition();\n @SYMTestExpectedResults The test checks whether 1. Phone numbers, Email addresses and URL's found by CTulAddressStringTokenizer are the correct ones. 2. CTulAddressStringTokenizer::ResetPosition() resets the position of the addressString array to zero. */ void CT_AddressStringTokenizerStep::CheckPositionsL() { CTulAddressStringTokenizer* addressString = CTulAddressStringTokenizer::NewL(KTextToBeParsedToCheckPositions, (CTulAddressStringTokenizer::TTokenizerSearchCase)(CTulAddressStringTokenizer::EFindItemSearchMailAddressBin | CTulAddressStringTokenizer::EFindItemSearchURLBin)); TBufC<512> str(KTextToBeParsedToCheckPositions); //Get count of found email addresses TInt count(addressString->ItemCount()); TEST(count == 4); // Get currently selected email CTulAddressStringTokenizer::SFoundItem item; addressString->Item(item); TPtrC16 result(str.Mid(item.iStartPos, item.iLength)); TEST(result.Compare(KURL4) == 0); addressString->NextItem(item); TPtrC16 result1(str.Mid(item.iStartPos, item.iLength)); TEST(result1.Compare(KEMail) == 0); //move to next item addressString->NextItem(item); TPtrC16 result2(str.Mid(item.iStartPos, item.iLength)); TEST(result2.Compare(KEMail1) == 0); //check that position is correct TEST(addressString->Position() == 2); //move to next item addressString->NextItem(item); result2.Set(str.Mid(item.iStartPos, item.iLength)); TEST(result2.Compare(KEMail2) == 0); //Resets the position to zero addressString->ResetPosition(); //get the first item addressString->Item(item); TPtrC16 reset_result1(str.Mid(item.iStartPos, item.iLength)); TEST(reset_result1.Compare(KURL4) == 0); //verify that we are in first item TEST(result == reset_result1); delete addressString; }
TEST(MeshLib, DoubleFlipQuadMesh) { std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::MeshGenerator::generateRegularQuadMesh(5, 5)); std::unique_ptr<MeshLib::Mesh> result (MeshLib::createFlippedMesh(*mesh)); std::unique_ptr<MeshLib::Mesh> result2 (MeshLib::createFlippedMesh(*result)); ASSERT_EQ(mesh->getNumberOfNodes(), result2->getNumberOfNodes()); ASSERT_EQ(mesh->getNumberOfElements(), result2->getNumberOfElements()); for (std::size_t i = 0; i < result2->getNumberOfElements(); ++i) { for (std::size_t j = 0; j < 4; ++j) { ASSERT_EQ(mesh->getElement(i)->getNode(j)->getID(), result2->getElement(i)->getNode(j)->getID()); } } }
Polynomial spolynomial(const SPI & spi,const FactBase & fc,TimingRecorder * timers) { if(timers) { timers->start(s_spolynomialsTiming); }; const GroebnerRule & first = fc.rule(spi.leftID()); const GroebnerRule & second = fc.rule(spi.rightID()); Monomial tip1(first.LHS()); Monomial tip2(second.LHS()); Monomial right1, left2, one; int len1 = spi.overlapLength(); MonomialIterator w1 = tip2.begin(); for(int k=1;k<=len1;++k) { ++w1;}; int max1 = tip2.numberOfFactors()-1; // The following line is for a faster run-time. right1.reserve(max1-len1+1); for(int i=len1;i<=max1;++i,++w1) { right1 *= (*w1); } MonomialIterator w2 = tip1.begin(); int max2 = tip1.numberOfFactors() - len1; // The following line is for a faster run-time. left2.reserve(max2); for(i=0;i< max2;++i,++w2) { left2 *= (*w2); } Term ONE(one); #if 0 Monomial check1(tip1); check1 *= right1; Monomial check2(left2); check2 *= tip1; if(check1!=check2) { DBG(); }; #endif Polynomial result1(first.RHS()); Polynomial result2(second.RHS()); result1 *= Term(right1); result2.premultiply(Term(left2)); result1 -= result2; if(timers) { timers->printpause("spolynomial Timing:",s_spolynomialsTiming); }; return result1; };
TEST(Py3Function, Print) { Include include("test_python"); Function function(include, "multiply"); Variable a(5); Variable b(3); VariablePtr result1(function(a, b)); EXPECT_EQ(15, result1->get<int32_t>()); // Run again just in case VariablePtr result2(function(a, b)); EXPECT_EQ(15, result2->get<int32_t>()); Variable c(10); Variable d(20); VariablePtr result(function(c, d)); EXPECT_EQ(200, result->get<int32_t>()); }
SecureArray QCACryptoInterface::sharedDHKey(const QString &prime, const QString &base, const QString &secret) { BigUnsigned primeNumber = stringToBigUnsigned(prime.toStdString()); BigInteger baseNumber = stringToBigUnsigned(base.toStdString()); BigUnsigned secretNumber = stringToBigUnsigned(secret.toStdString()); BigUnsigned result = modexp(baseNumber, secretNumber, primeNumber); QByteArray key; BigUnsigned result2(result); while (result2 != 0) { char rest = (result2 % 256).toUnsignedShort(); key.prepend(rest); result2 = result2 / 256; } int size = key.size(); return key; }
TEST_F(RegistryTablesTest, test_registry_or_clause) { SQL result1("SELECT * FROM registry WHERE key = \"" + kTestKey + "\""); SQL result2("SELECT * FROM registry WHERE key = \"" + kTestSpecificKey + "\""); SQL combinedResults("SELECT * FROM registry WHERE key = \"" + kTestKey + "\" OR key = \"" + kTestSpecificKey + "\""); EXPECT_TRUE(result1.rows().size() > 0); EXPECT_TRUE(result2.rows().size() > 0); EXPECT_TRUE(combinedResults.rows().size() == result1.rows().size() + result2.rows().size()); EXPECT_TRUE(std::includes(combinedResults.rows().begin(), combinedResults.rows().end(), result1.rows().begin(), result1.rows().end())); EXPECT_TRUE(std::includes(combinedResults.rows().begin(), combinedResults.rows().end(), result2.rows().begin(), result2.rows().end())); }
string multiply(string num1, string num2) { string result(num1.size()+num2.size(),'0'); for (int i = num1.size()-1; i >= 0; --i) { int carry = 0; for (int j = num2.size()-1; carry!=0 || j>=0; --j) { int n_digit = (j >= 0? (num1[i]-'0')*(num2[j]-'0'):0) + carry; carry = (result[i+j+1] -'0'+ n_digit)/10; result[i+j+1] = '0' + (result[i+j+1] -'0'+ n_digit) % 10; } } if (result.front() == '0') result.erase(result.begin()); if (num1.size() == 1 && num1.front() == '0' || num2.size() == 1 && num2.front()=='0') { string result2(1,'0'); return result2; } return result; }
void tst_QPlaceSearchResult::constructorTest() { QPlaceSearchResult result; QCOMPARE(result.type(), QPlaceSearchResult::UnknownSearchResult); QVERIFY(result.title().isEmpty()); QVERIFY(result.icon().isEmpty()); result.setTitle(QLatin1String("title")); QPlaceIcon icon; QVariantMap parameters; parameters.insert(QLatin1String("paramKey"), QLatin1String("paramValue")); icon.setParameters(parameters); result.setIcon(icon); QPlaceSearchResult result2(result); QCOMPARE(result2.title(), QLatin1String("title")); QCOMPARE(result2.icon().parameters().value(QLatin1String("paramKey")).toString(), QLatin1String("paramValue")); QCOMPARE(result2, result); }
void TestApp::test_matrix_mat4() { Console::write_line(" Class: Mat4"); Console::write_line(" Function: inverse()"); { Mat4f test_src = Mat4f::rotate((Angle(30, angle_degrees)), 1.0, 0.0, 0.0, true); Mat4f test_inv; Mat4f test_dest; Mat4f test_ident = Mat4f::identity(); test_dest = test_src; test_dest.inverse(); test_dest = test_dest * test_src; if (test_ident != test_dest) fail(); } static int test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2}; static int test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2}; Mat4i test_a(test_a_values); Mat4i test_b(test_b_values); Mat4f test_c(test_a); Mat4f test_c_scaled(test_c); { float x = 2.0f; float y = 3.0f; float z = 4.0f; test_c_scaled[0 + 4 * 0] *= x; test_c_scaled[0 + 4 * 1] *= y; test_c_scaled[0 + 4 * 2] *= z; test_c_scaled[1 + 4 * 0] *= x; test_c_scaled[1 + 4 * 1] *= y; test_c_scaled[1 + 4 * 2] *= z; test_c_scaled[2 + 4 * 0] *= x; test_c_scaled[2 + 4 * 1] *= y; test_c_scaled[2 + 4 * 2] *= z; test_c_scaled[3 + 4 * 0] *= x; test_c_scaled[3 + 4 * 1] *= y; test_c_scaled[3 + 4 * 2] *= z; } Console::write_line(" Function: add() and operator"); { int answer_values[] = {7, 8, 4, 9, 8, 11, 6, 11, 4, 7, 12, 16, 8, 7, 13, 4}; Mat4i answer(answer_values); Mat4i result = test_a + test_b; if (result != answer) fail(); result = Mat4i::add(test_a, test_b); if (result != answer) fail(); } Console::write_line(" Function: subtract() and operator"); { int answer_values[] = {-1, -6, 0, -1, 2, 1, 2, -7, -2, 1, 0, -2, 4, -1, 1, 0}; Mat4i answer(answer_values); Mat4i result = test_a - test_b; if (result != answer) fail(); result = Mat4i::subtract(test_a, test_b); if (result != answer) fail(); } Console::write_line(" Function: translate()"); { int answer_values[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, 4, 1}; Mat4i answer(answer_values); Mat4i result = Mat4i::translate(2, 3, 4); if (result != answer) fail(); } Console::write_line(" Function: translate_self() (int)"); { Mat4i answer(test_a); Mat4i result = test_a; result = result * Mat4i::translate(2, 3, 4); Mat4i result2 = test_a; result2.translate_self(2,3,4); if (result != result2) fail(); } Console::write_line(" Function: translate_self() (float)"); { Mat4f answer(test_a); Mat4f result(test_a); result = result * Mat4f::translate(2, 3, 4); Mat4f result2(test_a); result2.translate_self(2, 3, 4); if (!result.is_equal(result2, 0.00001f)) fail(); } Console::write_line(" Function: scale_self()"); { Mat4i answer(test_a); Mat4i result = test_a; result = result * Mat4i::scale(2, 3, 4); Mat4i result2 = test_a; result2.scale_self(2,3,4); if (result != result2) fail(); Mat4f test = test_c; test.scale_self(2.0f, 3.0f, 4.0f); if (!test.is_equal(test_c_scaled, 0.00001f)) fail(); } Console::write_line(" Function: rotate (using euler angles)"); { Mat4f mv = Mat4f::identity(); mv = mv * Mat4f::rotate(Angle(30.0f, angle_degrees), 0.0f, 0.0f, 1.0f, false); mv = mv * Mat4f::rotate(Angle(10.0f, angle_degrees), 1.0f, 0.0f, 0.0f, false); mv = mv * Mat4f::rotate(Angle(20.0f, angle_degrees), 0.0f, 1.0f, 0.0f, false); Mat4f test_matrix; test_matrix = Mat4f::rotate(Angle(10.0f, angle_degrees), Angle(20.0f, angle_degrees), Angle(30.0f, angle_degrees), order_YXZ); if (!test_matrix.is_equal(mv, 0.00001f)) fail(); } Console::write_line(" Function: rotate (using euler angles) and get_euler"); { test_rotate_and_get_euler(order_XYZ); test_rotate_and_get_euler(order_XZY); test_rotate_and_get_euler(order_YZX); test_rotate_and_get_euler(order_YXZ); test_rotate_and_get_euler(order_ZXY); test_rotate_and_get_euler(order_ZYX); } Console::write_line(" Function: transpose() (float)"); { Mat4f original(test_a); Mat4f transposed_matrix; transposed_matrix[0] = original[0]; transposed_matrix[1] = original[4]; transposed_matrix[2] = original[8]; transposed_matrix[3] = original[12]; transposed_matrix[4] = original[1]; transposed_matrix[5] = original[5]; transposed_matrix[6] = original[9]; transposed_matrix[7] = original[13]; transposed_matrix[8] = original[2]; transposed_matrix[9] = original[6]; transposed_matrix[10] = original[10]; transposed_matrix[11] = original[14]; transposed_matrix[12] = original[3]; transposed_matrix[13] = original[7]; transposed_matrix[14] = original[11]; transposed_matrix[15] = original[15]; Mat4f test = original; test.transpose(); if (!test.is_equal(transposed_matrix, 0.00001f)) fail(); } }
void test_recursive_variant() { typedef boost::make_recursive_variant< int , std::vector<boost::recursive_variant_> >::type var1_t; std::vector<var1_t> vec1; vec1.push_back(3); vec1.push_back(5); vec1.push_back(vec1); vec1.push_back(7); var1_t var1(vec1); std::string result1( boost::apply_visitor( vector_printer(), var1 ) ); std::cout << "result1: " << result1 << '\n'; BOOST_CHECK(result1 == "( 3 5 ( 3 5 ) 7 ) "); typedef boost::make_recursive_variant< boost::variant<int, double> , std::vector<boost::recursive_variant_> >::type var2_t; std::vector<var2_t> vec2; vec2.push_back(boost::variant<int, double>(3)); vec2.push_back(boost::variant<int, double>(3.5)); vec2.push_back(vec2); vec2.push_back(boost::variant<int, double>(7)); var2_t var2(vec2); std::string result2( boost::apply_visitor( vector_printer(), var2 ) ); std::cout << "result2: " << result2 << '\n'; BOOST_CHECK(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) "); typedef boost::make_recursive_variant< int , std::vector< boost::variant< double , std::vector<boost::recursive_variant_> > > >::type var3_t; typedef boost::variant<double, std::vector<var3_t> > var4_t; std::vector<var3_t> vec3; vec3.push_back(3); vec3.push_back(5); std::vector<var4_t> vec4; vec4.push_back(3.5); vec4.push_back(vec3); vec3.push_back(vec4); vec3.push_back(7); var4_t var4(vec3); std::string result3( boost::apply_visitor( vector_printer(), var4 ) ); std::cout << "result2: " << result3 << '\n'; BOOST_CHECK(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) "); typedef boost::make_recursive_variant< double, std::vector<var1_t> >::type var5_t; std::vector<var5_t> vec5; vec5.push_back(3.5); vec5.push_back(vec1); vec5.push_back(17.25); std::string result5( vector_printer()(vec5) ); std::cout << "result5: " << result5 << '\n'; BOOST_CHECK(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) "); typedef boost::make_recursive_variant< int, std::map<int, boost::recursive_variant_> >::type var6_t; var6_t var6; }
void test_eigen(const std::string& fn, bool is_symm) { std::cout << "Reading..." << "\n"; std::size_t sz; // read file std::fstream f(fn.c_str(), std::fstream::in); //read size of input matrix read_matrix_size(f, sz); bool is_row = viennacl::is_row_major<MatrixLayout>::value; if (is_row) std::cout << "Testing row-major matrix of size " << sz << "-by-" << sz << std::endl; else std::cout << "Testing column-major matrix of size " << sz << "-by-" << sz << std::endl; viennacl::matrix<ScalarType> A_input(sz, sz), A_ref(sz, sz), Q(sz, sz); // reference vector with reference values from file std::vector<ScalarType> eigen_ref_re(sz); // calculated real eigenvalues std::vector<ScalarType> eigen_re(sz); // calculated im. eigenvalues std::vector<ScalarType> eigen_im(sz); // read input matrix from file read_matrix_body(f, A_input); // read reference eigenvalues from file read_vector_body(f, eigen_ref_re); f.close(); A_ref = A_input; std::cout << "Calculation..." << "\n"; Timer timer; timer.start(); // Start the calculation if(is_symm) viennacl::linalg::qr_method_sym(A_input, Q, eigen_re); else viennacl::linalg::qr_method_nsm(A_input, Q, eigen_re, eigen_im); /* std::cout << "\n\n Matrix A: \n\n"; matrix_print(A_input); std::cout << "\n\n"; std::cout << "\n\n Matrix Q: \n\n"; matrix_print(Q); std::cout << "\n\n"; */ double time_spend = timer.get(); std::cout << "Verification..." << "\n"; bool is_hessenberg = check_hessenberg(A_input); bool is_tridiag = check_tridiag(A_input); ublas::matrix<ScalarType> A_ref_ublas(sz, sz), A_input_ublas(sz, sz), Q_ublas(sz, sz), result1(sz, sz), result2(sz, sz); viennacl::copy(A_ref, A_ref_ublas); viennacl::copy(A_input, A_input_ublas); viennacl::copy(Q, Q_ublas); // compute result1 = ublas::prod(Q_ublas, A_input_ublas); (terribly slow when using ublas directly) for (std::size_t i=0; i<result1.size1(); ++i) for (std::size_t j=0; j<result1.size2(); ++j) { ScalarType value = 0; for (std::size_t k=0; k<Q_ublas.size2(); ++k) value += Q_ublas(i, k) * A_input_ublas(k, j); result1(i,j) = value; } // compute result2 = ublas::prod(A_ref_ublas, Q_ublas); (terribly slow when using ublas directly) for (std::size_t i=0; i<result2.size1(); ++i) for (std::size_t j=0; j<result2.size2(); ++j) { ScalarType value = 0; for (std::size_t k=0; k<A_ref_ublas.size2(); ++k) value += A_ref_ublas(i, k) * Q_ublas(k, j); result2(i,j) = value; } ScalarType prods_diff = matrix_compare(result1, result2); ScalarType eigen_diff = vector_compare(eigen_re, eigen_ref_re); bool is_ok = is_hessenberg; if(is_symm) is_ok = is_ok && is_tridiag; is_ok = is_ok && (eigen_diff < EPS); is_ok = is_ok && (prods_diff < EPS); // std::cout << A_ref << "\n"; // std::cout << A_input << "\n"; // std::cout << Q << "\n"; // std::cout << eigen_re << "\n"; // std::cout << eigen_im << "\n"; // std::cout << eigen_ref_re << "\n"; // std::cout << eigen_ref_im << "\n"; // std::cout << result1 << "\n"; // std::cout << result2 << "\n"; // std::cout << eigen_ref << "\n"; // std::cout << eigen << "\n"; printf("%6s [%dx%d] %40s time = %.4f\n", is_ok?"[[OK]]":"[FAIL]", (int)A_ref.size1(), (int)A_ref.size2(), fn.c_str(), time_spend); printf("tridiagonal = %d, hessenberg = %d prod-diff = %f eigen-diff = %f\n", is_tridiag, is_hessenberg, prods_diff, eigen_diff); std::cout << std::endl << std::endl; if (!is_ok) exit(EXIT_FAILURE); }
static void test_type2index_list() { Tensor<float, 5> tensor(2,3,5,7,11); tensor.setRandom(); tensor += tensor.constant(10.0f); typedef Eigen::IndexList<Eigen::type2index<0>> Dims0; typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>> Dims1; typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>> Dims2; typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>, Eigen::type2index<3>> Dims3; typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>, Eigen::type2index<3>, Eigen::type2index<4>> Dims4; #if 0 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims0>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims1>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims2>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims3>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims4>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); #endif EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims0, 1, ColMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims1, 2, ColMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims2, 3, ColMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims3, 4, ColMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims4, 5, ColMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims0, 1, RowMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims1, 2, RowMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims2, 3, RowMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims3, 4, RowMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims4, 5, RowMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE); const Dims0 reduction_axis0; Tensor<float, 4> result0 = tensor.sum(reduction_axis0); for (int m = 0; m < 11; ++m) { for (int l = 0; l < 7; ++l) { for (int k = 0; k < 5; ++k) { for (int j = 0; j < 3; ++j) { float expected = 0.0f; for (int i = 0; i < 2; ++i) { expected += tensor(i,j,k,l,m); } VERIFY_IS_APPROX(result0(j,k,l,m), expected); } } } } const Dims1 reduction_axis1; Tensor<float, 3> result1 = tensor.sum(reduction_axis1); for (int m = 0; m < 11; ++m) { for (int l = 0; l < 7; ++l) { for (int k = 0; k < 5; ++k) { float expected = 0.0f; for (int j = 0; j < 3; ++j) { for (int i = 0; i < 2; ++i) { expected += tensor(i,j,k,l,m); } } VERIFY_IS_APPROX(result1(k,l,m), expected); } } } const Dims2 reduction_axis2; Tensor<float, 2> result2 = tensor.sum(reduction_axis2); for (int m = 0; m < 11; ++m) { for (int l = 0; l < 7; ++l) { float expected = 0.0f; for (int k = 0; k < 5; ++k) { for (int j = 0; j < 3; ++j) { for (int i = 0; i < 2; ++i) { expected += tensor(i,j,k,l,m); } } } VERIFY_IS_APPROX(result2(l,m), expected); } } const Dims3 reduction_axis3; Tensor<float, 1> result3 = tensor.sum(reduction_axis3); for (int m = 0; m < 11; ++m) { float expected = 0.0f; for (int l = 0; l < 7; ++l) { for (int k = 0; k < 5; ++k) { for (int j = 0; j < 3; ++j) { for (int i = 0; i < 2; ++i) { expected += tensor(i,j,k,l,m); } } } } VERIFY_IS_APPROX(result3(m), expected); } const Dims4 reduction_axis4; Tensor<float, 0> result4 = tensor.sum(reduction_axis4); float expected = 0.0f; for (int m = 0; m < 11; ++m) { for (int l = 0; l < 7; ++l) { for (int k = 0; k < 5; ++k) { for (int j = 0; j < 3; ++j) { for (int i = 0; i < 2; ++i) { expected += tensor(i,j,k,l,m); } } } } } VERIFY_IS_APPROX(result4(), expected); }
static void test_mixed_index_list() { Tensor<float, 4> tensor(2,3,5,7); tensor.setRandom(); int dim2 = 1; int dim4 = 3; auto reduction_axis = make_index_list(0, dim2, 2, dim4); VERIFY_IS_EQUAL(internal::array_get<0>(reduction_axis), 0); VERIFY_IS_EQUAL(internal::array_get<1>(reduction_axis), 1); VERIFY_IS_EQUAL(internal::array_get<2>(reduction_axis), 2); VERIFY_IS_EQUAL(internal::array_get<3>(reduction_axis), 3); VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[0]), 0); VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[1]), 1); VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[2]), 2); VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[3]), 3); typedef IndexList<type2index<0>, int, type2index<2>, int> ReductionIndices; ReductionIndices reduction_indices; reduction_indices.set(1, 1); reduction_indices.set(3, 3); EIGEN_STATIC_ASSERT((internal::array_get<0>(reduction_indices) == 0), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::array_get<2>(reduction_indices) == 2), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>()(0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>()(2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>()(0, 0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>()(2, 2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); #if 0 EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionIndices>()() == false), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionIndices>()() == false), YOU_MADE_A_PROGRAMMING_MISTAKE); #endif typedef IndexList<type2index<0>, type2index<1>, type2index<2>, type2index<3>> ReductionList; ReductionList reduction_list; EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(0, 0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(1, 1) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(2, 2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(3, 3) == true), YOU_MADE_A_PROGRAMMING_MISTAKE); #if 0 EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionList>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionList>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE); #endif Tensor<float, 0> result1 = tensor.sum(reduction_axis); Tensor<float, 0> result2 = tensor.sum(reduction_indices); Tensor<float, 0> result3 = tensor.sum(reduction_list); float expected = 0.0f; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 5; ++k) { for (int l = 0; l < 7; ++l) { expected += tensor(i,j,k,l); } } } } VERIFY_IS_APPROX(result1(), expected); VERIFY_IS_APPROX(result2(), expected); VERIFY_IS_APPROX(result3(), expected); }
int main(int argc, char* argv[]) { /*if (argc!=2) exit(0); double T = atof(argv[1]); printf(" T=%.3f\n",T);*/ system("rm lambda.T*"); GRID grid("params"); int N= grid.get_N(); Result result1(&grid); Result result2(&grid); Result result3(&grid); for (double T=0.30; T>0.05; T-=0.01) { for (double U=1.5; U<4.0; U+=0.1) { char FN[300]; sprintf( FN, "CHM.U%.3f.T%.3f", U, T); char FN2[300]; sprintf( FN2, "%s.FAILED", FN); if ((not FileExists(FN))and(not FileExists(FN2))) continue; char ldFN[300]; sprintf(ldFN,"lambdas_and_diffs.U%.3f.T%.3f",U,T); FILE* ldFile = fopen(ldFN,"w"); double lambdas[100]; int counter=0; for(int it=1; it<100; it++) { char FN[300]; sprintf( FN, "CHM.U%.3f.T%.3f.it%d", U, T, it); if(not result1.ReadFromFile(FN)) break; sprintf( FN, "CHM.U%.3f.T%.3f.it%d", U, T, it+1); if(not result2.ReadFromFile(FN)) break; sprintf( FN, "CHM.U%.3f.T%.3f.it%d", U, T, it+2); if(not result3.ReadFromFile(FN)) break; double sum = 0; for(int i=0; i<N; i++) sum += sqr( real(result2.G[i]-result1.G[i])) + sqr( imag(result2.G[i]-result1.G[i])); double diff = sqrt(sum)/(2.0*N); double simple_diff = abs( imag(result2.G[N/2]-result1.G[N/2]) ); double lambda = CalcLambda(N, result1.G, result2.G, result3.G); fprintf(ldFile,"%d %.15le %.15le %.15le\n",it,diff,lambda, simple_diff); lambdas[it-1]=lambda; counter++; complex<double>* dG = new complex<double>[N]; for(int i=0; i<N; i++) dG[i] = ((result2.G[i]-result1.G[i])/diff)/(2.0*((double) N)); sprintf( FN, "dG.U%.3f.T%.3f.it%d", U, T, it+1); PrintFunc(FN,N,dG,result1.omega); } fclose(ldFile); char lFN[300]; sprintf(lFN,"lambda.T%.3f",T); FILE* lFile = fopen(lFN,"a"); fprintf(lFile,"%.15le %.15le\n",U,FindLambda(counter,lambdas) ); fclose(lFile); } } return 0; }
void ResourceBundleTest::TestConstruction() { UErrorCode err = U_ZERO_ERROR; Locale locale("te", "IN"); const char* testdatapath=loadTestData(err); if(U_FAILURE(err)) { dataerrln("Could not load testdata.dat " + UnicodeString(testdatapath) + ", " + UnicodeString(u_errorName(err))); return; } /* Make sure that users using te_IN for the default locale don't get test failures. */ Locale originalDefault; if (Locale::getDefault() == Locale("te_IN")) { Locale::setDefault(Locale("en_US"), err); } ResourceBundle test1((UnicodeString)testdatapath, err); ResourceBundle test2(testdatapath, locale, err); //ResourceBundle test1("c:\\icu\\icu\\source\\test\\testdata\\testdata", err); //ResourceBundle test2("c:\\icu\\icu\\source\\test\\testdata\\testdata", locale, err); UnicodeString result1(test1.getStringEx("string_in_Root_te_te_IN", err)); UnicodeString result2(test2.getStringEx("string_in_Root_te_te_IN", err)); if (U_FAILURE(err)) { errln("Something threw an error in TestConstruction()"); return; } logln("for string_in_Root_te_te_IN, default.txt had " + result1); logln("for string_in_Root_te_te_IN, te_IN.txt had " + result2); if (result1 != "ROOT" || result2 != "TE_IN") errln("Construction test failed; run verbose for more information"); const char* version1; const char* version2; version1 = test1.getVersionNumber(); version2 = test2.getVersionNumber(); char *versionID1 = new char[1+strlen(version1)]; // + 1 for zero byte char *versionID2 = new char[1+ strlen(version2)]; // + 1 for zero byte strcpy(versionID1, "44.0"); // hardcoded, please change if the default.txt file or ResourceBundle::kVersionSeparater is changed. strcpy(versionID2, "55.0"); // hardcoded, please change if the te_IN.txt file or ResourceBundle::kVersionSeparater is changed. logln(UnicodeString("getVersionNumber on default.txt returned ") + version1); logln(UnicodeString("getVersionNumber on te_IN.txt returned ") + version2); if (strcmp(version1, versionID1) != 0 || strcmp(version2, versionID2) != 0) errln("getVersionNumber() failed"); delete[] versionID1; delete[] versionID2; /* Restore the default locale for the other tests. */ Locale::setDefault(originalDefault, err); }
static void execute(const Token *expr, std::map<unsigned int, MathLib::bigint> * const programMemory, MathLib::bigint *result, bool *error) { if (!expr) *error = true; else if (expr->isNumber()) *result = MathLib::toLongNumber(expr->str()); else if (expr->varId() > 0) { const std::map<unsigned int, MathLib::bigint>::const_iterator var = programMemory->find(expr->varId()); if (var == programMemory->end()) *error = true; else *result = var->second; } else if (expr->isComparisonOp()) { MathLib::bigint result1(0), result2(0); execute(expr->astOperand1(), programMemory, &result1, error); execute(expr->astOperand2(), programMemory, &result2, error); if (expr->str() == "<") *result = result1 < result2; else if (expr->str() == "<=") *result = result1 <= result2; else if (expr->str() == ">") *result = result1 > result2; else if (expr->str() == ">=") *result = result1 >= result2; else if (expr->str() == "==") *result = result1 == result2; else if (expr->str() == "!=") *result = result1 != result2; } else if (expr->str() == "=") { execute(expr->astOperand2(), programMemory, result, error); if (!*error && expr->astOperand1() && expr->astOperand1()->varId()) (*programMemory)[expr->astOperand1()->varId()] = *result; else *error = true; } else if (expr->str() == "++" || expr->str() == "--") { if (!expr->astOperand1() || expr->astOperand1()->varId() == 0U) *error = true; else { std::map<unsigned int, MathLib::bigint>::iterator var = programMemory->find(expr->astOperand1()->varId()); if (var == programMemory->end()) *error = true; else { if (var->second == 0 && expr->str() == "--" && expr->astOperand1()->variable() && expr->astOperand1()->variable()->typeStartToken()->isUnsigned()) *error = true; // overflow *result = var->second + (expr->str() == "++" ? 1 : -1); var->second = *result; } } } else if (expr->isArithmeticalOp() && expr->astOperand1() && expr->astOperand2()) { MathLib::bigint result1(0), result2(0); execute(expr->astOperand1(), programMemory, &result1, error); execute(expr->astOperand2(), programMemory, &result2, error); if (expr->str() == "+") *result = result1 + result2; else if (expr->str() == "-") *result = result1 - result2; else if (expr->str() == "*") *result = result1 * result2; else if (result2 == 0) *error = true; else if (expr->str() == "/") *result = result1 / result2; else if (expr->str() == "%") *result = result1 % result2; } else if (expr->str() == "&&") { bool error1 = false; execute(expr->astOperand1(), programMemory, result, &error1); if (!error1 && *result == 0) *result = 0; else { bool error2 = false; execute(expr->astOperand2(), programMemory, result, &error2); if (error1 && error2) *error = true; if (error2) *result = 1; else *result = !!*result; } } else if (expr->str() == "||") { execute(expr->astOperand1(), programMemory, result, error); if (*result == 0 && *error == false) execute(expr->astOperand2(), programMemory, result, error); } else *error = true; }