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

    https://github.com/apache/spark/pull/14219#discussion_r71077975
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala ---
    @@ -617,8 +617,27 @@ private[spark] object BLAS extends Serializable with 
Logging {
           x: SparseVector,
           beta: Double,
           y: DenseVector): Unit = {
    -    val xValues = x.values
    -    val xIndices = x.indices
    +    
    +    def isSorted(l:Array[Int]): Boolean = {
    +      var index = 1
    +      while(index < l.length){
    +        val prevElement = l(index - 1)
    +        val currentElement = l(index)
    +        
    +        if(prevElement > currentElement) return false
    +        index += 1
    +      }
    +      return true
    +    }
    +    
    +    val (xValues,xIndices) = isSorted(x.indices) match{
    --- End diff --
    
    match is overkilll for a boolean. Just use an `if`. We should avoid the 
style that omits member dereference "." here. Also you can use `unzip` I think
    
    ```
    val (xValues, xIndices) =
      if (isSorted(x.indices)) {
        (x.values, x.indices)
      } else {
        x.values.zip(x.indices).sortBy(_._2).unzip
      }
    ```
    
    The `def isSorted` probably should just be inlined, even, or made non-local


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