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 #95

Merged
merged 3 commits into from
Jan 18, 2017

Conversation

Xuefeng-Zhu
Copy link
Contributor

@Xuefeng-Zhu Xuefeng-Zhu commented Dec 29, 2016

fill is able to take function for value

i;

for (i = 0; i < count; i++)
data[i] = value;
data[i] = (isValueFn && value()) || value;
Copy link
Owner

Choose a reason for hiding this comment

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

If value() is a function returning 0 the condition will become false and it will erroneously pass the function itself as a value. This results in a Vector filled with NaN fields.

Test:

Vector.fill(5, function () {
  return 0;
});
// [NaN, NaN, NaN, NaN, NaN]

I also think the index i should be passed to the value function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have a look at #101, it used to have the same issue.

@Xuefeng-Zhu
Copy link
Contributor Author

@mateogianolio I have addressed the issue

@mateogianolio mateogianolio merged commit c4562d5 into mateogianolio:master Jan 18, 2017
ukrbublik added a commit to ukrbublik/vectorious-plus that referenced this pull request Aug 20, 2017
- 'make fill take function as value' not applied because of speed regression
- Also modified randomNormal() - added param method, 'Marsaglia' will be default.
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