/** * Factory method for creating unit Matrix instances with coefficients in a certain SemiRing. * * @param sr a SemiRing instance. Used to get one and zero. * @return a new unit square matrix. */ public static Matrix one(int dim, SemiRing sr) { Matrix m = new Matrix(dim); for (int i = 0; i < dim; i++) for (int j = 0; j < dim; j++) m.matrix[i][j] = (i == j) ? sr.one() : sr.zero(); return m; }
/** * Factory method for creating Matrix instances with coefficients in a certain SemiRing. * * @param sr a SemiRing instance. Used to get one and zero. * @return a new zero matrix. */ public static Matrix zero(int line, int col, SemiRing sr) { Matrix m = new Matrix(line, col); for (int i = 0; i < line; i++) for (int j = 0; j < col; j++) m.matrix[i][j] = sr.zero(); return m; }