Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

Xuefeng-Zhu
Copy link
Contributor

No description provided.

data[k] = deviation * Math.random() + mean;

return Matrix.fromTypedArray(data, [i, j]);
return Matrix.fill(count, function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undefined variable count

Copy link
Contributor

@bartvanandel bartvanandel left a 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;
Copy link
Contributor

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.

  1. When value() returns false, code will try to set data[k] the function instead.
  2. 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@mateogianolio
Copy link
Owner

See changes in #101.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants