/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of slices, rows and columns. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix3D</tt> the new matrix must also be of type <tt>DenseObjectMatrix3D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix3D</tt> the new matrix must also be of type <tt>SparseObjectMatrix3D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param slices the number of slices the matrix shall have. * @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 ObjectMatrix3D like(int slices, int rows, int columns) { return new DenseObjectMatrix3D(slices,rows,columns); } /**
/** * Constructs a matrix with a copy of the given values. * <tt>values</tt> is required to have the form <tt>values[slice][row][column]</tt> * and have exactly the same number of rows in in every slice and exactly the same number of columns in 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 <= slice < values.length: values[slice].length != values[slice-1].length</tt>. * @throws IllegalArgumentException if <tt>for any 1 <= row < values[0].length: values[slice][row].length != values[slice][row-1].length</tt>. */ public DenseObjectMatrix3D(Object[][][] values) { this(values.length, (values.length==0 ? 0: values[0].length), (values.length==0 ? 0: values[0].length==0 ? 0 : values[0][0].length)); assign(values); } /**
/** * Constructs a matrix with a given number of slices, rows and columns. * All entries are initially <tt>0</tt>. * @param slices the number of slices the matrix shall have. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @throws IllegalArgumentException if <tt>(Object)slices*columns*rows > Integer.MAX_VALUE</tt>. * @throws IllegalArgumentException if <tt>slices<0 || rows<0 || columns<0</tt>. */ public DenseObjectMatrix3D(int slices, int rows, int columns) { setUp(slices,rows, columns); this.elements = new Object[slices*rows*columns]; } /**
checkShape(other); if (haveSharedCells(other)) { ObjectMatrix3D c = other.copy(); if (! (c instanceof DenseObjectMatrix3D)) { // should not happen return super.assign(source);
if (values.length != slices) throw new IllegalArgumentException("Must have same number of slices: slices="+values.length+"slices()="+slices()); int i=slices*rows*columns - columns; for (int slice=slices; --slice >= 0;) { Object[][] currentSlice = values[slice]; if (currentSlice.length != rows) throw new IllegalArgumentException("Must have same number of rows in every slice: rows="+currentSlice.length+"rows()="+rows()); for (int row=rows; --row >= 0;) { Object[] currentRow = currentSlice[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;
checkShape(other); if (haveSharedCells(other)) { ObjectMatrix3D c = other.copy(); if (! (c instanceof DenseObjectMatrix3D)) { // should not happen return super.assign(source);
if (values.length != slices) throw new IllegalArgumentException("Must have same number of slices: slices="+values.length+"slices()="+slices()); int i=slices*rows*columns - columns; for (int slice=slices; --slice >= 0;) { Object[][] currentSlice = values[slice]; if (currentSlice.length != rows) throw new IllegalArgumentException("Must have same number of rows in every slice: rows="+currentSlice.length+"rows()="+rows()); for (int row=rows; --row >= 0;) { Object[] currentRow = currentSlice[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;
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of slices, rows and columns. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix3D</tt> the new matrix must also be of type <tt>DenseObjectMatrix3D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix3D</tt> the new matrix must also be of type <tt>SparseObjectMatrix3D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param slices the number of slices the matrix shall have. * @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 ObjectMatrix3D like(int slices, int rows, int columns) { return new DenseObjectMatrix3D(slices,rows,columns); } /**
/** * Constructs a matrix with a given number of slices, rows and columns. * All entries are initially <tt>0</tt>. * @param slices the number of slices the matrix shall have. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @throws IllegalArgumentException if <tt>(Object)slices*columns*rows > Integer.MAX_VALUE</tt>. * @throws IllegalArgumentException if <tt>slices<0 || rows<0 || columns<0</tt>. */ public DenseObjectMatrix3D(int slices, int rows, int columns) { setUp(slices,rows, columns); this.elements = new Object[slices*rows*columns]; } /**
/** * Constructs a matrix with a copy of the given values. * <tt>values</tt> is required to have the form <tt>values[slice][row][column]</tt> * and have exactly the same number of rows in in every slice and exactly the same number of columns in 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 <= slice < values.length: values[slice].length != values[slice-1].length</tt>. * @throws IllegalArgumentException if <tt>for any 1 <= row < values[0].length: values[slice][row].length != values[slice][row-1].length</tt>. */ public DenseObjectMatrix3D(Object[][][] values) { this(values.length, (values.length==0 ? 0: values[0].length), (values.length==0 ? 0: values[0].length==0 ? 0 : values[0][0].length)); assign(values); } /**
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of slices, rows and columns. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix3D</tt> the new matrix must also be of type <tt>DenseObjectMatrix3D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix3D</tt> the new matrix must also be of type <tt>SparseObjectMatrix3D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param slices the number of slices the matrix shall have. * @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 ObjectMatrix3D like(int slices, int rows, int columns) { return new DenseObjectMatrix3D(slices,rows,columns); } /**
/** * Constructs a view with the given parameters. * @param slices the number of slices the matrix shall have. * @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 sliceZero the position of the first element. * @param rowZero the position of the first element. * @param columnZero the position of the first element. * @param sliceStride the number of elements between two slices, i.e. <tt>index(k+1,i,j)-index(k,i,j)</tt>. * @param rowStride the number of elements between two rows, i.e. <tt>index(k,i+1,j)-index(k,i,j)</tt>. * @param columnnStride the number of elements between two columns, i.e. <tt>index(k,i,j+1)-index(k,i,j)</tt>. * @throws IllegalArgumentException if <tt>(Object)slices*columns*rows > Integer.MAX_VALUE</tt>. * @throws IllegalArgumentException if <tt>slices<0 || rows<0 || columns<0</tt>. */ protected DenseObjectMatrix3D(int slices, int rows, int columns, Object[] elements, int sliceZero, int rowZero, int columnZero, int sliceStride, int rowStride, int columnStride) { setUp(slices,rows,columns,sliceZero,rowZero,columnZero,sliceStride,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 slices, rows and columns. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix3D</tt> the new matrix must also be of type <tt>DenseObjectMatrix3D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix3D</tt> the new matrix must also be of type <tt>SparseObjectMatrix3D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param slices the number of slices the matrix shall have. * @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 ObjectMatrix3D like(int slices, int rows, int columns) { return new DenseObjectMatrix3D(slices,rows,columns); } /**
/** * Constructs a view with the given parameters. * @param slices the number of slices the matrix shall have. * @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 sliceZero the position of the first element. * @param rowZero the position of the first element. * @param columnZero the position of the first element. * @param sliceStride the number of elements between two slices, i.e. <tt>index(k+1,i,j)-index(k,i,j)</tt>. * @param rowStride the number of elements between two rows, i.e. <tt>index(k,i+1,j)-index(k,i,j)</tt>. * @param columnnStride the number of elements between two columns, i.e. <tt>index(k,i,j+1)-index(k,i,j)</tt>. * @throws IllegalArgumentException if <tt>(Object)slices*columns*rows > Integer.MAX_VALUE</tt>. * @throws IllegalArgumentException if <tt>slices<0 || rows<0 || columns<0</tt>. */ protected DenseObjectMatrix3D(int slices, int rows, int columns, Object[] elements, int sliceZero, int rowZero, int columnZero, int sliceStride, int rowStride, int columnStride) { setUp(slices,rows,columns,sliceZero,rowZero,columnZero,sliceStride,rowStride,columnStride); this.elements = elements; this.isNoView = false; } /**
/** * Constructs a matrix with the given shape, each cell initialized with zero. */ public ObjectMatrix3D make(int slices, int rows, int columns) { if (this==sparse) return new SparseObjectMatrix3D(slices,rows,columns); return new DenseObjectMatrix3D(slices,rows,columns); } /**
/** * Constructs a matrix with the given shape, each cell initialized with zero. */ public ObjectMatrix3D make(int slices, int rows, int columns) { if (this==sparse) return new SparseObjectMatrix3D(slices,rows,columns); return new DenseObjectMatrix3D(slices,rows,columns); } /**
/** * Constructs a matrix with the given cell values. * <tt>values</tt> is required to have the form <tt>values[slice][row][column]</tt> * and have exactly the same number of slices, 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 != slices() || for any 0 <= slice < slices(): values[slice].length != rows()</tt>. * @throws IllegalArgumentException if <tt>for any 0 <= column < columns(): values[slice][row].length != columns()</tt>. */ public ObjectMatrix3D make(Object[][][] values) { if (this==sparse) return new SparseObjectMatrix3D(values); return new DenseObjectMatrix3D(values); } /**
/** * Constructs a matrix with the given cell values. * <tt>values</tt> is required to have the form <tt>values[slice][row][column]</tt> * and have exactly the same number of slices, 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 != slices() || for any 0 <= slice < slices(): values[slice].length != rows()</tt>. * @throws IllegalArgumentException if <tt>for any 0 <= column < columns(): values[slice][row].length != columns()</tt>. */ public ObjectMatrix3D make(Object[][][] values) { if (this==sparse) return new SparseObjectMatrix3D(values); return new DenseObjectMatrix3D(values); } /**