public class Vector { /* Compute alpha*x + y and store in dest (daxpy-like operation) * * Arguments: * dest - destination vector. Can be the same as x or y. * alpha - scalar multiplier * x, y - vector inputs * n - vector size */ public static void axpy(double [1d] dest, double alpha, double [1d] x, double [1d] y) { int i; foreach (i in dest.domain()) dest[i] = alpha*x[i] + y[i]; } /* Compute the dot product of two vectors x'*y * * Arguments: * x, y - vector inputs * n - vector size */ public static double ddot(double [1d] x, double [1d] y) { int i; double sum = 0; foreach (i in x.domain()) sum += x[i]*y[i]; return sum; } public static String toString(double [1d] v) { String result = "["; int low = v.domain().min()[1]; int high = v.domain().max()[1]; for (int i = low; i < high; i++) { result += v[i] + ", "; } return result + v[high] + "]"; } public static String toString(int [1d] v) { String result = "["; int low = v.domain().min()[1]; int high = v.domain().max()[1]; for (int i = low; i < high; i++) { result += v[i] + ", "; } return result + v[high] + "]"; } }