added sparse cosine distance calculation