/** 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; } /**
/** 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; } /**
/** * 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; } /**
/** Constructs a matrix which is the concatenation of all given parts. Cells are copied. */ public ObjectMatrix1D make(ObjectMatrix1D[] parts) { if (parts.length==0) return make(0); int size = 0; for (int i=0; i < parts.length; i++) size += parts[i].size(); ObjectMatrix1D vector = make(size); size = 0; for (int i=0; i < parts.length; i++) { vector.viewPart(size,parts[i].size()).assign(parts[i]); size += parts[i].size(); } return vector; } /**
/** Constructs a matrix which is the concatenation of all given parts. Cells are copied. */ public ObjectMatrix1D make(ObjectMatrix1D[] parts) { if (parts.length==0) return make(0); int size = 0; for (int i=0; i < parts.length; i++) size += parts[i].size(); ObjectMatrix1D vector = make(size); size = 0; for (int i=0; i < parts.length; i++) { vector.viewPart(size,parts[i].size()).assign(parts[i]); size += parts[i].size(); } return vector; } /**
int[] indexes = new int[vector.size()]; // row indexes to reorder instead of matrix itself for (int i=indexes.length; --i >= 0; ) indexes[i] = i;
int[] indexes = new int[vector.size()]; // row indexes to reorder instead of matrix itself for (int i=indexes.length; --i >= 0; ) indexes[i] = i;
int[] indexes = new int[vector.size()]; // row indexes to reorder instead of matrix itself for (int i=indexes.length; --i >= 0; ) indexes[i] = i;
int[] indexes = new int[vector.size()]; // row indexes to reorder instead of matrix itself for (int i=indexes.length; --i >= 0; ) indexes[i] = i;
/** C = A||A||..||A; Constructs a new matrix which is concatenated <tt>repeat</tt> times. Example: <pre> 0 1 repeat(3) --> 0 1 0 1 0 1 </pre> */ public ObjectMatrix1D repeat(ObjectMatrix1D A, int repeat) { int size = A.size(); ObjectMatrix1D matrix = make(repeat * size); for (int i=repeat; --i >= 0; ) { matrix.viewPart(size*i,size).assign(A); } return matrix; } /**
/** C = A||A||..||A; Constructs a new matrix which is concatenated <tt>repeat</tt> times. Example: <pre> 0 1 repeat(3) --> 0 1 0 1 0 1 </pre> */ public ObjectMatrix1D repeat(ObjectMatrix1D A, int repeat) { int size = A.size(); ObjectMatrix1D matrix = make(repeat * size); for (int i=repeat; --i >= 0; ) { matrix.viewPart(size*i,size).assign(A); } return matrix; } /**
/** Constructs a new diagonal matrix whose diagonal elements are the elements of <tt>vector</tt>. Cells values are copied. The new matrix is not a view. Example: <pre> 5 4 3 --> 5 0 0 0 4 0 0 0 3 </pre> @return a new matrix. */ public ObjectMatrix2D diagonal(ObjectMatrix1D vector) { int size = vector.size(); ObjectMatrix2D diag = make(size,size); for (int i=size; --i >= 0; ) { diag.setQuick(i,i, vector.getQuick(i)); } return diag; } /**
/** * Returns a string representation of the given matrix. * @param matrix the matrix to convert. */ public String toString(ObjectMatrix1D matrix) { ObjectMatrix2D easy = matrix.like2D(1,matrix.size()); easy.viewRow(0).assign(matrix); return toString(easy); } /**
/** * Returns a string representation of the given matrix. * @param matrix the matrix to convert. */ public String toString(ObjectMatrix1D matrix) { ObjectMatrix2D easy = matrix.like2D(1,matrix.size()); easy.viewRow(0).assign(matrix); return toString(easy); } /**
/** Constructs a new diagonal matrix whose diagonal elements are the elements of <tt>vector</tt>. Cells values are copied. The new matrix is not a view. Example: <pre> 5 4 3 --> 5 0 0 0 4 0 0 0 3 </pre> @return a new matrix. */ public ObjectMatrix2D diagonal(ObjectMatrix1D vector) { int size = vector.size(); ObjectMatrix2D diag = make(size,size); for (int i=size; --i >= 0; ) { diag.setQuick(i,i, vector.getQuick(i)); } return diag; } /**
/** * 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; } }
/** * 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 (otherObj==null) return false; ObjectMatrix1D other = (ObjectMatrix1D) otherObj; if (size!=other.size()) return false;
if (otherObj==null) return false; ObjectMatrix1D other = (ObjectMatrix1D) otherObj; if (size!=other.size()) return false;