/** * Sets all cells to the state specified by <tt>value</tt>. * @param value the value to be filled into the cells. * @return <tt>this</tt> (for convenience only). */ public ObjectMatrix1D assign(Object value) { for (int i=size; --i >= 0;) { setQuick(i,value); } return this; } /**
/** * Sets all cells to the state specified by <tt>value</tt>. * @param value the value to be filled into the cells. * @return <tt>this</tt> (for convenience only). */ public ObjectMatrix1D assign(Object value) { for (int i=size; --i >= 0;) { setQuick(i,value); } return this; } /**
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. * @throws IndexOutOfBoundsException if <tt>index<0 || index>=size()</tt>. */ public void set(int index, Object value) { if (index<0 || index>=size) checkIndex(index); setQuick(index,value); } /**
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. * @throws IndexOutOfBoundsException if <tt>index<0 || index>=size()</tt>. */ public void set(int index, Object value) { if (index<0 || index>=size) checkIndex(index); setQuick(index,value); } /**
/** * 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 (values.length != size) throw new IllegalArgumentException("Must have same number of cells: length="+values.length+", size()="+size()); for (int i=size; --i >= 0;) { setQuick(i,values[i]); } return this; } /**
/** * 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 (values.length != size) throw new IllegalArgumentException("Must have same number of cells: length="+values.length+", size()="+size()); for (int i=size; --i >= 0;) { setQuick(i,values[i]); } return this; } /**
/** Swaps each element <tt>this[i]</tt> with <tt>other[i]</tt>. @throws IllegalArgumentException if <tt>size() != other.size()</tt>. */ public void swap(ObjectMatrix1D other) { checkSize(other); for (int i=size; --i >= 0; ) { Object tmp = getQuick(i); setQuick(i, other.getQuick(i)); other.setQuick(i, tmp); } return; } /**
/** Swaps each element <tt>this[i]</tt> with <tt>other[i]</tt>. @throws IllegalArgumentException if <tt>size() != other.size()</tt>. */ public void swap(ObjectMatrix1D other) { checkSize(other); for (int i=size; --i >= 0; ) { Object tmp = getQuick(i); setQuick(i, other.getQuick(i)); other.setQuick(i, tmp); } return; } /**
/** Assigns the result of a function to each cell; <tt>x[i] = function(x[i])</tt>. (Iterates downwards from <tt>[size()-1]</tt> to <tt>[0]</tt>). <p> <b>Example:</b> <pre> // change each cell to its sine matrix = 0.5 1.5 2.5 3.5 matrix.assign(cern.jet.math.Functions.sin); --> matrix == 0.479426 0.997495 0.598472 -0.350783 </pre> For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>. @param function a function object taking as argument the current cell's value. @return <tt>this</tt> (for convenience only). @see cern.jet.math.Functions */ public ObjectMatrix1D assign(cern.colt.function.ObjectFunction function) { for (int i=size; --i >= 0; ) { setQuick(i, function.apply(getQuick(i))); } return this; } /**
/** Assigns the result of a function to each cell; <tt>x[i] = function(x[i])</tt>. (Iterates downwards from <tt>[size()-1]</tt> to <tt>[0]</tt>). <p> <b>Example:</b> <pre> // change each cell to its sine matrix = 0.5 1.5 2.5 3.5 matrix.assign(cern.jet.math.Functions.sin); --> matrix == 0.479426 0.997495 0.598472 -0.350783 </pre> For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>. @param function a function object taking as argument the current cell's value. @return <tt>this</tt> (for convenience only). @see cern.jet.math.Functions */ public ObjectMatrix1D assign(cern.colt.function.ObjectFunction function) { for (int i=size; --i >= 0; ) { setQuick(i, function.apply(getQuick(i))); } return this; } /**
/** Constructs a new vector consisting of the diagonal elements of <tt>A</tt>. Cells values are copied. The new vector is not a view. Example: <pre> 5 0 0 9 0 4 0 9 0 0 3 9 --> 5 4 3 </pre> @param A the matrix, need not be square. @return a new vector. */ public ObjectMatrix1D diagonal(ObjectMatrix2D A) { int min = Math.min(A.rows(),A.columns()); ObjectMatrix1D diag = make1D(min); for (int i=min; --i >= 0; ) { diag.setQuick(i, A.getQuick(i,i)); } return diag; } /**
/** Constructs a new vector consisting of the diagonal elements of <tt>A</tt>. Cells values are copied. The new vector is not a view. Example: <pre> 5 0 0 9 0 4 0 9 0 0 3 9 --> 5 4 3 </pre> @param A the matrix, need not be square. @return a new vector. */ public ObjectMatrix1D diagonal(ObjectMatrix2D A) { int min = Math.min(A.rows(),A.columns()); ObjectMatrix1D diag = make1D(min); for (int i=min; --i >= 0; ) { diag.setQuick(i, A.getQuick(i,i)); } return diag; } /**
/** * Replaces all cell values of the receiver with the values of another matrix. * Both matrices must have the same size. * If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>. * * @param other the source matrix to copy from (may be identical to the receiver). * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>size() != other.size()</tt>. */ public ObjectMatrix1D assign(ObjectMatrix1D other) { if (other==this) return this; checkSize(other); if (haveSharedCells(other)) other = other.copy(); for (int i=size; --i >= 0;) { setQuick(i,other.getQuick(i)); } return this; } /**
/** * Replaces all cell values of the receiver with the values of another matrix. * Both matrices must have the same size. * If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>. * * @param other the source matrix to copy from (may be identical to the receiver). * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>size() != other.size()</tt>. */ public ObjectMatrix1D assign(ObjectMatrix1D other) { if (other==this) return this; checkSize(other); if (haveSharedCells(other)) other = other.copy(); for (int i=size; --i >= 0;) { setQuick(i,other.getQuick(i)); } return this; } /**
/** Assigns the result of a function to each cell; <tt>x[i] = function(x[i],y[i])</tt>. <p> <b>Example:</b> <pre> // assign x[i] = x[i]<sup>y[i]</sup> m1 = 0 1 2 3; m2 = 0 2 4 6; m1.assign(m2, cern.jet.math.Functions.pow); --> m1 == 1 1 16 729 </pre> For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>. @param y the secondary matrix to operate on. @param function a function object taking as first argument the current cell's value of <tt>this</tt>, and as second argument the current cell's value of <tt>y</tt>, @return <tt>this</tt> (for convenience only). @throws IllegalArgumentException if <tt>size() != y.size()</tt>. @see cern.jet.math.Functions */ public ObjectMatrix1D assign(ObjectMatrix1D y, cern.colt.function.ObjectObjectFunction function) { checkSize(y); for (int i=size; --i >= 0; ) { setQuick(i, function.apply(getQuick(i), y.getQuick(i))); } return this; } /**
/** Assigns the result of a function to each cell; <tt>x[i] = function(x[i],y[i])</tt>. <p> <b>Example:</b> <pre> // assign x[i] = x[i]<sup>y[i]</sup> m1 = 0 1 2 3; m2 = 0 2 4 6; m1.assign(m2, cern.jet.math.Functions.pow); --> m1 == 1 1 16 729 </pre> For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>. @param y the secondary matrix to operate on. @param function a function object taking as first argument the current cell's value of <tt>this</tt>, and as second argument the current cell's value of <tt>y</tt>, @return <tt>this</tt> (for convenience only). @throws IllegalArgumentException if <tt>size() != y.size()</tt>. @see cern.jet.math.Functions */ public ObjectMatrix1D assign(ObjectMatrix1D y, cern.colt.function.ObjectObjectFunction function) { checkSize(y); for (int i=size; --i >= 0; ) { setQuick(i, function.apply(getQuick(i), y.getQuick(i))); } return this; } /**