/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of rows and columns. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix2D</tt> the new matrix must also be of type <tt>DenseDoubleMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix2D</tt> the new matrix must also be of type <tt>SparseDoubleMatrix2D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @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 DoubleMatrix2D like(int rows, int columns) { return new RCMDoubleMatrix2D(rows,columns); } /**
/** * Constructs a matrix with a copy of the given values. * <tt>values</tt> is required to have the form <tt>values[row][column]</tt> * and have exactly the same number of columns 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 <= row < values.length: values[row].length != values[row-1].length</tt>. */ public RCMDoubleMatrix2D(double[][] values) { this(values.length, values.length==0 ? 0: values[0].length); assign(values); } /**
/** * Constructs a matrix with a given number of rows and columns. * All entries are initially <tt>0</tt>. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt>. */ public RCMDoubleMatrix2D(int rows, int columns) { super(null); setUp(rows, columns); indexes = new IntArrayList[rows]; values = new DoubleArrayList[rows]; } /**
/** * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>. * <tt>z[i] = alpha*Sum(A[i,j] * y[j]) + beta*z[i], i=0..A.rows()-1, j=0..y.size()-1</tt>. * Where <tt>A == this</tt>. * @param y the source vector. * @param z the vector where results are to be stored. * * @throws IllegalArgumentException if <tt>A.columns() != y.size() || A.rows() > z.size())</tt>. */ protected void zMult(final DoubleMatrix1D y, final DoubleMatrix1D z, cern.colt.list.IntArrayList nonZeroIndexes, DoubleMatrix1D[] allRows, final double alpha, final double beta) { if (columns != y.size() || rows > z.size()) throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort()); z.assign(cern.jet.math.Functions.mult(beta/alpha)); for (int i = indexes.length; --i >= 0; ) { if (indexes[i] != null) { for (int k = indexes[i].size(); --k >= 0; ) { int j = indexes[i].getQuick(k); double value = values[i].getQuick(k); z.setQuick(i,z.getQuick(i) + value * y.getQuick(j)); } } } z.assign(cern.jet.math.Functions.mult(alpha)); } }
/** * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>. * <tt>z[i] = alpha*Sum(A[i,j] * y[j]) + beta*z[i], i=0..A.rows()-1, j=0..y.size()-1</tt>. * Where <tt>A == this</tt>. * @param y the source vector. * @param z the vector where results are to be stored. * * @throws IllegalArgumentException if <tt>A.columns() != y.size() || A.rows() > z.size())</tt>. */ protected void zMult(final DoubleMatrix1D y, final DoubleMatrix1D z, cern.colt.list.IntArrayList nonZeroIndexes, DoubleMatrix1D[] allRows, final double alpha, final double beta) { if (columns != y.size() || rows > z.size()) throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort()); z.assign(cern.jet.math.Functions.mult(beta/alpha)); for (int i = indexes.length; --i >= 0; ) { if (indexes[i] != null) { for (int k = indexes[i].size(); --k >= 0; ) { int j = indexes[i].getQuick(k); double value = values[i].getQuick(k); z.setQuick(i,z.getQuick(i) + value * y.getQuick(j)); } } } z.assign(cern.jet.math.Functions.mult(alpha)); } }
/** * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of rows and columns. * For example, if the receiver is an instance of type <tt>DenseDoubleMatrix2D</tt> the new matrix must also be of type <tt>DenseDoubleMatrix2D</tt>, * if the receiver is an instance of type <tt>SparseDoubleMatrix2D</tt> the new matrix must also be of type <tt>SparseDoubleMatrix2D</tt>, etc. * In general, the new matrix should have internal parametrization as similar as possible. * * @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 DoubleMatrix2D like(int rows, int columns) { return new RCMDoubleMatrix2D(rows,columns); } /**
/** * Constructs a matrix with a given number of rows and columns. * All entries are initially <tt>0</tt>. * @param rows the number of rows the matrix shall have. * @param columns the number of columns the matrix shall have. * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt>. */ public RCMDoubleMatrix2D(int rows, int columns) { super(null); setUp(rows, columns); indexes = new IntArrayList[rows]; values = new DoubleArrayList[rows]; } /**
/** * Constructs a matrix with a copy of the given values. * <tt>values</tt> is required to have the form <tt>values[row][column]</tt> * and have exactly the same number of columns 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 <= row < values.length: values[row].length != values[row-1].length</tt>. */ public RCMDoubleMatrix2D(double[][] values) { this(values.length, values.length==0 ? 0: values[0].length); assign(values); } /**