#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdio>
#include "linbox/util/commentator.h"
#include "linbox/util/field-axpy.h"
#include "linbox/vector/stream.h"
#include "linbox/vector/vector-domain.h"
#include "linbox/blackbox/dense.h"
#include "linbox/integer.h"
#include "test-common.h"
Generic field tests | |
| template<class Field> bool | testField (Field &F, const char *title) |
| template<class Field> bool | testFieldNegation (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testFieldInversion (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testFieldAxioms (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testFieldAssociativity (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testGeometricSummation (const Field &F, const char *name, unsigned int iterations, unsigned int n) |
| template<class Field> bool | testFieldCharacteristic (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testFreshmansDream (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testArithmeticConsistency (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testAxpyConsistency (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | testRanditerBasic (const Field &F, const char *name, unsigned int iterations) |
| template<class Field> bool | runFieldTests (const Field &F, const char *desc, unsigned int iterations, size_t n, bool runCharacteristicTest) |
Generic tests for black boxes | |
| template<class Field, class Blackbox, class Vector> bool | testTranspose (Field &F, Blackbox &A, LinBox::VectorStream< Vector > &stream1, LinBox::VectorStream< Vector > &stream2) |
| template<class Field, class BB, class Vector> bool | testLinearity (Field &F, BB &A, LinBox::VectorStream< Vector > &stream1, LinBox::VectorStream< Vector > &stream2) |
| template<class Field, class Blackbox> bool | testSmallBlackbox (Field &F, Blackbox &A) |
| template<class Field, class BB> bool | testBlackbox (Field &F, BB &A) |
| template<class Field, class Blackbox> bool | testBB (Field &F) |
Generic field tests | |
| template<class Field> bool | testRandomIterator (const Field &F, const char *text, unsigned int num_trials, unsigned int num_categories, unsigned int hist_len) |
| template<class Field> bool | testRandomIteratorStep (const Field &F, const char *text, unsigned int num_trials, unsigned int num_categories, unsigned int hist_len) |
Vector operation tests | |
| template<class Field, class Vector1, class Vector2> bool | testDotProduct (Field &F, const char *text, LinBox::VectorStream< Vector1 > &stream1, LinBox::VectorStream< Vector2 > &stream2) |
| template<class Field, class Vector> bool | testAddMul (Field &F, const char *text, LinBox::VectorStream< Vector > &stream1, LinBox::VectorStream< Vector > &stream2) |
| template<class Field, class Vector> bool | testSubMul (Field &F, const char *text, LinBox::VectorStream< Vector > &stream1, LinBox::VectorStream< Vector > &stream2) |
| template<class Field, class Vector> bool | testAXPY (Field &F, const char *text, LinBox::VectorStream< Vector > &stream1, LinBox::VectorStream< Vector > &stream2) |
| template<class Field, class Vector1, class Vector2> bool | testCopyEqual (Field &F, const char *text, LinBox::VectorStream< Vector1 > &stream, LinBox::VectorStream< Vector2 > &stream2) |
Functions | |
| template<class Field> Field::Element | expt (const Field &F, typename Field::Element &res, const typename Field::Element &a, LinBox::integer &n) |
|
||||||||||||||||||||
|
|
|
||||||||||||
|
Generic test 1: Test of field operations Test various field oeprations F - Field over which to perform computations title - String to use as the descriptive title of this test Return true on success and false on failure |
|
||||||||||||||||
|
Tests of algebraic properties of fields |
|
||||||||||||||||
|
Generic test 5: Inversion of elements Inverts random elements and checks that they are true inverses |
|
||||||||||||||||
|
Generic test 7: Commutativity and distributivity of addition and multiplication Given random field elements 'a', 'b', and 'c', checks that (a + b) * c = a * c + b * c = c * (a + b) = b * c + a * c |
|
||||||||||||||||
|
Generic test 7: Associativity of addition and multiplication Given random field elements 'a', 'b', and 'c', checks that (a * b) * c = a * (b * c) and (a + b) + c = a + (b + c) |
|
||||||||||||||||||||
|
Generic test 2: Geometric summation Generates a random field element 'a' and raises it through repeated exponentiation to the power n. Takes the sum k of all intermediate values and checks that a^n = (k-1)/(a-1). |
|
||||||||||||||||
|
Generic test 3: Test of field characteristic Take random field elements and add them p times, where p is the characteristic of the field. Checks that the sum is 0. The test is not too useful when the characteristic of the field is 0, but it should still work correctly. |
|
||||||||||||||||
|
Generic test 4: The Freshman's Dream Generates two random field elements 'a' and 'b', and checks whether (a + b)^p = a^p + b^p, where p is the characteristic of the field. Bails out with an error if the field is of characteristic 0. |
|
||||||||||||||||
|
Generic test 7: Consistency of in-place and out-of-place arithmetic Generates random elements 'a' and 'b' and performs all basic arithmetic operations in-place and out-of-place, checking for consistency |
|
||||||||||||||||
|
Generic test 8: Consistency of axpy Generates random elements 'a', 'x', and 'y' and checks that a * x + y is the same for axpy, axpyin, add/mul |
|
||||||||||||||||
|
Generic test 9: Basic concept check of RandIter In a loop, generates random element 'a', and fails if it is always zero. |
|
||||||||||||||||||||||||
|
|
|
||||||||||||||||||||
|
Generic Blackbox test 1: (u^T A) v = u^T (A v). Take the given black box and compute u^T A v via <A^T u, v> and <u, Av> for randomly chosen u and v. Check whether the results are equal. In theory, this should guarantee that tranpose is working correctly if apply and dot product are also working correctly. Apply and dot product should, of course, be independently checked. F - Field over which to perform computations A - Black box of which to construct the transpose iterations - Number of random vectors to which to apply matrix Return true on success and false on failure |
|
||||||||||||||||||||
|
Generic Blackbox test 2: Linearity of black boxes. Given an arbitrary black box A, compute A(x+alpha y) and Ax+alphaAy and check equality. F - Field over which to perform computations A - Black box of which to compute the dense representation stream1 - Stream for x's stream2 - Stream for y's Return true on success and false on failure |
|
||||||||||||
|
Generic blackbox test 3: compare to a dense matrix. An equivalent dense matrix B is obtained with n applies. Then it's behaviour is compared to A's. F - Field over which to perform computations A - Black box of which to compute the dense representation |
|
||||||||||||
|
Generic blackbox test 4: combination of tests Call testTranspose and testLinearity. If large, time apply and applyTranspose. if small, call testSmallBlackbox. |
|
|
Generic blackbox test 5: test several sizes Call testTranspose and testLinearity. If large, time apply and applyTranspose. if small, call testSmallBlackbox. |
|
||||||||||||||||||||||||
|
Random number test Test that the random iterator over the given field works. Test up to five times, accepting any one, to increase probability of passing statistical tests. |
|
||||||||||||||||||||||||
|
|
|
||||||||||||||||||||
|
Test 1: Dot product of vectors Construct two random vectors and compute their dot product F - Field over which to perform computations n - Dimension to which to make vectors stream1 - Stream for first family of vectors stream2 - Stream for second family of vectors Return true on success and false on failure |
|
||||||||||||||||||||
|
Test 2: Vector-vector addition, vector-scalar multiply Construct two random vectors x and y and a random element a and compute (x + a*y) and a*(y + a^-1*x) using vector add, sub, and mul. Check whether the results are equal. F - Field over which to perform computations n - Dimension to which to make vectors iterations - Number of iterations over which to run Return true on success and false on failure |
|
||||||||||||||||||||
|
Test 3: Vector-vector subtraction, vector-scalar multiply Construct two random vectors x and y and a random element a and compute (x - a*y) and a*(a^-1*x - y) using vector add, sub, and mul. Check whether the results are equal. F - Field over which to perform computations n - Dimension to which to make vectors iterations - Number of iterations over which to run Return true on success and false on failure |
|
||||||||||||||||||||
|
Test 4: Vector-vector axpy Construct two random vectors x and y and a random element a and compute (x + a*y) - a*(y + a^-1*x) using vector axpy. Check whether the result is 0. F - Field over which to perform computations n - Dimension to which to make vectors iterations - Number of iterations over which to run Return true on success and false on failure |
|
||||||||||||||||||||
|
Test 5: Copy and areEqual Constructs a random vector and copies it to another vector. Then checks equality. F - Field over which to perform computations text - Text to use for test stream - Stream generating vectors stream2 - Dummy stream of second vector type to trick the compiler Return true on success and false on failure |
1.3.7