Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/629#discussion_r29319548
--- Diff:
flink-staging/flink-ml/src/main/scala/org/apache/flink/ml/math/DenseVector.scala
---
@@ -80,6 +80,27 @@ case class DenseVector(val data: Array[Double]) extends
Vector with Serializable
data(index) = value
}
+ /** Returns the dot product of the recipient and the argument
+ *
+ * @param other a Vector
+ * @return a scalar double of dot product
+ */
+ override def dot(other: Vector): Double = {
+ require(size == other.size, "The size of vector must be equal.")
+
+ other match {
+ case SparseVector(_, otherIndices, otherData) =>
+ otherIndices.map(i => data(i) * otherData(i)).sum
--- End diff --
this won't work because the ```otherIndices``` array does not contain the
indices into the ```otherData``` array. ```otherData``` contains all non-zero
elements in a condensed manner. The original indices of the elements are then
contained in ```otherIndices```. So the non-zero elements (tuple of index and
value) are computed by ```0 to otherData.size map ( i => (otherIndices(i),
otherData(i))```.
To calculate the dot product with a ```DenseVector``` something like
```otherIndices.zipWithIndex.map((otherIndex, index) => data(otherIndex) *
otherData(i)).sum```
should work.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---