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

    https://github.com/apache/spark/pull/3288#discussion_r20533260
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala 
---
    @@ -273,6 +289,47 @@ class DenseVector(val values: Array[Double]) extends 
Vector {
       override def copy: DenseVector = {
         new DenseVector(values.clone())
       }
    +
    +  private[spark] override def activeIterator(skippingZeros: Boolean) = new 
Iterator[(Int, Double)] {
    +    private var i = 0
    +    private val valuesSize = values.size
    +
    +    // If zeros are asked to be explicitly skipped, the parent `size` 
method is called to count
    +    // the number of nonzero elements using `hasNext` and `next` methods.
    +    override lazy val size: Int = if (skippingZeros) super.size else 
valuesSize
    +
    +    override def hasNext = {
    +      if (skippingZeros) {
    +        var found = false
    +        while (!found && i < valuesSize) if (values(i) != 0.0) found = 
true else i += 1
    +      }
    +      i < valuesSize
    +    }
    +
    +    override def next = {
    +      val result = (i, values(i))
    +      i += 1
    +      result
    +    }
    +
    +    override def foreach[@specialized(Unit) U](f: ((Int, Double)) => U) {
    --- End diff --
    
    Interesting. In scala's range code, they have
    
        @inline final override def foreach[@specialized(Unit) U](f: Int => U)
    
    I'll do a bytecode analysis, and see if it will generate the same bytecode.


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