@Test public void testBandMatrix() { System.out.println("BandMatrix"); double[][] A = { {0.9000, 0.4000, 0.0000}, {0.4000, 0.5000, 0.3000}, {0.0000, 0.3000, 0.8000} }; double[] b = {0.5, 0.5, 0.5}; Matrix a = new Matrix(A); Matrix.LU lu = a.lu(); double[] x = lu.solve(b); BandMatrix band = new BandMatrix(3, 3, 1, 1); for (int i = 0; i < A.length; i++) { for (int j = 0; j < A[i].length; j++) { if (A[i][j] != 0.0f) { band.set(i, j, A[i][j]); } } } double[] y = a.mv(x); double[] y2 = band.mv(x); for (int i = 0; i < y.length; i++) { assertEquals(y[i], y2[i], 1E-7f); } y = a.tv(x); y2 = band.tv(x); for (int i = 0; i < y.length; i++) { assertEquals(y[i], y2[i], 1E-7f); } BandMatrix.LU bandlu = band.lu(); double[] lux = bandlu.solve(b); assertEquals(lu.det(), bandlu.det(), 1E-7f); assertEquals(x.length, lux.length); for (int i = 0; i < x.length; i++) { assertEquals(x[i], lux[i], 1E-7f); } band.uplo(UPLO.UPPER); BandMatrix.Cholesky cholesky = band.cholesky(); double[] choleskyx = cholesky.solve(b); assertEquals(lu.det(), cholesky.det(), 1E-7f); assertEquals(choleskyx.length, x.length); for (int i = 0; i < x.length; i++) { assertEquals(x[i], choleskyx[i], 1E-6f); } band.uplo(UPLO.LOWER); cholesky = band.cholesky(); choleskyx = cholesky.solve(b); assertEquals(lu.det(), cholesky.det(), 1E-7f); assertEquals(choleskyx.length, x.length); for (int i = 0; i < x.length; i++) { assertEquals(x[i], choleskyx[i], 1E-6f); } }
public BandMatrix(int m, int n, int kl, int ku) { if (m <= 0 || n <= 0) { throw new IllegalArgumentException(String.format("Invalid matrix size: %d x %d", m, n)); } if (kl < 0 || ku < 0) { throw new IllegalArgumentException(String.format("Invalid subdiagonals or superdiagonals: kl = %d, ku = %d", kl, ku)); } if (kl >= m) { throw new IllegalArgumentException(String.format("Invalid subdiagonals %d >= %d", kl, m)); } if (ku >= n) { throw new IllegalArgumentException(String.format("Invalid superdiagonals %d >= %d", ku, n)); } this.m = m; this.n = n; this.kl = kl; this.ku = ku; this.ld = kl + ku + 1; this.AB = new double[ld * n]; }
BandMatrix extends DMatrix { public BandMatrix(int m, int n, int kl, int ku) { if (m <= 0 || n <= 0) { throw new IllegalArgumentException(String.format("Invalid matrix size: %d x %d", m, n)); } if (kl < 0 || ku < 0) { throw new IllegalArgumentException(String.format("Invalid subdiagonals or superdiagonals: kl = %d, ku = %d", kl, ku)); } if (kl >= m) { throw new IllegalArgumentException(String.format("Invalid subdiagonals %d >= %d", kl, m)); } if (ku >= n) { throw new IllegalArgumentException(String.format("Invalid superdiagonals %d >= %d", ku, n)); } this.m = m; this.n = n; this.kl = kl; this.ku = ku; this.ld = kl + ku + 1; this.AB = new double[ld * n]; } }
BandMatrix extends DMatrix { public BandMatrix(int m, int n, int kl, int ku) { if (m <= 0 || n <= 0) { throw new IllegalArgumentException(String.format("Invalid matrix size: %d x %d", m, n)); } if (kl < 0 || ku < 0) { throw new IllegalArgumentException(String.format("Invalid subdiagonals or superdiagonals: kl = %d, ku = %d", kl, ku)); } if (kl >= m) { throw new IllegalArgumentException(String.format("Invalid subdiagonals %d >= %d", kl, m)); } if (ku >= n) { throw new IllegalArgumentException(String.format("Invalid superdiagonals %d >= %d", ku, n)); } this.m = m; this.n = n; this.kl = kl; this.ku = ku; this.ld = kl + ku + 1; this.AB = new double[ld * n]; } BandMatrix(int m, int n, int kl, int ku);  BandMatrix(int m, int n, int kl, int ku, double[][] AB); }
BandMatrix extends DMatrix { public BandMatrix(int m, int n, int kl, int ku) { if (m <= 0 || n <= 0) { throw new IllegalArgumentException(String.format("Invalid matrix size: %d x %d", m, n)); } if (kl < 0 || ku < 0) { throw new IllegalArgumentException(String.format("Invalid subdiagonals or superdiagonals: kl = %d, ku = %d", kl, ku)); } if (kl >= m) { throw new IllegalArgumentException(String.format("Invalid subdiagonals %d >= %d", kl, m)); } if (ku >= n) { throw new IllegalArgumentException(String.format("Invalid superdiagonals %d >= %d", ku, n)); } this.m = m; this.n = n; this.kl = kl; this.ku = ku; this.ld = kl + ku + 1; this.AB = new double[ld * n]; } BandMatrix(int m, int n, int kl, int ku);  BandMatrix(int m, int n, int kl, int ku, double[][] AB); @Override BandMatrix clone(); @Override int nrows(); @Override int ncols(); @Override long size(); int kl(); int ku(); Layout layout(); int ld(); boolean isSymmetric(); BandMatrix uplo(UPLO uplo); UPLO uplo(); @Override boolean equals(Object o); boolean equals(BandMatrix o, double eps); @Override double get(int i, int j); @Override BandMatrix set(int i, int j, double x); @Override void mv(Transpose trans, double alpha, double[] x, double beta, double[] y); @Override void mv(double[] work, int inputOffset, int outputOffset); @Override void tv(double[] work, int inputOffset, int outputOffset); LU lu(); Cholesky cholesky(); }
BandMatrix extends DMatrix { public BandMatrix(int m, int n, int kl, int ku) { if (m <= 0 || n <= 0) { throw new IllegalArgumentException(String.format("Invalid matrix size: %d x %d", m, n)); } if (kl < 0 || ku < 0) { throw new IllegalArgumentException(String.format("Invalid subdiagonals or superdiagonals: kl = %d, ku = %d", kl, ku)); } if (kl >= m) { throw new IllegalArgumentException(String.format("Invalid subdiagonals %d >= %d", kl, m)); } if (ku >= n) { throw new IllegalArgumentException(String.format("Invalid superdiagonals %d >= %d", ku, n)); } this.m = m; this.n = n; this.kl = kl; this.ku = ku; this.ld = kl + ku + 1; this.AB = new double[ld * n]; } BandMatrix(int m, int n, int kl, int ku);  BandMatrix(int m, int n, int kl, int ku, double[][] AB); @Override BandMatrix clone(); @Override int nrows(); @Override int ncols(); @Override long size(); int kl(); int ku(); Layout layout(); int ld(); boolean isSymmetric(); BandMatrix uplo(UPLO uplo); UPLO uplo(); @Override boolean equals(Object o); boolean equals(BandMatrix o, double eps); @Override double get(int i, int j); @Override BandMatrix set(int i, int j, double x); @Override void mv(Transpose trans, double alpha, double[] x, double beta, double[] y); @Override void mv(double[] work, int inputOffset, int outputOffset); @Override void tv(double[] work, int inputOffset, int outputOffset); LU lu(); Cholesky cholesky();  }