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

    https://github.com/apache/spark/pull/17459#discussion_r118817991
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/IndexedRowMatrix.scala
 ---
    @@ -108,8 +108,69 @@ class IndexedRowMatrix @Since("1.0.0") (
        */
       @Since("1.3.0")
       def toBlockMatrix(rowsPerBlock: Int, colsPerBlock: Int): BlockMatrix = {
    -    // TODO: This implementation may be optimized
    -    toCoordinateMatrix().toBlockMatrix(rowsPerBlock, colsPerBlock)
    +    require(rowsPerBlock > 0,
    +      s"rowsPerBlock needs to be greater than 0. rowsPerBlock: 
$rowsPerBlock")
    +    require(colsPerBlock > 0,
    +      s"colsPerBlock needs to be greater than 0. colsPerBlock: 
$colsPerBlock")
    +
    +    // Since block matrices require an integer row index
    +    require(numRows() / rowsPerBlock.toDouble <= Int.MaxValue,
    --- End diff --
    
    So I guess the previous `toBlockMatrix` would have failed too when the 
number of rows exceeded this threshold? it looks like it, given how 
CoordinateMatrix.toBlockMatrix works. Hm, I wonder if you should even put this 
warning over there too because it will fail mysteriously otherwise. The result 
might even be wrong.
    
    BTW on second look, I realize this check isn't quite the same as the math 
that's performed below: `math.ceil(m.toDouble / rowsPerBlock).toInt`. I think 
you want to check exactly the same thing. Maybe move the check below the 
declaration of m, n, and just say: `require(math.ceil(m.toDouble / 
rowsPerBlock) <= Int.MaxValue)` That's very clear.
    
    Also, cols need to be checked.


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