int main(int argc, char* argv[]) { Teuchos::print_stack_on_segfault(); RCP<const Basic> x = rcp(new Symbol("x")); RCP<const Basic> y = rcp(new Symbol("y")); RCP<const Basic> z = rcp(new Symbol("z")); RCP<const Basic> w = rcp(new Symbol("w")); RCP<const Basic> i100 = rcp(new Integer(100)); RCP<const Basic> e, r; e = pow(add(add(pow(x, y), pow(y, x)), pow(z, x)), i100); std::cout << "Expanding: " << *e << std::endl; auto t1 = std::chrono::high_resolution_clock::now(); r = expand(e); auto t2 = std::chrono::high_resolution_clock::now(); //std::cout << *r << std::endl; std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << "ms" << std::endl; std::cout << "number of terms: " << rcp_dynamic_cast<const Add>(r)->dict_.size() << std::endl; return 0; }
void test_probab_prime_p() { RCP<const Integer> i1 = integer(1); RCP<const Integer> i5 = integer(5); RCP<const Integer> i6 = integer(6); assert(probab_prime_p(*i1) == 0); assert(probab_prime_p(*i5) == 2); assert(probab_prime_p(*i6) == 0); }
void test_factor() { RCP<const Integer> i2 = integer(2); RCP<const Integer> i3 = integer(3); RCP<const Integer> i6 = integer(6); RCP<const Integer> i17 = integer(17); RCP<const Integer> i31 = integer(31); RCP<const Integer> i121 = integer(121); RCP<const Integer> i122 = integer(122); RCP<const Integer> i1001 = integer(1001); RCP<const Integer> i900 = integer(900); RCP<const Integer> f; assert(factor(outArg(f), *i2) == 0); assert(factor(outArg(f), *i3) == 0); assert(factor(outArg(f), *i17) == 0); assert(factor(outArg(f), *i31) == 0); assert(factor(outArg(f), *i6) > 0); assert(divides(i6, f)); assert(factor(outArg(f), *i121) > 0); assert(divides(i121, f)); assert(factor(outArg(f), *i122) > 0); assert(divides(i122, f)); assert(factor(outArg(f), *i1001) > 0); assert(divides(i1001, f)); assert(!divides(i1001, i6)); assert(factor(outArg(f), *i900) > 0); assert(divides(i900, f)); }
void test_factor_lehman_method() { RCP<const Integer> i21 = integer(21); RCP<const Integer> i23 = integer(23); RCP<const Integer> i31 = integer(31); RCP<const Integer> i47 = integer(47); RCP<const Integer> i121 = integer(121); RCP<const Integer> i122 = integer(122); RCP<const Integer> i900 = integer(900); RCP<const Integer> i1001 = integer(1001); RCP<const Integer> f; assert(factor_lehman_method(outArg(f), *i23) == 0); assert(factor_lehman_method(outArg(f), *i31) == 0); assert(factor_lehman_method(outArg(f), *i47) == 0); assert(factor_lehman_method(outArg(f), *i21) > 0); assert(divides(i21, f)); assert(factor_lehman_method(outArg(f), *i121) > 0); assert(divides(i121, f)); assert(factor_lehman_method(outArg(f), *i122) > 0); assert(divides(i122, f)); assert(factor_lehman_method(outArg(f), *i900) > 0); assert(divides(i900, f)); assert(factor_lehman_method(outArg(f), *i1001) > 0); assert(divides(i1001, f)); }
void test_mul() { RCP<Basic> x = rcp(new Symbol("x")); RCP<Basic> y = rcp(new Symbol("y")); RCP<Basic> z = rcp(new Symbol("z")); RCP<Basic> w = rcp(new Symbol("w")); RCP<Basic> i2 = rcp(new Integer(2)); RCP<Basic> i3 = rcp(new Integer(3)); RCP<Basic> i4 = rcp(new Integer(4)); RCP<Basic> r1 = mul(x, y); RCP<Basic> r2 = pow(y, i2); map_basic_basic d; d[x] = y; assert(eq(r1->subs(d), r2)); d[x] = z; d[y] = w; r1 = mul(x, y); r2 = mul(z, w); assert(eq(r1->subs(d), r2)); d.clear(); d[mul(x, y)] = z; r1 = mul(x, y); r2 = z; assert(eq(r1->subs(d), r2)); d.clear(); d[pow(x, y)] = z; r1 = mul(i2, pow(x, y)); r2 = mul(i2, z); assert(eq(r1->subs(d), r2)); }
int main(int argc, char* argv[]) { print_stack_on_segfault(); test_monomial_mul(); test_expand(); return 0; }
void test_expand() { RCP<Basic> x = rcp(new Symbol("x")); RCP<Basic> y = rcp(new Symbol("y")); RCP<Basic> z = rcp(new Symbol("z")); RCP<Basic> w = rcp(new Symbol("w")); RCP<Basic> i4 = rcp(new Integer(2)); RCP<Basic> e, f1, f2, r; e = pow(add(add(add(x, y), z), w), i4); f1 = expand(e); f2 = expand(add(e, w)); Dict_int syms; syms[x] = rcp(new Integer(0)); syms[y] = rcp(new Integer(1)); syms[z] = rcp(new Integer(2)); syms[w] = rcp(new Integer(3)); umap_vec_mpz P1, P2, C; expr2poly(f1, syms, P1); expr2poly(f2, syms, P2); std::cout << "poly_mul start" << std::endl; auto t1 = std::chrono::high_resolution_clock::now(); poly_mul(P1, P2, C); auto t2 = std::chrono::high_resolution_clock::now(); std::cout << "poly_mul stop" << std::endl; /* std::cout << *e << std::endl; std::cout << *f1 << std::endl; std::cout << P1 << std::endl; std::cout << *f2 << std::endl; std::cout << P2 << std::endl; std::cout << "RESULT:" << std::endl; std::cout << C << std::endl; */ std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << "ms" << std::endl; }
int main(int argc, char* argv[]) { print_stack_on_segfault(); test_printing(); test_matrix(); return 0; }
void test_factorial() { RCP<const Integer> i1 = integer(1); assert(eq(factorial(1), i1)); assert(eq(factorial(0), i1)); assert(eq(factorial(5), integer(120))); assert(eq(factorial(9), integer(362880))); }
int main(int argc, char* argv[]) { print_stack_on_segfault(); test_symbol(); test_add(); test_mul(); test_pow(); test_trig(); return 0; }
int main(int argc, char* argv[]) { Teuchos::print_stack_on_segfault(); RCP<const Basic> x = rcp(new Symbol("x")); RCP<const Basic> a, c; int N; N = 3000; a = x; c = integer(1); auto t1 = std::chrono::high_resolution_clock::now(); for (int i = 0; i < N; i++) { a = add(a, mul(c, pow(x, integer(i)))); c = mul(c, integer(-1)); } auto t2 = std::chrono::high_resolution_clock::now(); //std::cout << *a << std::endl; std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << "ms" << std::endl; std::cout << "number of terms: " << rcp_dynamic_cast<const Add>(a)->dict_.size() << std::endl; return 0; }
void test_nextprime() { RCP<const Integer> i1 = integer(1); RCP<const Integer> i5 = integer(5); RCP<const Integer> i6 = integer(6); assert(eq(nextprime(*i1), integer(2))); assert(eq(nextprime(*i5), integer(7))); assert(eq(nextprime(*i6), integer(7))); }
int main(int argc, char* argv[]) { Teuchos::print_stack_on_segfault(); RCP<const Basic> e = sin(integer(1)); double r, r_exact; for(int i = 0; i < 10000; i++) e = pow(add(mul(add(e, pow(integer(2), integer(-3))), integer(3)), integer(1)), div(integer(2), integer(3))); // Too long: // std::cout << "Evaluating: " << *e << std::endl; auto t1 = std::chrono::high_resolution_clock::now(); for (int i = 0; i < 500; i++) r = eval_double(*e); auto t2 = std::chrono::high_resolution_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << "ms" << std::endl; /* In SymPy for few iterations: In [7]: sympify("(1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + (1 + 3*(1/8 + sin(1)))^(2/3)))^(2/3)))^(2/3)))^(2/3)))^(2/3)").n(20) Out[7]: 8.0152751504518535013 // r_exact = 8.0152751504518535013; Here is code to use SymPy for more iterations: In [5]: e = sin(1) In [6]: for i in range(10): ...: e = ((e+2**(-S(3)))*3 + 1)**(S(2)/3) ...: In [7]: e.n(20) Out[7]: 9.6473976427977306146 But unfortunately SymPy can't do more than perhaps 10 or 20 iterations, while we need to test ~10000. However, the numbers seem to converge to 9.85647... */ r_exact = 9.8564741713701043569; std::cout << "r (double) = " << r << std::endl; std::cout << "r (exact) = " << r_exact << std::endl; std::cout << "error = " << std::abs(r-r_exact) << std::endl; return 0; }
void test_monomial_mul() { vec_int a, b, c, d; a = {1, 2, 3, 4}; b = {2, 3, 2, 5}; c = {0, 0, 0, 0}; monomial_mul(a, b, c); d = {3, 5, 5, 9}; assert(c == d); d = {5, 6, 5, 5}; assert(c != d); umap_vec_mpz m; m[a] = 4; }
void test_binomial() { RCP<const Integer> i10 = integer(10); RCP<const Integer> i5 = integer(5); RCP<const Integer> i0 = integer(0); RCP<const Integer> m10 = integer(-10); assert(eq(binomial(*i10, 1), i10)); assert(eq(binomial(*i5, 2), i10)); assert(eq(binomial(*i5, 10), i0)); assert(eq(binomial(*i10, 11), i0)); assert(eq(binomial(*i10, 2), integer(45))); assert(eq(binomial(*m10, 3), integer(-220))); assert(eq(binomial(*m10, 2), integer(55))); }
void test_prime_factors() { RCP<const Integer> i0 = integer(0); RCP<const Integer> i1 = integer(1); RCP<const Integer> i5 = integer(5); RCP<const Integer> i6 = integer(6); RCP<const Integer> i12 = integer(12); RCP<const Integer> i36 = integer(36); RCP<const Integer> i125 = integer(125); RCP<const Integer> i1001 = integer(1001); _test_primefactors(i0, 0); _test_primefactors(i1, 0); _test_primefactors(i5, 1); _test_primefactors(i6, 2); _test_primefactors(i12, 3); _test_primefactors(i36, 4); _test_primefactors(i125, 3); _test_primefactors(i1001, 3); }
void test_modular_inverse() { RCP<const Integer> i5 = integer(5); RCP<const Integer> i3 = integer(3); RCP<const Integer> i8 = integer(8); RCP<const Integer> i11 = integer(11); RCP<const Integer> b; assert(mod_inverse(outArg(b), *i3, *i5) != 0); assert(eq(b, integer(2))); assert(mod_inverse(outArg(b), *i3, *i8) != 0); assert(eq(b, integer(3))); assert(mod_inverse(outArg(b), *i3, *i11) != 0); assert(eq(b, integer(4))); }
void test_symbol() { RCP<Basic> x = rcp(new Symbol("x")); RCP<Basic> y = rcp(new Symbol("y")); RCP<Basic> z = rcp(new Symbol("z")); RCP<Basic> w = rcp(new Symbol("w")); RCP<Basic> i2 = rcp(new Integer(2)); RCP<Basic> i3 = rcp(new Integer(3)); RCP<Basic> i4 = rcp(new Integer(4)); RCP<Basic> r1 = x; RCP<Basic> r2 = y; map_basic_basic d; d[x] = y; assert(eq(r1->subs(d), r2)); assert(neq(r1->subs(d), r1)); }
void _test_prime_factor_multiplicities(const RCP<const Integer> &a) { unsigned multiplicity; RCP<const Integer> _a = a; std::vector<RCP<const Integer>> primes; map_integer_uint prime_mul; prime_factor_multiplicities(a, prime_mul); for (auto it : prime_mul) { multiplicity = it.second; while(multiplicity) { _a = rcp_dynamic_cast<const Integer>(div(_a, it.first)); multiplicity--; } } assert(eq(_a, integer(1))); }
int main(int argc, char* argv[]) { print_stack_on_segfault(); test_gcd_lcm(); test_nextprime(); test_probab_prime_p(); test_modular_inverse(); test_fibonacci_lucas(); test_binomial(); test_factorial(); test_factor(); test_factor_lehman_method(); test_sieve(); test_prime_factors(); test_prime_factor_multiplicities(); return 0; }
void test_prime_factor_multiplicities() { RCP<const Integer> i2 = integer(2); RCP<const Integer> i3 = integer(3); RCP<const Integer> i6 = integer(6); RCP<const Integer> i12 = integer(12); RCP<const Integer> i36 = integer(36); RCP<const Integer> i125 = integer(125); RCP<const Integer> i2357 = integer(2357); _test_prime_factor_multiplicities(i2); _test_prime_factor_multiplicities(i3); _test_prime_factor_multiplicities(i6); _test_prime_factor_multiplicities(i12); _test_prime_factor_multiplicities(i36); _test_prime_factor_multiplicities(i125); _test_prime_factor_multiplicities(i2357); }
void test_add() { RCP<Basic> x = rcp(new Symbol("x")); RCP<Basic> y = rcp(new Symbol("y")); RCP<Basic> z = rcp(new Symbol("z")); RCP<Basic> w = rcp(new Symbol("w")); RCP<Basic> i2 = rcp(new Integer(2)); RCP<Basic> i3 = rcp(new Integer(3)); RCP<Basic> i4 = rcp(new Integer(4)); RCP<Basic> r1 = add(x, y); RCP<Basic> r2 = mul(i2, y); map_basic_basic d; d[x] = y; assert(eq(r1->subs(d), r2)); d[x] = z; d[y] = w; r1 = add(x, y); r2 = add(z, w); assert(eq(r1->subs(d), r2)); d.clear(); d[add(x, y)] = z; r1 = add(x, y); r2 = z; assert(eq(r1->subs(d), r2)); d.clear(); d[pow(x, y)] = z; d[pow(x, i2)] = y; d[pow(i2, y)] = x; r1 = add(add(pow(x, y), pow(x, i2)), pow(i2, y)); r2 = add(add(x, y), z); assert(eq(r1->subs(d), r2)); r1 = add(add(add(add(pow(x, y), pow(x, i2)), pow(i2, y)), x), i3); r2 = add(add(add(mul(i2, x), y), z), i3); assert(eq(r1->subs(d), r2)); }
int main(int argc, char* argv[]) { print_stack_on_segfault(); RCP<const Basic> x = rcp(new Symbol("x")); RCP<const Basic> y = rcp(new Symbol("y")); RCP<const Basic> z = rcp(new Symbol("z")); RCP<const Basic> w = rcp(new Symbol("w")); RCP<const Basic> i15 = rcp(new Integer(15)); RCP<const Basic> e, f1, f2, r; e = pow(add(add(add(x, y), z), w), i15); f1 = expand(e); f2 = expand(add(e, w)); umap_basic_int syms; insert(syms, x, rcp(new Integer(0))); insert(syms, y, rcp(new Integer(1))); insert(syms, z, rcp(new Integer(2))); insert(syms, w, rcp(new Integer(3))); umap_vec_mpz P1, P2, C; expr2poly(f1, syms, P1); expr2poly(f2, syms, P2); std::cout << "poly_mul start" << std::endl; auto t1 = std::chrono::high_resolution_clock::now(); poly_mul(P1, P2, C); auto t2 = std::chrono::high_resolution_clock::now(); std::cout << "poly_mul stop" << std::endl; /* std::cout << *e << std::endl; std::cout << *f1 << std::endl; std::cout << P1 << std::endl; std::cout << *f2 << std::endl; std::cout << P2 << std::endl; std::cout << "RESULT:" << std::endl; std::cout << C << std::endl; */ std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << "ms" << std::endl; std::cout << "number of terms: " << C.size() << std::endl; return 0; }
void test_printing() { RCP<const Basic> r, r1, r2; RCP<const Integer> i = integer(-1); RCP<const Symbol> x = symbol("x"); RCP<const Symbol> y = symbol("y"); r = div(integer(12), pow(integer(196), div(integer(1), integer(2)))); assert(r->__str__() == "(3/49)*196^(1/2)"); r = mul(integer(12), pow(integer(196), div(integer(1), integer(2)))); assert(r->__str__() == "12*196^(1/2)"); r = mul(integer(23), mul(pow(integer(5), div(integer(1), integer(2))), pow(integer(7), div(integer(1), integer(2))))); assert(r->__str__() == "23*5^(1/2)*7^(1/2)"); r = mul(integer(2), pow(symbol("x"), integer(2))); assert(r->__str__() == "2*x^2"); r1 = mul(integer(12), pow(integer(196), div(integer(-1), integer(2)))); r2 = mul(integer(294), pow(integer(196), div(integer(-1), integer(2)))); r = add(integer(-51), mul(r1, r2)); assert(r->__str__() == "-33"); r1 = mul(x, i); r2 = mul(r1, y); assert(r1->__str__() == "-x"); assert(r1->__str__() != "-1x"); assert(r2->__str__() == "-x*y"); assert(r2->__str__() != "-1x*y"); r = mul(integer(-1), pow(integer(196), div(integer(1), integer(2)))); assert(r->__str__() == "-196^(1/2)"); r = pow(integer(-6), div(integer(1), integer(2))); assert(r->__str__() == "(-6)^(1/2)"); RCP<const Number> rn1, rn2, rn3, c1, c2; rn1 = Rational::from_two_ints(integer(2), integer(4)); rn2 = Rational::from_two_ints(integer(5), integer(7)); rn3 = Rational::from_two_ints(integer(-5), integer(7)); c1 = Complex::from_two_rats(static_cast<const Rational&>(*rn1), static_cast<const Rational&>(*rn2)); c2 = Complex::from_two_rats(static_cast<const Rational&>(*rn1), static_cast<const Rational&>(*rn3)); r1 = mul(c1, x); r2 = mul(c2, x); assert(c1->__str__() == "1/2 + 5/7*I"); assert(c2->__str__() == "1/2 - 5/7*I"); assert(r1->__str__() == "(1/2 + 5/7*I)*x"); assert(r2->__str__() == "(1/2 - 5/7*I)*x"); r1 = pow(x, c1); r2 = pow(x, c2); assert(r1->__str__() == "x^(1/2 + 5/7*I)"); assert(r2->__str__() == "x^(1/2 - 5/7*I)"); c1 = Complex::from_two_nums(*rn1, *rn2); c2 = Complex::from_two_nums(*rn1, *rn3); assert(c1->__str__() == "1/2 + 5/7*I"); assert(c2->__str__() == "1/2 - 5/7*I"); rn1 = Rational::from_two_ints(integer(0), integer(4)); c1 = Complex::from_two_nums(*rn1, *rn2); c2 = Complex::from_two_nums(*rn1, *rn3); r1 = mul(c1, x); r2 = mul(c2, x); assert(c1->__str__() == "5/7*I"); assert(c2->__str__() == "-5/7*I"); assert(r1->__str__() == "5/7*I*x"); assert(r2->__str__() == "-5/7*I*x"); r1 = pow(x, c1); r2 = pow(x, c2); assert(r1->__str__() == "x^(5/7*I)"); assert(r2->__str__() == "x^(-5/7*I)"); c1 = Complex::from_two_nums(*rn2, *rn1); c2 = Complex::from_two_nums(*rn3, *rn1); r1 = mul(c1, x); r2 = mul(c2, x); assert(c1->__str__() == "5/7"); assert(c2->__str__() == "-5/7"); assert(r1->__str__() == "(5/7)*x"); assert(r2->__str__() == "(-5/7)*x"); r1 = pow(x, c1); r2 = pow(x, c2); assert(r1->__str__() == "x^(5/7)"); assert(r2->__str__() == "x^(-5/7)"); rn1 = Rational::from_two_ints(integer(1), integer(1)); c1 = Complex::from_two_nums(*rn2, *rn1); assert(c1->__str__() == "5/7 + I"); rn1 = Rational::from_two_ints(integer(-1), integer(1)); c1 = Complex::from_two_nums(*rn2, *rn1); assert(c1->__str__() == "5/7 - I"); r1 = mul(c1, x); assert(r1->__str__() == "(5/7 - I)*x" ); r1 = mul(integer(2), x); assert(r1->__str__() == "2*x" ); r1 = mul(mul(integer(2), pow(symbol("x"), div(integer(2), integer(3)))), y); assert(r1->__str__() == "2*x^(2/3)*y" ); r1 = mul(x, y); assert(r1->__str__() == "x*y" ); }
void test_trig() { RCP<Basic> x = rcp(new Symbol("x")); RCP<Basic> y = rcp(new Symbol("y")); RCP<Basic> z = rcp(new Symbol("z")); RCP<Basic> w = rcp(new Symbol("w")); RCP<Basic> i2 = rcp(new Integer(2)); RCP<Basic> i3 = rcp(new Integer(3)); RCP<Basic> i4 = rcp(new Integer(4)); RCP<Basic> r1 = sin(x); RCP<Basic> r2 = zero; map_basic_basic d; d[x] = zero; assert(eq(r1->subs(d), r2)); r1 = cos(x); r2 = one; assert(eq(r1->subs(d), r2)); d[x] = y; r1 = sin(pow(x, i2)); r2 = sin(pow(y, i2)); assert(eq(r1->subs(d), r2)); d.clear(); d[sin(x)] = z; r1 = sin(x); r2 = z; assert(eq(r1->subs(d), r2)); r1 = mul(i2, sin(x)); r2 = mul(i2, z); assert(eq(r1->subs(d), r2)); }
void test_matrix() { DenseMatrix A = DenseMatrix(2, 2, {integer(1), integer(0), integer(0), integer(1)}); assert(A.__str__() == "[1, 0]\n[0, 1]\n"); }
void test_fibonacci_lucas() { RCP<const Integer> g; RCP<const Integer> s; assert(eq(fibonacci(1), integer(1))); assert(eq(fibonacci(2), integer(1))); assert(eq(fibonacci(3), integer(2))); assert(eq(fibonacci(5), integer(5))); assert(eq(lucas(1), integer(1))); assert(eq(lucas(2), integer(3))); assert(eq(lucas(3), integer(4))); assert(eq(lucas(5), integer(11))); fibonacci2(outArg(g), outArg(s), 10); assert(eq(g, integer(55))); assert(eq(s, integer(34))); lucas2(outArg(g), outArg(s), 10); assert(eq(g, integer(123))); assert(eq(s, integer(76))); }
void test_gcd_lcm() { RCP<const Integer> i2 = integer(2); RCP<const Integer> i3 = integer(3); RCP<const Integer> i4 = integer(4); RCP<const Integer> i6 = integer(6); RCP<const Integer> g = integer(2); RCP<const Integer> s = integer(2); RCP<const Integer> t = integer(3); assert(eq(gcd(*i2, *i4), integer(2))); assert(eq(gcd(*i2, *i3), integer(1))); assert(eq(gcd(*i2, *i6), integer(2))); assert(eq(gcd(*i3, *i6), integer(3))); assert(eq(lcm(*i2, *i4), integer(4))); assert(eq(lcm(*i2, *i3), integer(6))); assert(eq(lcm(*i2, *i6), integer(6))); assert(eq(lcm(*i3, *i6), integer(6))); gcd_ext(outArg(g), outArg(s), outArg(t), *i2, *i3); assert(eq(g, integer(1))); assert(eq(g, add(mul(i2, s), mul(i3, t)))); // check if g = i2*s + i3*t gcd_ext(outArg(g), outArg(s), outArg(t), *i3, *i6); assert(eq(g, integer(3))); assert(eq(g, add(mul(i3, s), mul(i6, t)))); // check if g = i3*s + i6*t }
int main(int argc, char* argv[]) { Teuchos::print_stack_on_segfault(); DenseMatrix A = DenseMatrix(3, 3, {symbol("a"), symbol("b"), symbol("c"), symbol("d"), symbol("e"), symbol("f"), symbol("g"), symbol("h"), symbol("i")}); DenseMatrix B = DenseMatrix(3, 3, {symbol("x"), symbol("y"), symbol("z"), symbol("p"), symbol("q"), symbol("r"), symbol("u"), symbol("v"), symbol("w")}); DenseMatrix C(3, 3); std::cout << "Adding Two Matrices; matrix dimensions: 3 x 3" << std::endl; // We are taking an average time since time for a single addition varied in // a range of 40-50 microseconds unsigned N = 10000; auto t1 = std::chrono::high_resolution_clock::now(); for (unsigned i = 0; i < N; i++) add_dense_dense(A, B, C); auto t2 = std::chrono::high_resolution_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::microseconds>(t2-t1).count()/N << " microseconds" << std::endl; return 0; }
int main(int argc, char* argv[]) { Teuchos::print_stack_on_segfault(); DenseMatrix A = DenseMatrix(4, 4, {integer(1), integer(2), integer(3), integer(4), integer(5), integer(6), integer(7), integer(8), integer(9), integer(10), integer(11), integer(12), integer(13), integer(14), integer(15), integer(16)}); DenseMatrix B = DenseMatrix(4, 4, {integer(1), integer(2), integer(3), integer(4), integer(5), integer(6), integer(7), integer(8), integer(9), integer(10), integer(11), integer(12), integer(13), integer(14), integer(15), integer(16)}); DenseMatrix C(4, 4); std::cout << "Adding Two Matrices; matrix dimensions: 4 x 4" << std::endl; // We are taking an average time since time for a single addition varied in // a range of 40-50 microseconds unsigned N = 10000; auto t1 = std::chrono::high_resolution_clock::now(); for (unsigned i = 0; i < N; i++) add_dense_dense(A, B, C); auto t2 = std::chrono::high_resolution_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::microseconds>(t2-t1).count()/N << " microseconds" << std::endl; return 0; }