class CosineDistance extends FastDistance {

    @Override
    public void updateLabel(FastDistanceData data) {
        if (data instanceof FastDistanceVectorData) {
            FastDistanceVectorData vectorData = (FastDistanceVectorData)data;
            double vectorLabel = Math.sqrt(MatVecOp.dot(vectorData.vector, vectorData.vector));
            if(vectorLabel > 0){
                vectorData.vector.scaleEqual(1.0 / vectorLabel);
            }
        } else {
            FastDistanceMatrixData matrix = (FastDistanceMatrixData)data;
            int vectorSize = matrix.vectors.numRows();
            double[] matrixData = matrix.vectors.getData();

            int cnt = 0;
            while (cnt < matrixData.length) {
                int endIndex = cnt + vectorSize;
                double vectorLabel = 0.;
                while (cnt < endIndex) {
                    vectorLabel += matrixData[cnt] * matrixData[cnt];
                    cnt++;
                }
                vectorLabel = Math.sqrt(vectorLabel);
                if(vectorLabel > 0) {
                    BLAS.scal(1.0 / vectorLabel, matrixData, cnt - vectorSize, vectorSize);
                }
            }
        }
    }

}