/** C = A||B; Constructs a new matrix which is the concatenation of two other matrices. Example: <tt>0 1</tt> append <tt>3 4</tt> --> <tt>0 1 3 4</tt>. */ public ObjectMatrix1D append(ObjectMatrix1D A, ObjectMatrix1D B) { // concatenate ObjectMatrix1D matrix = make(A.size()+B.size()); matrix.viewPart(0,A.size()).assign(A); matrix.viewPart(A.size(),B.size()).assign(B); return matrix; } /**
/** * Returns the matrix cell value at coordinate <tt>index</tt>. * * @param index the index of the cell. * @return the value of the specified cell. * @throws IndexOutOfBoundsException if <tt>index<0 || index>=size()</tt>. */ public Object get(int index) { if (index<0 || index>=size) checkIndex(index); return getQuick(index); } /**
checkIndexes(indexes); int[] offsets = new int[indexes.length]; for (int i=indexes.length; --i >= 0; ) { offsets[i] = index(indexes[i]); return viewSelectionLike(offsets);
/** * 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); } /**
/** * Returns <tt>true</tt> if both matrices share at least one identical cell. */ protected boolean haveSharedCells(ObjectMatrix1D other) { if (other==null) return false; if (this==other) return true; return getContent().haveSharedCellsRaw(other.getContent()); } /**
/** * 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; } /**
/** 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; } /**
/** * Constructs a matrix with the given shape, each cell initialized with the given value. */ public ObjectMatrix1D make(int size, Object initialValue) { return make(size).assign(initialValue); } /**
/** * Constructs and returns a deep copy of the receiver. * <p> * <b>Note that the returned matrix is an independent deep copy.</b> * The returned matrix is not backed by this matrix, so changes in the returned matrix are not reflected in this matrix, and vice-versa. * * @return a deep copy of the receiver. */ public ObjectMatrix1D copy() { ObjectMatrix1D copy = like(); copy.assign(this); return copy; } /**
/** * Constructs a list from the given matrix. * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the list, and vice-versa. * * @param values The values to be filled into the new list. * @return a new list. */ public cern.colt.list.ObjectArrayList toList(ObjectMatrix1D values) { int size = values.size(); cern.colt.list.ObjectArrayList list = new cern.colt.list.ObjectArrayList(size); list.setSize(size); for (int i=size; --i >= 0; ) list.set(i, values.get(i)); return list; } }
if (r>0) titleMatrix.viewRow(0).viewPart(c,columns).assign(columnNames); String[] rowAxisStrings = new String[rowAxisName.length()]; for (int i=rowAxisName.length(); --i >= 0; ) rowAxisStrings[i] = rowAxisName.substring(i,i+1); titleMatrix.viewColumn(0).viewPart(r,rowAxisName.length()).assign(rowAxisStrings); if (rowNames!=null) titleMatrix.viewColumn(c-2).viewPart(r,rows).assign(rowNames); if (c>0) titleMatrix.viewColumn(c-2+1).viewPart(0,rows+r).assign("|");
/** * Compares the specified Object with the receiver for equality. * Equivalent to <tt>equals(otherObj,true)</tt>. * * @param otherObj the Object to be compared for equality with the receiver. * @return true if the specified Object is equal to the receiver. */ public boolean equals(Object otherObj) { //delta return equals(otherObj, true); } /**
/** * Returns the number of cells having non-zero values. */ public int cardinality() { if (this.isNoView) return this.elements.size(); else return super.cardinality(); } /**
/** * Converts a given cell to a String; no alignment considered. */ protected String form(ObjectMatrix1D matrix, int index, Former formatter) { Object value = matrix.get(index); if (value==null) return ""; return String.valueOf(value); } /**
/** * Constructs and returns a new view equal to the receiver. * The view is a shallow clone. Calls <code>clone()</code> and casts the result. * <p> * <b>Note that the view is not a deep copy.</b> * The returned matrix is backed by this matrix, so changes in the returned matrix are reflected in this matrix, and vice-versa. * <p> * Use {@link #copy()} to construct an independent deep copy rather than a new view. * * @return a new view of the receiver. */ protected ObjectMatrix1D view() { return (ObjectMatrix1D) clone(); } /**
/** * 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; } /**
/** 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; } /**