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

    https://github.com/apache/spark/pull/15628#discussion_r105068149
  
    --- Diff: 
mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala ---
    @@ -153,6 +153,86 @@ sealed trait Matrix extends Serializable {
        */
       @Since("2.0.0")
       def numActives: Int
    +
    +  /**
    +   * Converts this matrix to a sparse matrix.
    +   *
    +   * @param columnMajor Whether the values of the resulting sparse matrix 
should be in column major
    +   *                    or row major order. If `false`, resulting matrix 
will be row major.
    +   */
    +  private[ml] def toSparseMatrix(columnMajor: Boolean): SparseMatrix
    --- End diff --
    
    Yeah, this is very hacky in my opinion too! 
    
    The problem is that when one overloads a function without parenthesis, the 
ambiguity happens because when that function is invoked without parenthesis, 
this can be calling the actual function without parenthesis, or getting the 
function with parenthesis. The following is an example demonstrating the issue. 
    
    In my opinion, I would like to call it `toSparse(columnMajor: Boolean)` and 
`toSparse() = toSparse(true)`, but in the vector api, we already use the one 
without parenthesis, so it will result inconsistency in the api design.
    
    I think exposing the ability of converting it to `columnMajor` or 
`rowMajor` is very useful, as a result, we can expose it as `toCSRMatrix`, 
`toCSCMatrix`, and `toSparse` which converts the matrix to the one with 
smallest storage. 
    
    ```scala
    scala> trait A {
         | def foo(b: Boolean): String
         | def foo: String = foo(true)
         | }
    defined trait A
    
    scala> class B extends A {
         | def foo(b: Boolean): String = b.toString
         | }
    defined class B
    
    scala> val b = new B
    b: B = B@67b6d4ae
    
    scala> b.foo
    <console>:18: error: ambiguous reference to overloaded definition,
    both method foo in class B of type (b: Boolean)String
    and  method foo in trait A of type => String
    match expected type ?
           b.foo
             ^
    
    scala> val x: String = b.foo
    x: String = true
    
    scala> val y: Boolean=> String = b.foo
    y: Boolean => String = <function1>
    ```


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