@@ -0,0 +1,1472 @@
+package edu.neu.ccs.pyramid.util;%0A%0Aimport org.apache.mahout.math.Vector;%0A%0A/**%0A * Created by chengli on 1/3/16.%0A */%0Apublic class Vectors %7B%0A    public static double dot(Vector vector1, Vector vector2)%7B%0A        if (vector1.size()!=vector2.size())%7B%0A            throw new IllegalArgumentException(%22vector1.size()!=vector2.size()%22);%0A        %7D%0A%0A        boolean vector1Dense = vector1.isDense();%0A        boolean vector2Dense = vector2.isDense();%0A%0A        if (vector1Dense&&vector2Dense)%7B%0A            return dotDenseDense(vector1,vector2);%0A        %7D else if (vector1Dense && !vector2Dense)%7B%0A            return dotDenseSparse(vector1,vector2);%0A        %7D else if (!vector1Dense && vector2Dense)%7B%0A            return dotDenseSparse(vector2,vector1);%0A        %7D else %7B%0A            throw new UnsupportedOperationException(%22sparse dot sparse is not supported%22);%0A        %7D%0A%0A    %7D%0A%0A    private static double dotDenseDense(Vector vector1, Vector vector2)%7B%0A        int size = vector1.size();%0A        double sum = 0;%0A        for (int d=0;d%3Csize;d++)%7B%0A            sum += vector1.getQuick(d)*vector2.getQuick(d);%0A        %7D%0A        return sum;%0A    %7D%0A%0A    private static double dotDenseSparse(Vector denseVector, Vector sparseVector)%7B%0A        double sum = 0;%0A        for (Vector.Element element: sparseVector.nonZeroes())%7B%0A            int index = element.index();%0A            double value = element.get();%0A            sum += value*denseVector.getQuick(index);%0A        %7D%0A        return sum;%0A    %7D%0A%7D%0A

add class Vectors