-
Notifications
You must be signed in to change notification settings - Fork 44
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
make fill take function as value for matrix #98
Conversation
data[k] = deviation * Math.random() + mean; | ||
|
||
return Matrix.fromTypedArray(data, [i, j]); | ||
return Matrix.fill(count, function() { |
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.
Undefined variable count
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.
Fix approved, new issue found.
k; | ||
for (k = 0; k < size; k++) | ||
data[k] = value; | ||
data[k] = (isValueFn && value()) || value; |
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.
Two issues with this approach.
- When value() returns false, code will try to set data[k] the function instead.
- Value function should probably take (row, col) as input to improve its usability
Summarized, better use something like this:
data[k] = isValueFn ? value(k / j | 0, k % j) : value;
Note: adapted from Matrix.prototype.map
which uses same approach for row/col computation.
Side note: for consistency of value names fill
should probably use r, c
as arguments: i
and j
are more often used as element indices, not size parameters.
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.
updated
See changes in #101. |
No description provided.