-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-8920] [MLlib] Add @since tags to mllib.linalg #7729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c4f7a4
Add @since tag to mllib.linalg.*
2e5ebd6
Add @since tag to mllib.linalg.*
3be09e9
Remove @since tag from sealed traits Vector and Matrix
3012864
Fixed various tagging issues per review by @mechcoder
09aad77
Remove @since tag from toString and confirmed alternate constructor h…
68b3ed9
Correct @since tag versions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,6 +229,7 @@ private[spark] class MatrixUDT extends UserDefinedType[Matrix] { | |
| * @param values matrix entries in column major if not transposed or in row major otherwise | ||
| * @param isTransposed whether the matrix is transposed. If true, `values` stores the matrix in | ||
| * row major. | ||
| * @since 1.0.0 | ||
| */ | ||
| @SQLUserDefinedType(udt = classOf[MatrixUDT]) | ||
| class DenseMatrix( | ||
|
|
@@ -254,6 +255,7 @@ class DenseMatrix( | |
| * @param numRows number of rows | ||
| * @param numCols number of columns | ||
| * @param values matrix entries in column major | ||
| * @since 1.3.0 | ||
| */ | ||
| def this(numRows: Int, numCols: Int, values: Array[Double]) = | ||
| this(numRows, numCols, values, false) | ||
|
|
@@ -279,6 +281,9 @@ class DenseMatrix( | |
|
|
||
| private[mllib] def apply(i: Int): Double = values(i) | ||
|
|
||
| /** | ||
| * @since 1.3.0 | ||
| */ | ||
| override def apply(i: Int, j: Int): Double = values(index(i, j)) | ||
|
|
||
| private[mllib] def index(i: Int, j: Int): Int = { | ||
|
|
@@ -289,6 +294,9 @@ class DenseMatrix( | |
| values(index(i, j)) = v | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.4.0 | ||
| */ | ||
| override def copy: DenseMatrix = new DenseMatrix(numRows, numCols, values.clone()) | ||
|
|
||
| private[spark] def map(f: Double => Double) = new DenseMatrix(numRows, numCols, values.map(f), | ||
|
|
@@ -304,6 +312,9 @@ class DenseMatrix( | |
| this | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.3.0 | ||
| */ | ||
| override def transpose: DenseMatrix = new DenseMatrix(numCols, numRows, values, !isTransposed) | ||
|
|
||
| private[spark] override def foreachActive(f: (Int, Int, Double) => Unit): Unit = { | ||
|
|
@@ -334,13 +345,20 @@ class DenseMatrix( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.5.0 | ||
| */ | ||
| override def numNonzeros: Int = values.count(_ != 0) | ||
|
|
||
| /** | ||
| * @since 1.5.0 | ||
| */ | ||
| override def numActives: Int = values.length | ||
|
|
||
| /** | ||
| * Generate a `SparseMatrix` from the given `DenseMatrix`. The new matrix will have isTransposed | ||
| * set to false. | ||
| * @since 1.3.0 | ||
| */ | ||
| def toSparse: SparseMatrix = { | ||
| val spVals: MArrayBuilder[Double] = new MArrayBuilder.ofDouble | ||
|
|
@@ -368,6 +386,7 @@ class DenseMatrix( | |
|
|
||
| /** | ||
| * Factory methods for [[org.apache.spark.mllib.linalg.DenseMatrix]]. | ||
| * @since 1.3.0 | ||
| */ | ||
| object DenseMatrix { | ||
|
|
||
|
|
@@ -376,6 +395,7 @@ object DenseMatrix { | |
| * @param numRows number of rows of the matrix | ||
| * @param numCols number of columns of the matrix | ||
| * @return `DenseMatrix` with size `numRows` x `numCols` and values of zeros | ||
| * @since 1.3.0 | ||
| */ | ||
| def zeros(numRows: Int, numCols: Int): DenseMatrix = { | ||
| require(numRows.toLong * numCols <= Int.MaxValue, | ||
|
|
@@ -388,6 +408,7 @@ object DenseMatrix { | |
| * @param numRows number of rows of the matrix | ||
| * @param numCols number of columns of the matrix | ||
| * @return `DenseMatrix` with size `numRows` x `numCols` and values of ones | ||
| * @since 1.3.0 | ||
| */ | ||
| def ones(numRows: Int, numCols: Int): DenseMatrix = { | ||
| require(numRows.toLong * numCols <= Int.MaxValue, | ||
|
|
@@ -399,6 +420,7 @@ object DenseMatrix { | |
| * Generate an Identity Matrix in `DenseMatrix` format. | ||
| * @param n number of rows and columns of the matrix | ||
| * @return `DenseMatrix` with size `n` x `n` and values of ones on the diagonal | ||
| * @since 1.3.0 | ||
| */ | ||
| def eye(n: Int): DenseMatrix = { | ||
| val identity = DenseMatrix.zeros(n, n) | ||
|
|
@@ -416,6 +438,7 @@ object DenseMatrix { | |
| * @param numCols number of columns of the matrix | ||
| * @param rng a random number generator | ||
| * @return `DenseMatrix` with size `numRows` x `numCols` and values in U(0, 1) | ||
| * @since 1.3.0 | ||
| */ | ||
| def rand(numRows: Int, numCols: Int, rng: Random): DenseMatrix = { | ||
| require(numRows.toLong * numCols <= Int.MaxValue, | ||
|
|
@@ -429,6 +452,7 @@ object DenseMatrix { | |
| * @param numCols number of columns of the matrix | ||
| * @param rng a random number generator | ||
| * @return `DenseMatrix` with size `numRows` x `numCols` and values in N(0, 1) | ||
| * @since 1.3.0 | ||
| */ | ||
| def randn(numRows: Int, numCols: Int, rng: Random): DenseMatrix = { | ||
| require(numRows.toLong * numCols <= Int.MaxValue, | ||
|
|
@@ -441,6 +465,7 @@ object DenseMatrix { | |
| * @param vector a `Vector` that will form the values on the diagonal of the matrix | ||
| * @return Square `DenseMatrix` with size `values.length` x `values.length` and `values` | ||
| * on the diagonal | ||
| * @since 1.3.0 | ||
| */ | ||
| def diag(vector: Vector): DenseMatrix = { | ||
| val n = vector.size | ||
|
|
@@ -476,6 +501,7 @@ object DenseMatrix { | |
| * @param isTransposed whether the matrix is transposed. If true, the matrix can be considered | ||
| * Compressed Sparse Row (CSR) format, where `colPtrs` behaves as rowPtrs, | ||
| * and `rowIndices` behave as colIndices, and `values` are stored in row major. | ||
| * @since 1.2.0 | ||
| */ | ||
| @SQLUserDefinedType(udt = classOf[MatrixUDT]) | ||
| class SparseMatrix( | ||
|
|
@@ -513,6 +539,7 @@ class SparseMatrix( | |
| * @param rowIndices the row index of the entry. They must be in strictly increasing | ||
| * order for each column | ||
| * @param values non-zero matrix entries in column major | ||
| * @since 1.3.0 | ||
| */ | ||
| def this( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well. |
||
| numRows: Int, | ||
|
|
@@ -530,6 +557,9 @@ class SparseMatrix( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.3.0 | ||
| */ | ||
| override def apply(i: Int, j: Int): Double = { | ||
| val ind = index(i, j) | ||
| if (ind < 0) 0.0 else values(ind) | ||
|
|
@@ -553,6 +583,9 @@ class SparseMatrix( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.4.0 | ||
| */ | ||
| override def copy: SparseMatrix = { | ||
| new SparseMatrix(numRows, numCols, colPtrs, rowIndices, values.clone()) | ||
| } | ||
|
|
@@ -570,6 +603,9 @@ class SparseMatrix( | |
| this | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.3.0 | ||
| */ | ||
| override def transpose: SparseMatrix = | ||
| new SparseMatrix(numCols, numRows, colPtrs, rowIndices, values, !isTransposed) | ||
|
|
||
|
|
@@ -603,19 +639,27 @@ class SparseMatrix( | |
| /** | ||
| * Generate a `DenseMatrix` from the given `SparseMatrix`. The new matrix will have isTransposed | ||
| * set to false. | ||
| * @since 1.3.0 | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tags for numNonzeros and numActives are missing. |
||
| def toDense: DenseMatrix = { | ||
| new DenseMatrix(numRows, numCols, toArray) | ||
| } | ||
|
|
||
| /** | ||
| * @since 1.5.0 | ||
| */ | ||
| override def numNonzeros: Int = values.count(_ != 0) | ||
|
|
||
| /** | ||
| * @since 1.5.0 | ||
| */ | ||
| override def numActives: Int = values.length | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Factory methods for [[org.apache.spark.mllib.linalg.SparseMatrix]]. | ||
| * @since 1.3.0 | ||
| */ | ||
| object SparseMatrix { | ||
|
|
||
|
|
@@ -627,6 +671,7 @@ object SparseMatrix { | |
| * @param numCols number of columns of the matrix | ||
| * @param entries Array of (i, j, value) tuples | ||
| * @return The corresponding `SparseMatrix` | ||
| * @since 1.3.0 | ||
| */ | ||
| def fromCOO(numRows: Int, numCols: Int, entries: Iterable[(Int, Int, Double)]): SparseMatrix = { | ||
| val sortedEntries = entries.toSeq.sortBy(v => (v._2, v._1)) | ||
|
|
@@ -675,6 +720,7 @@ object SparseMatrix { | |
| * Generate an Identity Matrix in `SparseMatrix` format. | ||
| * @param n number of rows and columns of the matrix | ||
| * @return `SparseMatrix` with size `n` x `n` and values of ones on the diagonal | ||
| * @since 1.3.0 | ||
| */ | ||
| def speye(n: Int): SparseMatrix = { | ||
| new SparseMatrix(n, n, (0 to n).toArray, (0 until n).toArray, Array.fill(n)(1.0)) | ||
|
|
@@ -744,6 +790,7 @@ object SparseMatrix { | |
| * @param density the desired density for the matrix | ||
| * @param rng a random number generator | ||
| * @return `SparseMatrix` with size `numRows` x `numCols` and values in U(0, 1) | ||
| * @since 1.3.0 | ||
| */ | ||
| def sprand(numRows: Int, numCols: Int, density: Double, rng: Random): SparseMatrix = { | ||
| val mat = genRandMatrix(numRows, numCols, density, rng) | ||
|
|
@@ -757,6 +804,7 @@ object SparseMatrix { | |
| * @param density the desired density for the matrix | ||
| * @param rng a random number generator | ||
| * @return `SparseMatrix` with size `numRows` x `numCols` and values in N(0, 1) | ||
| * @since 1.3.0 | ||
| */ | ||
| def sprandn(numRows: Int, numCols: Int, density: Double, rng: Random): SparseMatrix = { | ||
| val mat = genRandMatrix(numRows, numCols, density, rng) | ||
|
|
@@ -768,6 +816,7 @@ object SparseMatrix { | |
| * @param vector a `Vector` that will form the values on the diagonal of the matrix | ||
| * @return Square `SparseMatrix` with size `values.length` x `values.length` and non-zero | ||
| * `values` on the diagonal | ||
| * @since 1.3.0 | ||
| */ | ||
| def spdiag(vector: Vector): SparseMatrix = { | ||
| val n = vector.size | ||
|
|
@@ -784,6 +833,7 @@ object SparseMatrix { | |
|
|
||
| /** | ||
| * Factory methods for [[org.apache.spark.mllib.linalg.Matrix]]. | ||
| * @since 1.0.0 | ||
| */ | ||
| object Matrices { | ||
|
|
||
|
|
@@ -793,6 +843,7 @@ object Matrices { | |
| * @param numRows number of rows | ||
| * @param numCols number of columns | ||
| * @param values matrix entries in column major | ||
| * @since 1.0.0 | ||
| */ | ||
| def dense(numRows: Int, numCols: Int, values: Array[Double]): Matrix = { | ||
| new DenseMatrix(numRows, numCols, values) | ||
|
|
@@ -806,6 +857,7 @@ object Matrices { | |
| * @param colPtrs the index corresponding to the start of a new column | ||
| * @param rowIndices the row index of the entry | ||
| * @param values non-zero matrix entries in column major | ||
| * @since 1.2.0 | ||
| */ | ||
| def sparse( | ||
| numRows: Int, | ||
|
|
@@ -839,6 +891,7 @@ object Matrices { | |
| * @param numRows number of rows of the matrix | ||
| * @param numCols number of columns of the matrix | ||
| * @return `Matrix` with size `numRows` x `numCols` and values of zeros | ||
| * @since 1.2.0 | ||
| */ | ||
| def zeros(numRows: Int, numCols: Int): Matrix = DenseMatrix.zeros(numRows, numCols) | ||
|
|
||
|
|
@@ -847,20 +900,23 @@ object Matrices { | |
| * @param numRows number of rows of the matrix | ||
| * @param numCols number of columns of the matrix | ||
| * @return `Matrix` with size `numRows` x `numCols` and values of ones | ||
| * @since 1.2.0 | ||
| */ | ||
| def ones(numRows: Int, numCols: Int): Matrix = DenseMatrix.ones(numRows, numCols) | ||
|
|
||
| /** | ||
| * Generate a dense Identity Matrix in `Matrix` format. | ||
| * @param n number of rows and columns of the matrix | ||
| * @return `Matrix` with size `n` x `n` and values of ones on the diagonal | ||
| * @since 1.2.0 | ||
| */ | ||
| def eye(n: Int): Matrix = DenseMatrix.eye(n) | ||
|
|
||
| /** | ||
| * Generate a sparse Identity Matrix in `Matrix` format. | ||
| * @param n number of rows and columns of the matrix | ||
| * @return `Matrix` with size `n` x `n` and values of ones on the diagonal | ||
| * @since 1.3.0 | ||
| */ | ||
| def speye(n: Int): Matrix = SparseMatrix.speye(n) | ||
|
|
||
|
|
@@ -870,6 +926,7 @@ object Matrices { | |
| * @param numCols number of columns of the matrix | ||
| * @param rng a random number generator | ||
| * @return `Matrix` with size `numRows` x `numCols` and values in U(0, 1) | ||
| * @since 1.2.0 | ||
| */ | ||
| def rand(numRows: Int, numCols: Int, rng: Random): Matrix = | ||
| DenseMatrix.rand(numRows, numCols, rng) | ||
|
|
@@ -881,6 +938,7 @@ object Matrices { | |
| * @param density the desired density for the matrix | ||
| * @param rng a random number generator | ||
| * @return `Matrix` with size `numRows` x `numCols` and values in U(0, 1) | ||
| * @since 1.3.0 | ||
| */ | ||
| def sprand(numRows: Int, numCols: Int, density: Double, rng: Random): Matrix = | ||
| SparseMatrix.sprand(numRows, numCols, density, rng) | ||
|
|
@@ -891,6 +949,7 @@ object Matrices { | |
| * @param numCols number of columns of the matrix | ||
| * @param rng a random number generator | ||
| * @return `Matrix` with size `numRows` x `numCols` and values in N(0, 1) | ||
| * @since 1.2.0 | ||
| */ | ||
| def randn(numRows: Int, numCols: Int, rng: Random): Matrix = | ||
| DenseMatrix.randn(numRows, numCols, rng) | ||
|
|
@@ -902,6 +961,7 @@ object Matrices { | |
| * @param density the desired density for the matrix | ||
| * @param rng a random number generator | ||
| * @return `Matrix` with size `numRows` x `numCols` and values in N(0, 1) | ||
| * @since 1.3.0 | ||
| */ | ||
| def sprandn(numRows: Int, numCols: Int, density: Double, rng: Random): Matrix = | ||
| SparseMatrix.sprandn(numRows, numCols, density, rng) | ||
|
|
@@ -911,6 +971,7 @@ object Matrices { | |
| * @param vector a `Vector` that will form the values on the diagonal of the matrix | ||
| * @return Square `Matrix` with size `values.length` x `values.length` and `values` | ||
| * on the diagonal | ||
| * @since 1.2.0 | ||
| */ | ||
| def diag(vector: Vector): Matrix = DenseMatrix.diag(vector) | ||
|
|
||
|
|
@@ -920,6 +981,7 @@ object Matrices { | |
| * a sparse matrix. If the Array is empty, an empty `DenseMatrix` will be returned. | ||
| * @param matrices array of matrices | ||
| * @return a single `Matrix` composed of the matrices that were horizontally concatenated | ||
| * @since 1.3.0 | ||
| */ | ||
| def horzcat(matrices: Array[Matrix]): Matrix = { | ||
| if (matrices.isEmpty) { | ||
|
|
@@ -978,6 +1040,7 @@ object Matrices { | |
| * a sparse matrix. If the Array is empty, an empty `DenseMatrix` will be returned. | ||
| * @param matrices array of matrices | ||
| * @return a single `Matrix` composed of the matrices that were vertically concatenated | ||
| * @since 1.3.0 | ||
| */ | ||
| def vertcat(matrices: Array[Matrix]): Matrix = { | ||
| if (matrices.isEmpty) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MechCoder I sincerely apologize for my ignorance here! I am a little new to Scala and am not sure what I am missing here. I will be happy to fix it if you can provide some clarification. I have fixed the other errors that you identified below and will update the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh never mind, I could notice that from the diff view :( . Looks all right to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) Thanks!