File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
main/scala/org/apache/spark/mllib/linalg
test/scala/org/apache/spark/mllib/linalg Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -87,8 +87,8 @@ sealed trait Matrix extends Serializable {
8787 /** A human readable representation of the matrix */
8888 override def toString : String = toBreeze.toString()
8989
90- /** A human readable representation of the matrix with specific lines and width */
91- def toString (maxLines : Int , maxWidth : Int ): String = toBreeze.toString(maxLines, maxWidth )
90+ /** A human readable representation of the matrix with maximum lines and width */
91+ def toString (maxLines : Int , maxLineWidth : Int ): String = toBreeze.toString(maxLines, maxLineWidth )
9292
9393 /** Map the values of this matrix using a function. Generates a new matrix. Performs the
9494 * function on only the backing array. For example, an operation such as addition or
Original file line number Diff line number Diff line change @@ -439,4 +439,20 @@ class MatricesSuite extends FunSuite {
439439 assert(mUDT.typeName == " matrix" )
440440 assert(mUDT.simpleString == " matrix" )
441441 }
442+
443+ test(" toString" ) {
444+ val empty = Matrices .ones(0 , 0 )
445+ empty.toString(0 , 0 )
446+
447+ val mat = Matrices .rand(5 , 10 , new Random ())
448+ mat.toString(- 1 , - 5 )
449+ mat.toString(0 , 0 )
450+ mat.toString(Int .MinValue , Int .MinValue )
451+ mat.toString(Int .MaxValue , Int .MaxValue )
452+ var lines = mat.toString(6 , 50 ).lines.toArray
453+ assert(lines.size == 5 && lines.forall(_.size <= 50 ))
454+
455+ lines = mat.toString(5 , 100 ).lines.toArray
456+ assert(lines.size == 5 && lines.forall(_.size <= 100 ))
457+ }
442458}
Original file line number Diff line number Diff line change @@ -64,8 +64,12 @@ object MimaExcludes {
6464 // SPARK-6492 Fix deadlock in SparkContext.stop()
6565 ProblemFilters .exclude[MissingMethodProblem ](" org.apache.spark.SparkContext.org$" +
6666 " apache$spark$SparkContext$$SPARK_CONTEXT_CONSTRUCTOR_LOCK" )
67+ )++ Seq (
68+ // SPARK-6693 add tostring with max lines and width for matrix
69+ ProblemFilters .exclude[MissingMethodProblem ](" org.apache.spark.mllib.linalg.Matrix.toString" )
6770 )
6871
72+
6973 case v if v.startsWith(" 1.3" ) =>
7074 Seq (
7175 MimaBuild .excludeSparkPackage(" deploy" ),
You can’t perform that action at this time.
0 commit comments