/** * Subtract the values in the given vector from a copy of * this vector and return the result * @param vector the array to add * @return the resultant vector */ public SparseDoubleArray subtract(SparseDoubleArray vector) { return copy().subtractInplace(vector); }
/** * Copy this vector and multiply its values by a * scalar * @param value scalar multiplier * @return the multiplied vector */ public SparseDoubleArray multiply(double value) { return copy().multiplyInplace(value); }
/** * Add the values in the given vector to a copy of * this array and return the result * @param vector the vector to add * @return the resultant vector */ public SparseDoubleArray add(SparseDoubleArray vector) { return copy().addInplace(vector); }
@Override public SparseDoubleArray concatenate(List<SparseDoubleArray> ins) { final SparseDoubleArray result = copy(); for (int i=0; i<ins.size(); i++) { final int oldLength = result.length; result.setLength(oldLength + ins.get(i).length); for (Entry e : ins.get(i).entries()) { result.set(e.index + oldLength, e.value); } } return result; } }
@Override public SparseDoubleArray concatenate(SparseDoubleArray... ins) { final SparseDoubleArray result = copy(); for (int i=0; i<ins.length; i++) { final int oldLength = result.length; result.setLength(oldLength + ins[i].length); for (Entry e : ins[i].entries()) { result.set(e.index + oldLength, e.value); } } return result; }
/** * Concatenate multiple arrays into a single new array. * * @param arrays the arrays to concatenate. * @return the new concatenated array */ public static SparseDoubleArray concatenateArrays(SparseDoubleArray... arrays) { SparseDoubleArray concat = arrays[0].copy(); for (int i=1; i<arrays.length; i++) { if (arrays[i] != null) { int oldLength = concat.length; concat.setLength(oldLength + arrays[i].length); for (Entry e : arrays[i].entries()) concat.set(e.index + oldLength, e.value); } } return concat; }