1. def fabs(n: Double): Double = {
if (n > 0) n else -n
if (n > 0) n else -n
}
2. def Cosin(vecA: Array[Float], vecB: Array[Float]): Double = {
val product = vecA.view.zip(vecB.view).map { case (a, b) => a * b}.sum
val la = Math.sqrt(vecA.view.zip(vecA.view).map { case (a, b) => a * b}.sum)
val lb = Math.sqrt(vecB.view.zip(vecB.view).map { case (a, b) => a * b}.sum)
if (la < 0.000001 || lb < 0.000001){
return 0.0f
}
return (product/(la*lb)).toFloat;
}
3. val parts = line.split(' ')
(parts(0), Vectors.dense(parts.tail.map(x => x.toDouble)))