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

    https://github.com/apache/spark/pull/3462#discussion_r20967444
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala 
---
    @@ -261,6 +261,57 @@ object Vectors {
             sys.error("Unsupported Breeze vector type: " + v.getClass.getName)
         }
       }
    +
    +  /**
    +   * Returns the p-norm of this vector.
    +   * @param vector input vector.
    +   * @param p norm.
    +   * @return norm in L^p^ space.
    +   */
    +  private[spark] def norm(vector: Vector, p: Double): Double = {
    +    require(p >= 1.0)
    +    val values = vector match {
    +      case dv: DenseVector => dv.values
    +      case sv: SparseVector => sv.values
    +      case v => throw new IllegalArgumentException("Do not support vector 
type " + v.getClass)
    +    }
    +    val size = values.size
    +
    +    if (p == 1) {
    +      var sum = 0.0
    +      var i = 0
    +      while (i < size) {
    +        sum += math.abs(values(i))
    +        i += 1
    +      }
    +      sum
    +    } else if (p == 2) {
    +      var sum = 0.0
    +      var i = 0
    +      while (i < size) {
    +        sum += values(i) * values(i)
    --- End diff --
    
    @mengxr Having `var value` outside will generate the same bytecode. It 
doesn't make sense, since in the bytecode, it just stores the value to stack, 
and no difference between two version.
    
    @srowen I'm very curious about this myself. :P I'm using ASM Bytecode 
Outline plugin in intellij, https://plugins.jetbrains.com/plugin/5918 so I can 
generate the bytecode by just simple right click. We use it to find couple 
boxing/unboxing performance issue at Alpine, and it's very useful. 


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