Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3288#discussion_r20557238
  
    --- 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 --
    
    `Tuple2[Int, Double]` is specialized in Scala: 
https://github.com/scala/scala/blob/2.10.x/src/library/scala/Tuple2.scala, but 
the iterator interface still won't be high-performance for numerical 
computation. The iterator interface is not used in this PR, as we only need 
`foreach`. Then the best for us is defining `foreach` directly: 
    
    ~~~scala
    def foreach(f: (Int, Double) => Unit)
    ~~~
    
    ( We could implement `ZippedTraversable2` but it doesn't seem to be 
necessary.)
    
    or
    
    ~~~scala
    def foreach(skipZeros = True)(f: (Int, Double) => Unit)
    ~~~
    
    This is a private function. We can change it when we see more use cases.



---
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]

Reply via email to