public void solveModel() { int n = 5; IElementalAccessMatrix A = new SparseRowMatrix(n, n, 5); IElementalAccessVector b = new DenseVector(n), x = new DenseVector(n); x.SetValue(0, 0.1); x.SetValue(1, 0.2); x.SetValue(2, 0.3); x.SetValue(3, 0.4); x.SetValue(4, 0.5); b = new DenseVector(x.Length); for (int it = 0; it < 100; it++) { model(b, x); grad(A, x); IElementalAccessVector dx = new DenseVector(n); ILinearSolver solver = new BiCGSolver(); IPreconditioner M = new IdentityPreconditioner(); DefaultLinearIteration iter = new DefaultLinearIteration(); iter.SetParameters(1e-10, 1e-50, 1e+5, 1000000); double[] ans = solve(A, b, dx, solver, M, iter); for (int i = 0; i < x.Length; i++) { x.AddValue(i, -0.2 * dx.GetValue(i)); } int iii = 1; } }
public TestSparseRowMatrix() { _a = new double[] { 1, 8, 2, 7, 2, 3, 6, 4 }; _ia = new int[] { 0, 2, 4, 6, 8 }; _ja = new int[] { 0, 2, 1, 3, 0, 2, 1, 3 }; vector = new Vector(new double[] { 2, 1, 1, 1 }); sparseRowMatrix = new SparseRowMatrix(_a, _ja, _ia); }
/// <remarks>"This test been excluded from test fixture by Igor Sukhov on 17.10.2007"</remarks> //[TestMethod] public virtual void SparseRowMatrix() { int n = TesterUtilities.getInt(nmax, _random), m = TesterUtilities.getInt(mmax, _random), nu = GetNu(n, m); IElementalAccessMatrix A = new SparseRowMatrix(n, m); repeatedAssembly(A, nu); }
[Test] public virtual void SparseRowMatrix() { Random r = new Random(); int n = Math.Max(TesterUtilities.getInt(nmax, r), 4); IElementalAccessMatrix A = new SparseRowMatrix(n, n, 3); IElementalAccessVector b = new DenseVector(n), x = new DenseVector(n); Helper1(A, b, x); }
public TestSparseRowMatrix(ITestOutputHelper testOutputHelper) { _a = new double[] { 1, 8, 2, 7, 2, 3, 6, 4 }; _ia = new int[] { 0, 2, 4, 6, 8 }; _ja = new int[] { 0, 2, 1, 3, 0, 2, 1, 3 }; vector = new Vector(new double[] { 2, 1, 1, 1 }); sparseRowMatrix = new SparseRowMatrix(_a, _ja, _ia); _testOutputHelper = testOutputHelper; }
public void SparseRowMatrix_TestForeach() { var a = new double[] { 1, 5, 2, 7, 5, 3, 7, 4 }; var ia = new int[] { 0, 2, 4, 6, 8 }; var ja = new int[] { 0, 2, 1, 3, 0, 2, 1, 3 }; SparseRowMatrix sparseRowMatrix = new SparseRowMatrix(a, ja, ia); //Assert.True(symmetricSparseRowMatrix.SequenceEqual(sparseRowMatrix)); Assert.True(new HashSet <(double, int, int)>(symmetricSparseRowMatrix).SetEquals(sparseRowMatrix)); }
/// <remarks>"This test been excluded from test fixture by Igor Sukhov on 17.10.2007"</remarks> //[TestMethod] public virtual void SparseRowTranspose() { int n = TesterUtilities.getInt(nmax, _random), m = TesterUtilities.getInt(mmax, _random), nu = GetNu(n, m); for (int i = 0; i < repeat; ++i) { IElementalAccessMatrix A = new SparseRowMatrix(n, m, nu); double[,] Am = TesterUtilities.SetAssembleRowMatrix(A, nu); TransposeCheck(A, Am); } }
public void SparseRowMatrixCheck() { SparseRowMatrix sm = new SparseRowMatrix(10, 100); Assert.Equal(0, sm.NonZeroValueCount); sm.At(8, 8, 0); Assert.Equal(0.0D, sm.At(8, 8)); // Should not insert a value Assert.Equal(0, sm.NonZeroValueCount); Assert.Equal(sm.rowLength(0), 0); Assert.Throws <IndexOutOfRangeException>(() => sm.rowLength(-2)); Assert.Throws <ArgumentOutOfRangeException>(() => sm.RowLengthSafe(-2)); Assert.Throws <IndexOutOfRangeException>(() => sm.rowLength(101)); Assert.Throws <ArgumentOutOfRangeException>(() => sm.RowLengthSafe(101)); }
public void Fill() { FillFunc fillFunc = (row, col) => { return((row + 1) + (col + 1)); }; sparseRowMatrix.Fill(fillFunc); _a = new double[] { 2, 4, 4, 6, 4, 6, 6, 8 }; _ia = new int[] { 0, 2, 4, 6, 8 }; _ja = new int[] { 0, 2, 1, 3, 0, 2, 1, 3 }; SparseRowMatrix sparseRow = new SparseRowMatrix(_a, _ja, _ia); Assert.True(new HashSet <(double, int, int)>(sparseRowMatrix).SetEquals(sparseRow)); }
public virtual void SparseRowMult() { int n = TesterUtilities.getInt(nmax, _random), m = TesterUtilities.getInt(mmax, _random), nu = GetNu(n, m); for (int i = 0; i < repeat; ++i) { IElementalAccessMatrix A = new SparseRowMatrix(n, m, nu); IElementalAccessVector x = new DenseVector(m), y = new DenseVector(n), z = new DenseVector(n); rowCheck(A, x, y, z, nu); } }