-
-def _random_matrix(dims):
- """
- Generate a random square (``dims``-by-``dims``) matrix. This is used
- only by the :class:`SymmetricLinearGameTest` class.
- """
- return matrix([[uniform(-10, 10) for i in range(dims)]
- for j in range(dims)])
-
-def _random_nonnegative_matrix(dims):
- """
- Generate a random square (``dims``-by-``dims``) matrix with
- nonnegative entries. This is used only by the
- :class:`SymmetricLinearGameTest` class.
- """
- L = _random_matrix(dims)
- return matrix([abs(entry) for entry in L], (dims, dims))
-
-def _random_diagonal_matrix(dims):
- """
- Generate a random square (``dims``-by-``dims``) matrix with nonzero
- entries only on the diagonal. This is used only by the
- :class:`SymmetricLinearGameTest` class.
- """
- return matrix([[uniform(-10, 10)*int(i == j) for i in range(dims)]
- for j in range(dims)])
-
-
-def _random_skew_symmetric_matrix(dims):
- """
- Generate a random skew-symmetrix (``dims``-by-``dims``) matrix.
-
- Examples
- --------
-
- >>> from dunshire.matrices import norm
- >>> A = _random_skew_symmetric_matrix(randint(1, 10))
- >>> norm(A + A.trans()) < options.ABS_TOL
- True
-
- """
- strict_ut = [[uniform(-10, 10)*int(i < j) for i in range(dims)]
- for j in range(dims)]
-
- strict_ut = matrix(strict_ut, (dims, dims))
- return strict_ut - strict_ut.trans()
-
-
-def _random_lyapunov_like_icecream(dims):
- """
- Generate a random Lyapunov-like matrix over the ice-cream cone in
- ``dims`` dimensions.
- """
- a = matrix([uniform(-10, 10)], (1, 1))
- b = matrix([uniform(-10, 10) for idx in range(dims-1)], (dims-1, 1))
- D = _random_skew_symmetric_matrix(dims-1) + a*identity(dims-1)
- row1 = append_col(a, b.trans())
- row2 = append_col(b, D)
- return append_row(row1, row2)
-
-
-def _random_orthant_params():
- """
- Generate the ``L``, ``K``, ``e1``, and ``e2`` parameters for a
- random game over the nonnegative orthant. This is only used by
- the :class:`SymmetricLinearGameTest` class.
- """
- ambient_dim = randint(1, 10)
- K = NonnegativeOrthant(ambient_dim)
- e1 = [uniform(0.5, 10) for idx in range(K.dimension())]
- e2 = [uniform(0.5, 10) for idx in range(K.dimension())]
- L = _random_matrix(K.dimension())
- return (L, K, matrix(e1), matrix(e2))
-
-
-def _random_icecream_params():
- """
- Generate the ``L``, ``K``, ``e1``, and ``e2`` parameters for a
- random game over the ice cream cone. This is only used by
- the :class:`SymmetricLinearGameTest` class.
- """
- # Use a minimum dimension of two to avoid divide-by-zero in
- # the fudge factor we make up later.
- ambient_dim = randint(2, 10)
- K = IceCream(ambient_dim)
- e1 = [1] # Set the "height" of e1 to one
- e2 = [1] # And the same for e2
-
- # If we choose the rest of the components of e1,e2 randomly
- # between 0 and 1, then the largest the squared norm of the
- # non-height part of e1,e2 could be is the 1*(dim(K) - 1). We
- # need to make it less than one (the height of the cone) so
- # that the whole thing is in the cone. The norm of the
- # non-height part is sqrt(dim(K) - 1), and we can divide by
- # twice that.
- fudge_factor = 1.0 / (2.0*sqrt(K.dimension() - 1.0))
- e1 += [fudge_factor*uniform(0, 1) for idx in range(K.dimension() - 1)]
- e2 += [fudge_factor*uniform(0, 1) for idx in range(K.dimension() - 1)]
- L = _random_matrix(K.dimension())
-
- return (L, K, matrix(e1), matrix(e2))
-
+from .randomgen import (RANDOM_MAX, random_icecream_game,
+ random_ll_icecream_game, random_ll_orthant_game,
+ random_nn_scaling, random_orthant_game,
+ random_positive_orthant_game, random_translation)
+
+EPSILON = (1 + RANDOM_MAX)*options.ABS_TOL
+"""
+This is the tolerance constant including fudge factors that we use to
+determine whether or not two numbers are equal in tests.
+
+Often we will want to compare two solutions, say for games that are
+equivalent. If the first game value is low by ``ABS_TOL`` and the second
+is high by ``ABS_TOL``, then the total could be off by ``2*ABS_TOL``. We
+also subject solutions to translations and scalings, which adds to or
+scales their error. If the first game is low by ``ABS_TOL`` and the
+second is high by ``ABS_TOL`` before scaling, then after scaling, the
+second could be high by ``RANDOM_MAX*ABS_TOL``. That is the rationale
+for the factor of ``1 + RANDOM_MAX`` in ``EPSILON``. Since ``1 +
+RANDOM_MAX`` is greater than ``2*ABS_TOL``, we don't need to handle the
+first issue mentioned (both solutions off by the same amount in opposite
+directions).
+"""