Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/3288#discussion_r20549368
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala
---
@@ -76,6 +76,22 @@ sealed trait Vector extends Serializable {
def copy: Vector = {
throw new NotImplementedError(s"copy is not implemented for
${this.getClass}.")
}
+
+ /**
+ * It will return the iterator for the active elements of dense and
sparse vector as
+ * (index, value) pair. Note that foreach method can be overridden for
better performance
+ * in different vector implementation.
+ *
+ * @param skippingZeros Skipping zero elements explicitly if true. It
will be useful when we
+ * iterator through dense vector having lots of
zero elements which
+ * we want to skip. Default is false.
+ * @return Iterator[(Int, Double)] where the first element in the tuple
is the index,
+ * and the second element is the corresponding value.
+ */
+ private[spark] def activeIterator(skippingZeros: Boolean):
Iterator[(Int, Double)]
--- End diff --
I think the following code should have the same performance:
~~~scala
vec.foreach { (i, v) =>
if (v != 0.0) {
...
}
}
~~~
---
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.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]