Search code examples
scalaapache-sparkintellij-ideabreeze

Cannot resolve symbol norm


The following is a code snippet that I'm working on with for a recommender. Although,

import breeze.linalg.Vector

been made, the error mentioned above appeared when calling 'norm'. Can someone please suggest a fix for this matter and the reason. The code snippet is as follows.

object CosineDistance extends DistanceMetric with Serializable {
  def getDistance(v1: Vector[Double], v2: Vector[Double]) = {

    val dotProduct: Double = v1 dot v2
    val v1norm: Double = v1.norm(2.0)
    val v2norm: Double = v2.norm(2.0)

    1 - (dotProduct / (v1norm * v2norm))
  }

  override def getName: String = "cosine"

  override def getDescription: String = "Cosine distance"
}

Solution

  • For norm, seems there is no implicits for Vector, you should use it like:

      import breeze.linalg._
      val v1norm: Double = norm(v1, 2.0)