package utils.array;


public class ArrayUtil {

	public static void reverse(int[] array) {
		for (int i = 0; i < array.length / 2; i++) {
			int temp = array[i];
			array[i] = array[array.length - i - 1];
			array[array.length - i - 1] = temp;
		}
	}

//	public static void reverse(long[] array) {
//		for (int i = 0; i < array.length / 2; i++) {
//			long temp = array[i];
//			array[i] = array[array.length - i - 1];
//			array[array.length - i - 1] = temp;
//		}
//	}
//
//	public static void reverse(float[] array) {
//		for (int i = 0; i < array.length / 2; i++) {
//			float temp = array[i];
//			array[i] = array[array.length - i - 1];
//			array[array.length - i - 1] = temp;
//		}
//	}
    
	public static void reverse(double[] array) {
		for (int i = 0; i < array.length / 2; i++) {
			double temp = array[i];
			array[i] = array[array.length - i - 1];
			array[array.length - i - 1] = temp;
		}
	}

//	public static String fill(String str, int length) {
//
//		String template = "";
//		for (int i = 0; i < length; i++) {
//			template += " ";
//		}
//
//		int count = 0;
//		for (char c : str.toCharArray()) {
//			if (c < 127) {
//				count++;
//			} else {
//				count += 2;
//			}
//		}
//		if (count < length)
//			return str + template.substring(count);
//		else
//			return str;
//	}
}

@@ -23,32 +23,219 @@
 %0D%0A%0D%0A
-public class ArrayUtil %7B
+import org.apache.logging.log4j.LogManager;%0D%0Aimport org.apache.logging.log4j.Logger;%0D%0A%0D%0Aimport java.util.Arrays;%0D%0A%0D%0Apublic class ArrayUtil %7B%0D%0A%0D%0A%09private static Logger log = LogManager.getLogger(ArrayUtil.class);
 %0D%0A%0D%0A
@@ -1539,12 +1539,712 @@
 ;%0D%0A//%09%7D%0D
+%0A%0D%0A%09public static double innerProduct(double%5B%5D x1, double%5B%5D x2) %7B%0D%0A%0D%0A%09%09double result = 0;%0D%0A%09%09for (int i = 0; i %3C x1.length; i++) %7B%0D%0A%09%09%09result += x1%5Bi%5D * x2%5Bi%5D;%0D%0A%09%09%7D%0D%0A%0D%0A%09%09return result;%0D%0A%09%7D%0D%0A%0D%0A%09public static double%5B%5D arraySubtract(double%5B%5D x1, double%5B%5D x2) %7B%0D%0A%0D%0A%09%09double%5B%5D result = new double%5Bx1.length%5D;%0D%0A%09%09for (int i = 0; i %3C x1.length; i++) %7B%0D%0A%09%09%09result%5Bi%5D = x1%5Bi%5D - x2%5Bi%5D;%0D%0A%09%09%7D%0D%0A%0D%0A%09%09return result;%0D%0A%09%7D%0D%0A%0D%0A%09public static double euclidean(double%5B%5D x1, double%5B%5D x2) %7B%0D%0A%09%09double%5B%5D x3 = arraySubtract(x1, x2);%0D%0A%09%09return Arrays.stream(x3).map(xi -%3E Math.pow(xi, 2)).sum();%0D%0A%09%7D%0D%0A%0D%0A%09public static double normL2(double%5B%5D x) %7B%0D%0A%09%09return Math.pow(Arrays.stream(x).map(xi -%3E Math.pow(xi, 2)).sum(), 0.5);%0D%0A%09%7D%0D
 %0A%7D%0D%0A

add euclidean distance and inner product