/** * Returns {@code true} if the two vectors are equal to one another. Two {@code Vector} insances * are considered equal if they contain the same number of elements and all corresponding pairs of * {@code Number} values are equal. Two values {@code n1} and {@code n2} are considered equal if * {@code n1.equals(n2)}. */ public static boolean equals(Vector v1, Vector v2) { if (v1.length() == v2.length()) { int length = v1.length(); for (int i = 0; i < length; ++i) { Number n1 = v1.getValue(i); Number n2 = v2.getValue(i); if (!n1.equals(n2)) return false; } return true; } return false; }
/** * Creates a copy of a given {@code Vector}. * * @param source The {@code Vector} to copy. * @return A copy of {@code source} with the same type. */ public static Vector copyOf(Vector source) { if (source instanceof DoubleVector) return copyOf((DoubleVector) source); if (source instanceof IntegerVector) return copyOf((IntegerVector) source); Vector result = new DenseVector(source.length()); for (int i = 0; i < source.length(); ++i) result.set(i, source.getValue(i)); return result; }
/** * Copies all of the values from one {@code Vector} into another. After the operation, all of the * values in {@code dest} will be the same as that of {@code source}. The legnth of {@code dest} * must be as long as the length of {@code source}. Once completed {@code dest} is returned. * * @param dest The {@code Vector} to copy values into. * @param source The {@code Vector} to copy values from. * @return {@code dest} after being copied from {@code source}. * @throws IllegalArgumentException if the length of {@code dest} is less than that of {@code * source}. */ public static Vector copy(Vector dest, Vector source) { for (int i = 0; i < source.length(); ++i) dest.set(i, source.getValue(i).doubleValue()); return dest; }