aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala3
-rw-r--r--mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala16
-rw-r--r--project/MimaExcludes.scala4
3 files changed, 23 insertions, 0 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala
index d1a174063c..3fa5e068d1 100644
--- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala
+++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala
@@ -87,6 +87,9 @@ sealed trait Matrix extends Serializable {
/** A human readable representation of the matrix */
override def toString: String = toBreeze.toString()
+ /** A human readable representation of the matrix with maximum lines and width */
+ def toString(maxLines: Int, maxLineWidth: Int): String = toBreeze.toString(maxLines, maxLineWidth)
+
/** Map the values of this matrix using a function. Generates a new matrix. Performs the
* function on only the backing array. For example, an operation such as addition or
* subtraction will only be performed on the non-zero values in a `SparseMatrix`. */
diff --git a/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala b/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala
index 0d2cec58e2..86119ec381 100644
--- a/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala
@@ -439,4 +439,20 @@ class MatricesSuite extends FunSuite {
assert(mUDT.typeName == "matrix")
assert(mUDT.simpleString == "matrix")
}
+
+ test("toString") {
+ val empty = Matrices.ones(0, 0)
+ empty.toString(0, 0)
+
+ val mat = Matrices.rand(5, 10, new Random())
+ mat.toString(-1, -5)
+ mat.toString(0, 0)
+ mat.toString(Int.MinValue, Int.MinValue)
+ mat.toString(Int.MaxValue, Int.MaxValue)
+ var lines = mat.toString(6, 50).lines.toArray
+ assert(lines.size == 5 && lines.forall(_.size <= 50))
+
+ lines = mat.toString(5, 100).lines.toArray
+ assert(lines.size == 5 && lines.forall(_.size <= 100))
+ }
}
diff --git a/project/MimaExcludes.scala b/project/MimaExcludes.scala
index c2d828f982..1564babefa 100644
--- a/project/MimaExcludes.scala
+++ b/project/MimaExcludes.scala
@@ -64,6 +64,10 @@ object MimaExcludes {
// SPARK-6492 Fix deadlock in SparkContext.stop()
ProblemFilters.exclude[MissingMethodProblem]("org.apache.spark.SparkContext.org$" +
"apache$spark$SparkContext$$SPARK_CONTEXT_CONSTRUCTOR_LOCK")
+ )++ Seq(
+ // SPARK-6693 add tostring with max lines and width for matrix
+ ProblemFilters.exclude[MissingMethodProblem](
+ "org.apache.spark.mllib.linalg.Matrix.toString")
)
case v if v.startsWith("1.3") =>