You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by me...@apache.org on 2015/04/10 00:37:47 UTC

spark git commit: [Spark-6693][MLlib]add tostring with max lines and width for matrix

Repository: spark
Updated Branches:
  refs/heads/master a0411aebe -> 9c67049b4


[Spark-6693][MLlib]add tostring with max lines and width for matrix

jira: https://issues.apache.org/jira/browse/SPARK-6693

It's kind of annoying when debugging and found you cannot print out the matrix as you want.

original toString of Matrix only print like following,
0.17810102596909183    0.5616906241468385    ... (10 total)
0.9692861997823815     0.015558159784155756  ...
0.8513015122819192     0.031523763918528847  ...
0.5396875653953941     0.3267864552779176    ...

The   def toString(maxLines : Int, maxWidth : Int) is useful when debuging, logging and saving matrix to files.

Author: Yuhao Yang <hh...@gmail.com>

Closes #5344 from hhbyyh/addToString and squashes the following commits:

19a6836 [Yuhao Yang] remove extra line
6314b21 [Yuhao Yang] add exclude
736c324 [Yuhao Yang] add ut and exclude
420da39 [Yuhao Yang] Merge remote-tracking branch 'upstream/master' into addToString
c22f352 [Yuhao Yang] style change
64a9e0f [Yuhao Yang] add specific to string to matrix


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/9c67049b
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/9c67049b
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/9c67049b

Branch: refs/heads/master
Commit: 9c67049b4ef416a80803ccb958bbac1dd02cc380
Parents: a0411ae
Author: Yuhao Yang <hh...@gmail.com>
Authored: Thu Apr 9 15:37:45 2015 -0700
Committer: Xiangrui Meng <me...@databricks.com>
Committed: Thu Apr 9 15:37:45 2015 -0700

----------------------------------------------------------------------
 .../org/apache/spark/mllib/linalg/Matrices.scala    |  3 +++
 .../apache/spark/mllib/linalg/MatricesSuite.scala   | 16 ++++++++++++++++
 project/MimaExcludes.scala                          |  4 ++++
 3 files changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/9c67049b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala
----------------------------------------------------------------------
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 d1a1740..3fa5e06 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`. */

http://git-wip-us.apache.org/repos/asf/spark/blob/9c67049b/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala
----------------------------------------------------------------------
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 0d2cec5..86119ec 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))
+  }
 }

http://git-wip-us.apache.org/repos/asf/spark/blob/9c67049b/project/MimaExcludes.scala
----------------------------------------------------------------------
diff --git a/project/MimaExcludes.scala b/project/MimaExcludes.scala
index c2d828f..1564bab 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") =>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org