Skip to content

Commit 736c324

Browse files
committed
add ut and exclude
1 parent 420da39 commit 736c324

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

project/MimaExcludes.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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"),

0 commit comments

Comments
 (0)