-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Add rand(numRows: Int, numCols: Int) functions #14422
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
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? |
def rand(numRows: Int, numCols: Int): DenseMatrix = { | ||
require(numRows.toLong * numCols <= Int.MaxValue, | ||
s"$numRows x $numCols dense matrix is too large to allocate") | ||
new DenseMatrix(numRows, numCols, Array.fill(numRows * numCols)((new Random).nextDouble())) |
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.
This makes a new RNG for every element, which isn't great.
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.
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()