Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling toString on a DenseMatrix with zero rows and some columns throws java.lang.UnsupportedOperationException: empty.max #28

Closed
rossetd0 opened this issue Feb 4, 2013 · 1 comment

Comments

@rossetd0
Copy link

rossetd0 commented Feb 4, 2013

Try the following in the REPL:

This works:

scala> breeze.linalg.DenseMatrix.zeros[Int](0,2).toString
scala> breeze.linalg.DenseVector[Int]().toString

This throws java.lang.UnsupportedOperationException: empty.max :

scala> breeze.linalg.DenseMatrix.zeros[Int](0,2).toString
java.lang.UnsupportedOperationException: empty.max
    at scala.collection.TraversableOnce$class.max(TraversableOnce.scala:201)
    at scala.collection.immutable.Vector.max(Vector.scala:63)
    at breeze.linalg.Matrix$class.colWidth$1(Matrix.scala:68)
    at breeze.linalg.Matrix$class.toString(Matrix.scala:73)

The culprit is the following line:

    def colWidth(col : Int) =
      (0 until showRows).map(row => this(row,col).toString.length+2).max

which should be replaced by:

    def colWidth(col : Int) =
      if (showRows > 0) (0 until showRows).map(row => this(row,col).toString.length+2).max else 0

or something approaching.

Thanks for any correction!

Denis

@dlwh dlwh closed this as completed in b4fb562 Feb 4, 2013
@dlwh
Copy link
Member

dlwh commented Feb 4, 2013

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants