/** * Construct and returns a new 1-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>DenseObjectMatrix2D</tt> the new matrix must be of type <tt>DenseObjectMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix2D</tt> the new matrix must be of type <tt>SparseObjectMatrix1D</tt>, etc. * * @param size the number of cells the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public ObjectMatrix1D like1D(int size) { return new DenseObjectMatrix1D(size); } /**
/** * Constructs a matrix with a copy of the given values. * 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. */ public DenseObjectMatrix1D(Object[] values) { this(values.length); assign(values); } /**
/** * Constructs a matrix with a given number of cells. * All entries are initially <tt>0</tt>. * @param size the number of cells the matrix shall have. * @throws IllegalArgumentException if <tt>size<0</tt>. */ public DenseObjectMatrix1D(int size) { setUp(size); this.elements = new Object[size]; } /**
checkSize(other); if (isNoView && other.isNoView) { // quickest System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length); return this; if (haveSharedCells(other)) { ObjectMatrix1D c = other.copy(); if (! (c instanceof DenseObjectMatrix1D)) { // should not happen return super.assign(source); int ys = other.stride; int index = index(0); int otherIndex = other.index(0); for (int k=size; --k >= 0; ) { elems[index] = otherElems[otherIndex];
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the same number of cells 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 != size()</tt>. */ public ObjectMatrix1D assign(Object[] values) { if (isNoView) { if (values.length != size) throw new IllegalArgumentException("Must have same number of cells: length="+values.length+"size()="+size()); System.arraycopy(values, 0, this.elements, 0, values.length); } else { super.assign(values); } return this; } /**
int i=index(0); Object[] elems = this.elements; if (elements==null) throw new InternalError();
checkSize(other); if (isNoView && other.isNoView) { // quickest System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length); return this; if (haveSharedCells(other)) { ObjectMatrix1D c = other.copy(); if (! (c instanceof DenseObjectMatrix1D)) { // should not happen return super.assign(source); int ys = other.stride; int index = index(0); int otherIndex = other.index(0); for (int k=size; --k >= 0; ) { elems[index] = otherElems[otherIndex];
/** * Sets all cells to the state specified by <tt>values</tt>. * <tt>values</tt> is required to have the same number of cells 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 != size()</tt>. */ public ObjectMatrix1D assign(Object[] values) { if (isNoView) { if (values.length != size) throw new IllegalArgumentException("Must have same number of cells: length="+values.length+"size()="+size()); System.arraycopy(values, 0, this.elements, 0, values.length); } else { super.assign(values); } return this; } /**
int i=index(0); Object[] elems = this.elements; if (elements==null) throw new InternalError();
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified size. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix1D</tt> the new matrix must also be of type <tt>DenseObjectMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix1D</tt> the new matrix must also be of type <tt>SparseObjectMatrix1D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param size the number of cell the matrix shall have. * @return a new empty matrix of the same dynamic type. */ public ObjectMatrix1D like(int size) { return new DenseObjectMatrix1D(size); } /**
/** * Constructs a matrix with a given number of cells. * All entries are initially <tt>0</tt>. * @param size the number of cells the matrix shall have. * @throws IllegalArgumentException if <tt>size<0</tt>. */ public DenseObjectMatrix1D(int size) { setUp(size); this.elements = new Object[size]; } /**
/** * Constructs a matrix with a copy of the given values. * 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. */ public DenseObjectMatrix1D(Object[] values) { this(values.length); assign(values); } /**
/** * Construct and returns a new 1-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>DenseObjectMatrix2D</tt> the new matrix must be of type <tt>DenseObjectMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix2D</tt> the new matrix must be of type <tt>SparseObjectMatrix1D</tt>, etc. * * @param size the number of cells the matrix shall have. * @return a new matrix of the corresponding dynamic type. */ public ObjectMatrix1D like1D(int size) { return new DenseObjectMatrix1D(size); } /**
/** * Constructs a matrix view with the given parameters. * @param size the number of cells the matrix shall have. * @param elements the cells. * @param zero the index of the first element. * @param stride the number of indexes between any two elements, i.e. <tt>index(i+1)-index(i)</tt>. * @throws IllegalArgumentException if <tt>size<0</tt>. */ protected DenseObjectMatrix1D(int size, Object[] elements, int zero, int stride) { setUp(size,zero,stride); 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 size. * For example, if the receiver is an instance of type <tt>DenseObjectMatrix1D</tt> the new matrix must also be of type <tt>DenseObjectMatrix1D</tt>, * if the receiver is an instance of type <tt>SparseObjectMatrix1D</tt> the new matrix must also be of type <tt>SparseObjectMatrix1D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @param size the number of cell the matrix shall have. * @return a new empty matrix of the same dynamic type. */ public ObjectMatrix1D like(int size) { return new DenseObjectMatrix1D(size); } /**
/** * Constructs a matrix view with the given parameters. * @param size the number of cells the matrix shall have. * @param elements the cells. * @param zero the index of the first element. * @param stride the number of indexes between any two elements, i.e. <tt>index(i+1)-index(i)</tt>. * @throws IllegalArgumentException if <tt>size<0</tt>. */ protected DenseObjectMatrix1D(int size, Object[] elements, int zero, int stride) { setUp(size,zero,stride); this.elements = elements; this.isNoView = false; } /**