/** * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix1D</tt> the new matrix must be of type <tt>DenseObjectMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix1D</tt> the new matrix must be of type <tt>SparseObjectMatrix2D</tt>, etc. * * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public ObjectMatrix2D like2D(int rows, int columns) { return new DenseObjectMatrix2D(rows,columns); } /**
/** * Constructs a matrix with a copy of the given values. * <tt>values</tt> is required to have the form <tt>values[row][column]</tt> * and have exactly the same number of columns in every row. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values The values to be filled into the new matrix. * @throws IllegalArgumentException if <tt>for any 1 <= row < values.length: values[row].length != values[row-1].length</tt>. */ public DenseObjectMatrix2D(Object[][] values) { this(values.length, values.length==0 ? 0: values[0].length); assign(values); } /**
/** * Constructs a matrix with a given number of rows and columns. * All entries are initially <tt>0</tt>. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (Object)columns*rows > Integer.MAX_VALUE</tt>. */ public DenseObjectMatrix2D(int rows, int columns) { setUp(rows, columns); this.elements = new Object[rows*columns]; } /**
checkShape(other); if (haveSharedCells(other)) { ObjectMatrix2D c = other.copy(); if (! (c instanceof DenseObjectMatrix2D)) { // should not happen return super.assign(other); int ors = other.rowStride; int otherIndex = other.index(0,0); int index = index(0,0); for (int row=rows; --row >= 0; ) { for (int i=index, j=otherIndex, column=columns; --column >= 0; ) {
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the form <tt>values[row][column]</tt> * and have exactly the same number of rows and columns as the receiver. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values the values to be filled into the cells. * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>values.length != rows() || for any 0 <= row < rows(): values[row].length != columns()</tt>. */ public ObjectMatrix2D assign(Object[][] values) { if (this.isNoView) { if (values.length != rows) throw new IllegalArgumentException("Must have same number of rows: rows="+values.length+"rows()="+rows()); int i = columns*(rows-1); for (int row=rows; --row >= 0;) { Object[] currentRow = values[row]; if (currentRow.length != columns) throw new IllegalArgumentException("Must have same number of columns in every row: columns="+currentRow.length+"columns()="+columns()); System.arraycopy(currentRow, 0, this.elements, i, columns); i -= columns; } } else { super.assign(values); } return this; } /**
checkShape(y); int ors = other.rowStride; int otherIndex = other.index(0,0); int index = index(0,0);
final Object[] elems = this.elements; if (elems==null) throw new InternalError(); int index = index(0,0); int cs = this.columnStride; int rs = this.rowStride;
checkShape(other); if (haveSharedCells(other)) { ObjectMatrix2D c = other.copy(); if (! (c instanceof DenseObjectMatrix2D)) { // should not happen return super.assign(other); int ors = other.rowStride; int otherIndex = other.index(0,0); int index = index(0,0); for (int row=rows; --row >= 0; ) { for (int i=index, j=otherIndex, column=columns; --column >= 0; ) {
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the form <tt>values[row][column]</tt> * and have exactly the same number of rows and columns as the receiver. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values the values to be filled into the cells. * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>values.length != rows() || for any 0 <= row < rows(): values[row].length != columns()</tt>. */ public ObjectMatrix2D assign(Object[][] values) { if (this.isNoView) { if (values.length != rows) throw new IllegalArgumentException("Must have same number of rows: rows="+values.length+"rows()="+rows()); int i = columns*(rows-1); for (int row=rows; --row >= 0;) { Object[] currentRow = values[row]; if (currentRow.length != columns) throw new IllegalArgumentException("Must have same number of columns in every row: columns="+currentRow.length+"columns()="+columns()); System.arraycopy(currentRow, 0, this.elements, i, columns); i -= columns; } } else { super.assign(values); } return this; } /**
checkShape(y); int ors = other.rowStride; int otherIndex = other.index(0,0); int index = index(0,0);
final Object[] elems = this.elements; if (elems==null) throw new InternalError(); int index = index(0,0); int cs = this.columnStride; int rs = this.rowStride;
/** * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix1D</tt> the new matrix must be of type <tt>DenseObjectMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix1D</tt> the new matrix must be of type <tt>SparseObjectMatrix2D</tt>, etc. * * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public ObjectMatrix2D like2D(int rows, int columns) { return new DenseObjectMatrix2D(rows,columns); } /**
/** * Constructs a matrix with a given number of rows and columns. * All entries are initially <tt>0</tt>. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (Object)columns*rows > Integer.MAX_VALUE</tt>. */ public DenseObjectMatrix2D(int rows, int columns) { setUp(rows, columns); this.elements = new Object[rows*columns]; } /**
/** * Constructs a matrix with a copy of the given values. * <tt>values</tt> is required to have the form <tt>values[row][column]</tt> * and have exactly the same number of columns in every row. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa. * * @param values The values to be filled into the new matrix. * @throws IllegalArgumentException if <tt>for any 1 <= row < values.length: values[row].length != values[row-1].length</tt>. */ public DenseObjectMatrix2D(Object[][] values) { this(values.length, values.length==0 ? 0: values[0].length); assign(values); } /**
/** * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix1D</tt> the new matrix must be of type <tt>DenseObjectMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix1D</tt> the new matrix must be of type <tt>SparseObjectMatrix2D</tt>, etc. * * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public ObjectMatrix2D like2D(int rows, int columns) { return new DenseObjectMatrix2D(rows,columns); } /**
/** * Constructs a view with the given parameters. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @param elements the cells. * @param rowZero the position of the first element. * @param columnZero the position of the first element. * @param rowStride the number of elements between two rows, i.e. <tt>index(i+1,j)-index(i,j)</tt>. * @param columnStride the number of elements between two columns, i.e. <tt>index(i,j+1)-index(i,j)</tt>. * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (Object)columns*rows > Integer.MAX_VALUE</tt> or flip's are illegal. */ protected DenseObjectMatrix2D(int rows, int columns, Object[] elements, int rowZero, int columnZero, int rowStride, int columnStride) { setUp(rows,columns,rowZero,columnZero,rowStride,columnStride); this.elements = elements; this.isNoView = false; } /**
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of rows and columns. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix2D</tt> the new matrix must also be of type <tt>DenseObjectMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix2D</tt> the new matrix must also be of type <tt>SparseObjectMatrix2D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @return a new empty matrix of the same dynamic type. */ public ObjectMatrix2D like(int rows, int columns) { return new DenseObjectMatrix2D(rows, columns); } /**
/** * Constructs a view with the given parameters. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @param elements the cells. * @param rowZero the position of the first element. * @param columnZero the position of the first element. * @param rowStride the number of elements between two rows, i.e. <tt>index(i+1,j)-index(i,j)</tt>. * @param columnStride the number of elements between two columns, i.e. <tt>index(i,j+1)-index(i,j)</tt>. * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (Object)columns*rows > Integer.MAX_VALUE</tt> or flip's are illegal. */ protected DenseObjectMatrix2D(int rows, int columns, Object[] elements, int rowZero, int columnZero, int rowStride, int columnStride) { setUp(rows,columns,rowZero,columnZero,rowStride,columnStride); this.elements = elements; this.isNoView = false; } /**
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of rows and columns. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix2D</tt> the new matrix must also be of type <tt>DenseObjectMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix2D</tt> the new matrix must also be of type <tt>SparseObjectMatrix2D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @return a new empty matrix of the same dynamic type. */ public ObjectMatrix2D like(int rows, int columns) { return new DenseObjectMatrix2D(rows, columns); } /**
/** * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix1D</tt> the new matrix must be of type <tt>DenseObjectMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix1D</tt> the new matrix must be of type <tt>SparseObjectMatrix2D</tt>, etc. * * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public ObjectMatrix2D like2D(int rows, int columns) { return new DenseObjectMatrix2D(rows,columns); } /**