From a51c80614006956c13e3a8d5b6a424cc68c35392 Mon Sep 17 00:00:00 2001 From: "Peng, Meng" Date: Fri, 26 Aug 2016 12:52:05 +0800 Subject: [PATCH 1/6] Change require condition for Matrix contructor --- .../main/scala/org/apache/spark/ml/linalg/Matrices.scala | 8 +++++--- .../scala/org/apache/spark/mllib/linalg/Matrices.scala | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala index 0ea687bbccc5..510003d4000a 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala @@ -455,9 +455,11 @@ class SparseMatrix @Since("2.0.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") // The Or statement is for the case when the matrix is transposed - require(colPtrs.length == numCols + 1 || colPtrs.length == numRows + 1, "The length of the " + - "column indices should be the number of columns + 1. Currently, colPointers.length: " + - s"${colPtrs.length}, numCols: $numCols") + require(!isTransposed && colPtrs.length == numCols + 1 || + isTransposed && colPtrs.length == numRows + 1, "The length of the column indices should be " + + "the number of columns + 1 if transposed is false, or rows + 1 if transposed is true. " + + "Currently, colPointers.length: " + s"${colPtrs.length}, numCols: $numCols, numRows: " + + "$numRows, isTransposed: $isTransposed") require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") 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 e8f34388cd9f..847ee1c49905 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 @@ -573,9 +573,11 @@ class SparseMatrix @Since("1.3.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") // The Or statement is for the case when the matrix is transposed - require(colPtrs.length == numCols + 1 || colPtrs.length == numRows + 1, "The length of the " + - "column indices should be the number of columns + 1. Currently, colPointers.length: " + - s"${colPtrs.length}, numCols: $numCols") + require(!isTransposed && colPtrs.length == numCols + 1 || + isTransposed && colPtrs.length == numRows + 1, "The length of the column indices should be " + + "the number of columns + 1 if transposed is false, or rows + 1 if transposed is true. " + + "Currently, colPointers.length: " + s"${colPtrs.length}, numCols: $numCols, numRows: " + + "$numRows, isTransposed: $isTransposed") require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") From e5af18f83ae628104989ed71688a0ed42318a46b Mon Sep 17 00:00:00 2001 From: "Peng, Meng" Date: Fri, 26 Aug 2016 17:46:08 +0800 Subject: [PATCH 2/6] use interpolation in a string --- .../src/main/scala/org/apache/spark/ml/linalg/Matrices.scala | 2 +- .../src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala index 510003d4000a..d57d7baeb75e 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala @@ -459,7 +459,7 @@ class SparseMatrix @Since("2.0.0") ( isTransposed && colPtrs.length == numRows + 1, "The length of the column indices should be " + "the number of columns + 1 if transposed is false, or rows + 1 if transposed is true. " + "Currently, colPointers.length: " + s"${colPtrs.length}, numCols: $numCols, numRows: " + - "$numRows, isTransposed: $isTransposed") + s"$numRows, isTransposed: $isTransposed") require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") 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 847ee1c49905..041bcca64eb5 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 @@ -577,7 +577,7 @@ class SparseMatrix @Since("1.3.0") ( isTransposed && colPtrs.length == numRows + 1, "The length of the column indices should be " + "the number of columns + 1 if transposed is false, or rows + 1 if transposed is true. " + "Currently, colPointers.length: " + s"${colPtrs.length}, numCols: $numCols, numRows: " + - "$numRows, isTransposed: $isTransposed") + s"$numRows, isTransposed: $isTransposed") require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") From ea0aa9c0995729e8afa7d6661b3d4cec7327862f Mon Sep 17 00:00:00 2001 From: "Peng, Meng" Date: Fri, 26 Aug 2016 21:23:02 +0800 Subject: [PATCH 3/6] Change the code style --- .../org/apache/spark/ml/linalg/Matrices.scala | 14 +++++++++----- .../org/apache/spark/mllib/linalg/Matrices.scala | 15 +++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala index d57d7baeb75e..efbb7486071b 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala @@ -455,11 +455,15 @@ class SparseMatrix @Since("2.0.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") // The Or statement is for the case when the matrix is transposed - require(!isTransposed && colPtrs.length == numCols + 1 || - isTransposed && colPtrs.length == numRows + 1, "The length of the column indices should be " + - "the number of columns + 1 if transposed is false, or rows + 1 if transposed is true. " + - "Currently, colPointers.length: " + s"${colPtrs.length}, numCols: $numCols, numRows: " + - s"$numRows, isTransposed: $isTransposed") + if (isTransposed) { + require(colPtrs.length == numRows + 1, "The length of the column indices should be " + + "the number of rows + 1. " + + s"Currently, colPointers.length: ${colPtrs.length}, numRows: $numRows.") + } else { + require(colPtrs.length == numCols + 1, "The length of the column indices should be " + + "the number of columns + 1. " + + s"Currently, colPointers.length: ${colPtrs.length}, numCols: $numCols.") + } require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") 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 041bcca64eb5..e7aae681ee7e 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 @@ -572,12 +572,15 @@ class SparseMatrix @Since("1.3.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") - // The Or statement is for the case when the matrix is transposed - require(!isTransposed && colPtrs.length == numCols + 1 || - isTransposed && colPtrs.length == numRows + 1, "The length of the column indices should be " + - "the number of columns + 1 if transposed is false, or rows + 1 if transposed is true. " + - "Currently, colPointers.length: " + s"${colPtrs.length}, numCols: $numCols, numRows: " + - s"$numRows, isTransposed: $isTransposed") + if (isTransposed) { + require(colPtrs.length == numRows + 1, "The length of the column indices should be " + + "the number of rows + 1. " + + s"Currently, colPointers.length: ${colPtrs.length}, numRows: $numRows.") + } else { + require(colPtrs.length == numCols + 1, "The length of the column indices should be " + + "the number of columns + 1. " + + s"Currently, colPointers.length: ${colPtrs.length}, numCols: $numCols.") + } require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") From 3b756ec9b27f3833b9321c0b4358689997a220a7 Mon Sep 17 00:00:00 2001 From: "Peng, Meng" Date: Fri, 26 Aug 2016 21:27:16 +0800 Subject: [PATCH 4/6] delete a comment --- .../src/main/scala/org/apache/spark/ml/linalg/Matrices.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala index efbb7486071b..046b68499147 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala @@ -454,7 +454,6 @@ class SparseMatrix @Since("2.0.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") - // The Or statement is for the case when the matrix is transposed if (isTransposed) { require(colPtrs.length == numRows + 1, "The length of the column indices should be " + "the number of rows + 1. " + From c8b817f4691c2f9a16a5e57357de5d5ff29be0d0 Mon Sep 17 00:00:00 2001 From: "Peng, Meng" Date: Fri, 26 Aug 2016 21:46:07 +0800 Subject: [PATCH 5/6] Change code style --- .../scala/org/apache/spark/ml/linalg/Matrices.scala | 10 ++++------ .../scala/org/apache/spark/mllib/linalg/Matrices.scala | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala index 046b68499147..2cd59d3fd086 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala @@ -455,13 +455,11 @@ class SparseMatrix @Since("2.0.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") if (isTransposed) { - require(colPtrs.length == numRows + 1, "The length of the column indices should be " + - "the number of rows + 1. " + - s"Currently, colPointers.length: ${colPtrs.length}, numRows: $numRows.") + require(colPtrs.length == numRows + 1, + "Expecting ${numRows + 1} colPtrs when numRows = $numRows but got ${colPtrs.length}") } else { - require(colPtrs.length == numCols + 1, "The length of the column indices should be " + - "the number of columns + 1. " + - s"Currently, colPointers.length: ${colPtrs.length}, numCols: $numCols.") + require(colPtrs.length == numCols + 1, + "Expecting ${numCols + 1} colPtrs when numCols = $numCols but got ${colPtrs.length}") } require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") 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 e7aae681ee7e..a601600585e2 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 @@ -573,13 +573,11 @@ class SparseMatrix @Since("1.3.0") ( require(values.length == rowIndices.length, "The number of row indices and values don't match! " + s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") if (isTransposed) { - require(colPtrs.length == numRows + 1, "The length of the column indices should be " + - "the number of rows + 1. " + - s"Currently, colPointers.length: ${colPtrs.length}, numRows: $numRows.") + require(colPtrs.length == numRows + 1, + "Expecting ${numRows + 1} colPtrs when numRows = $numRows but got ${colPtrs.length}") } else { - require(colPtrs.length == numCols + 1, "The length of the column indices should be " + - "the number of columns + 1. " + - s"Currently, colPointers.length: ${colPtrs.length}, numCols: $numCols.") + require(colPtrs.length == numCols + 1, + "Expecting ${numCols + 1} colPtrs when numCols = $numCols but got ${colPtrs.length}") } require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") From dfded28b19f8a62ed6b8a68c6fcaa15b4622aa7b Mon Sep 17 00:00:00 2001 From: "Peng, Meng" Date: Fri, 26 Aug 2016 21:49:07 +0800 Subject: [PATCH 6/6] Change code style --- .../src/main/scala/org/apache/spark/ml/linalg/Matrices.scala | 4 ++-- .../main/scala/org/apache/spark/mllib/linalg/Matrices.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala index 2cd59d3fd086..f1ecc65af110 100644 --- a/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala +++ b/mllib-local/src/main/scala/org/apache/spark/ml/linalg/Matrices.scala @@ -456,10 +456,10 @@ class SparseMatrix @Since("2.0.0") ( s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") if (isTransposed) { require(colPtrs.length == numRows + 1, - "Expecting ${numRows + 1} colPtrs when numRows = $numRows but got ${colPtrs.length}") + s"Expecting ${numRows + 1} colPtrs when numRows = $numRows but got ${colPtrs.length}") } else { require(colPtrs.length == numCols + 1, - "Expecting ${numCols + 1} colPtrs when numCols = $numCols but got ${colPtrs.length}") + s"Expecting ${numCols + 1} colPtrs when numCols = $numCols but got ${colPtrs.length}") } require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}") 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 a601600585e2..4c39cf17f427 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 @@ -574,10 +574,10 @@ class SparseMatrix @Since("1.3.0") ( s"values.length: ${values.length}, rowIndices.length: ${rowIndices.length}") if (isTransposed) { require(colPtrs.length == numRows + 1, - "Expecting ${numRows + 1} colPtrs when numRows = $numRows but got ${colPtrs.length}") + s"Expecting ${numRows + 1} colPtrs when numRows = $numRows but got ${colPtrs.length}") } else { require(colPtrs.length == numCols + 1, - "Expecting ${numCols + 1} colPtrs when numCols = $numCols but got ${colPtrs.length}") + s"Expecting ${numCols + 1} colPtrs when numCols = $numCols but got ${colPtrs.length}") } require(values.length == colPtrs.last, "The last value of colPtrs must equal the number of " + s"elements. values.length: ${values.length}, colPtrs.last: ${colPtrs.last}")