From 5b23c51e0f2c1e0b4360f8bbf8e59ad50e8c0306 Mon Sep 17 00:00:00 2001 From: Jose Manuel Abuin Mosquera Date: Thu, 2 Jun 2016 17:28:26 +0200 Subject: [PATCH] Added dot vector operation for the class DenseVector --- .../org/apache/spark/ml/linalg/Vectors.scala | 16 ++++++++++++++++ .../org/apache/spark/mllib/linalg/Vectors.scala | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Vectors.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Vectors.scala index 909fec1c06653..006048ea0cdfe 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Vectors.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Vectors.scala @@ -537,6 +537,22 @@ class DenseVector @Since("2.0.0") ( @Since("2.0.0") val values: Array[Double]) e maxIdx } } + + /** + * Function that returns the result of multiply this DenseVector by another DenseVector. + * + * @param other The second DenseVector + * @return The resulting Double value + */ + def dot(other: DenseVector): Double = { + require(this.size == other.size, "DenseVectors dimmensions must be the same." + + s" You provided ${this.size} items and " + + s" ${other.size} items.") + + return BLAS.dot(this,other) + + } + } @Since("2.0.0") diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala index 02fd60da7d590..87f4891d3373d 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala @@ -712,6 +712,23 @@ class DenseVector @Since("1.0.0") ( override def asML: newlinalg.DenseVector = { new newlinalg.DenseVector(values) } + + /** + * Function that returns the result of multiply this DenseVector by another DenseVector. + * + * @param other The second DenseVector + * @return The resulting Double value + */ + @Since("2.0.0") + def dot(other: DenseVector): Double = { + require(this.size == other.size, "DenseVectors dimmensions must be the same." + + s" You provided ${this.size} items and " + + s" ${other.size} items.") + + return BLAS.dot(this,other) + + } + } @Since("1.3.0")