@Test
public final void testExternalSolver_random()
{
final DoubleMatrix2D matrix = DoubleFactory2D.sparse.make(size,size);
matrix.assign(randomGenerator);
final DoubleMatrix1D b = DoubleFactory1D.dense.make(size);
b.assign(randomGenerator);
final LSolver solver = new LSolver(matrix,DoubleFactory1D.dense.make(matrix.rows(), 0));
boolean singular = false;
try
{
solver.solveExternally();
}
catch(IllegalArgumentException ex)
{
if (ex.getMessage().contains("singular"))
singular = true;
else
throw ex;
}
if (!singular)
TestSolver.verifyAxb(solver);
LUDecompositionQuick coltSolver = new LUDecompositionQuick();
coltSolver.decompose(matrix);coltSolver.setLU(matrix);
DoubleMatrix1D vector = DoubleFactory1D.dense.make(matrix.rows(), 0);
try
{
coltSolver.solve(vector);
}
catch(IllegalArgumentException ex)
{
if (ex.getMessage().contains("singular"))
Assert.assertTrue(singular);
else
throw ex;
}
if (!singular)
{
for(int i=0;i<matrix.rows();++i)
Assert.assertEquals(solver.j_x[i], vector.getQuick(i),TestSolver.comparisonAccuracy);
TestSolver.verifyAxb(matrix,solver.toDoubleMatrix1D(),vector);
}
try
{
for(int i=0;i<matrix.rows();++i) solver.j_x[i]=0;
solver.solveUsingColt();
}
catch(IllegalArgumentException ex)
{
if (ex.getMessage().contains("singular"))
Assert.assertTrue(singular);
else
throw ex;
}
if (!singular)
{
for(int i=0;i<matrix.rows();++i)
Assert.assertEquals(solver.j_x[i], vector.getQuick(i),TestSolver.comparisonAccuracy);
TestSolver.verifyAxb(solver);
}
}