Add rand(numRows: Int, numCols: Int) functions#14422
Add rand(numRows: Int, numCols: Int) functions#14422xubo245 wants to merge 2 commits intoapache:masterfrom
Conversation
add rand(numRows: Int, numCols: Int) functions to DenseMatrix object,like breeze.linalg.DenseMatrix.rand()
|
we can use it to replace breeze.linalg.DenseMatrix.rand(numRows: Int, numCols: Int) |
|
Can one of the admins verify this patch? |
| @Since("2.0.0") | ||
| def rand(numRows: Int, numCols: Int): DenseMatrix = { | ||
| require(numRows.toLong * numCols <= Int.MaxValue, | ||
| s"$numRows x $numCols dense matrix is too large to allocate") |
There was a problem hiding this comment.
This makes a new RNG for every element, which isn't great.
There was a problem hiding this comment.
Can fix RNG, This makes a new RNG for all element :
val rng = new Random()
new DenseMatrix(numRows, numCols, Array.fill(numRows * numCols)(rng.nextDouble()))
|
Doesn't that need a JIRA, test and PR description maybe? |
|
I add test : #14424 |
|
I guess it might be nicer if the contributions you make follow https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark just like other contributions and I believe usually we put a test together in the related patch ( not in a separate PR).. |
|
@HyukjinKwon Thank you. |
|
Please don't open other PRs for related changes. Usually, you also need a JIRA. Although I understand the use for these methods, is there any use for them in Spark? we probably wouldn't add these things unless Spark itself needed them a few places, or else it was clearly a common task. I am not clear these are. |
|
@srowen sorry, please close the issue. I will learning more before next PR. The PR is only because breeze have the function. In spark ,there is no use for them. |
|
@xubo245 you need to close the issues, we can't do so directly. |
|
ok |
What changes were proposed in this pull request?
(Please fill in changes proposed in this fix)
How was this patch tested?
(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)
(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)
add rand(numRows: Int, numCols: Int) functions to DenseMatrix object,like breeze.linalg.DenseMatrix.rand()