Pade_approximant::Pade_approximant(const Array<COMPLEX,1> & z_in, const Array<COMPLEX,1> & u_in) : z_in(z_in) { int N = z_in.size(); a.resize(N); // Change the default precision of GMP floats. // MF: I have put an unsigned long instead of gmp::mp_bitcnt_t here so that it's compatible with GMP >= 4.3 unsigned long old_prec = gmp::mpf_get_default_prec(); gmp::mpf_set_default_prec(GMP_default_prec); // How do we determine it? Array<MP_COMPLEX,2> g(N,N); g = MP_COMPLEX(.0); g(0,Range::all()) = cast<MP_COMPLEX>(u_in); MP_COMPLEX MP_1(1.0); for(int p=1; p<N; ++p) for(int j=p; j<N; ++j){ MP_COMPLEX x(g(p-1,p-1)/g(p-1,j) - MP_1); MP_COMPLEX y(z_in(j)-z_in(p-1)); g(p,j) = x/y; } for(int j=0; j<N; ++j){ MP_COMPLEX gj(g(j,j)); a(j) = COMPLEX(real(gj).get_d(),imag(gj).get_d()); } // Restore the precision. gmp::mpf_set_default_prec(old_prec); }
void URLCollectionTest::malformedJSON() { const char * badJson[] = { // just bogus syntax "{", // missing required keys "{}", "{\"UseDomainForHTTP\": false}", "{\"urls\": []}", // bad types "{\"UseDomainForHTTP\": false, \"urls\": true}", "{\"UseDomainForHTTP\": 'abc', \"urls\": []}" }; // ensure we can delete test file CPPUNIT_ASSERT(bpf::safeRemove(m_path)); for (unsigned int i = 0; i < sizeof(badJson) / sizeof(badJson[0]); i++) { std::string bj(badJson[i]); // ensure we can write test file CPPUNIT_ASSERT(bp::strutil::storeToFile(m_path, bj)); // now try to parse that crap bp::URLCollection coll; CPPUNIT_ASSERT(coll.init(m_path) == false); // after a failed init, other functions should fail too CPPUNIT_ASSERT(coll.add("http://www.yahoo.com") == false); CPPUNIT_ASSERT(coll.has("http://www.yahoo.com") == false); // ensure we can delete test file CPPUNIT_ASSERT(bpf::safeRemove(m_path)); } // now as a sanity check, let's try some valid json { std::string gj("{\"UseDomainForHTTP\": false, \"urls\": []}"); // ensure we can write test file CPPUNIT_ASSERT(bp::strutil::storeToFile(m_path, gj)); // now try to parse that crap bp::URLCollection coll; CPPUNIT_ASSERT(coll.init(m_path)); // after a failed init, other functions should fail too CPPUNIT_ASSERT(coll.add("http://www.yahoo.com")); CPPUNIT_ASSERT(coll.has("http://www.yahoo.com")); // ensure we can delete test file CPPUNIT_ASSERT(bpf::safeRemove(m_path)); } }
/** Matrix inversion via the Gauss-Jordan algorithm. */ static elem_t* invert_matrix(const elem_t* const a, const int n) { int i, j; elem_t* const inv = new_matrix(n, n); elem_t* const tmp = new_matrix(n, 2*n); copy_matrix(a, n, n, 0, n, 0, n, tmp, n, 2 * n, 0, n, 0, n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) tmp[i * 2 * n + n + j] = (i == j); gj(tmp, n, 2*n); copy_matrix(tmp, n, 2*n, 0, n, n, 2*n, inv, n, n, 0, n, 0, n); delete_matrix(tmp); return inv; }