1 2 package JSci.maths.matrices; 3 4 import java.awt.Dimension ; 5 import java.util.Hashtable ; 6 import JSci.maths.algebras.Algebra; 7 import JSci.maths.fields.Ring; 8 import JSci.maths.groups.AbelianGroup; 9 10 public final class DoubleMatrixAlgebra implements Algebra, Ring { 11 private static final Hashtable algebras = new Hashtable (); 12 static DoubleMatrixAlgebra get(int rows, int cols) { 13 Dimension dim = new Dimension (rows, cols); 14 DoubleMatrixAlgebra algebra = (DoubleMatrixAlgebra) algebras.get(dim); 15 if(algebra == null) { 16 algebra = new DoubleMatrixAlgebra(rows, cols); 17 algebras.put(dim, algebra); 18 } 19 return algebra; 20 } 21 22 private final int rows; 23 private final int cols; 24 private AbstractDoubleMatrix zero; 25 private AbstractDoubleSquareMatrix one; 26 private DoubleMatrixAlgebra(int rows, int cols) { 27 this.rows = rows; 28 this.cols = cols; 29 } 30 33 public Ring.Member one() { 34 if(one == null) 35 one = DoubleDiagonalMatrix.identity(cols); 36 return one; 37 } 38 public boolean isOne(Ring.Member r) { 39 return one().equals(r); 40 } 41 public AbelianGroup.Member zero() { 42 if(zero == null) 43 zero = new DoubleMatrix(rows, cols); 44 return zero; 45 } 46 public boolean isZero(AbelianGroup.Member r) { 47 return zero().equals(r); 48 } 49 public boolean isNegative(AbelianGroup.Member a, AbelianGroup.Member b) { 50 return zero().equals(a.add(b)); 51 } 52 } 53 | Popular Tags |