Skip to content

Made random data generation generic.#102

Merged
lemire merged 2 commits into
fast-pack:masterfrom
cbsmith:cbsmith-genrandom
Feb 20, 2023
Merged

Made random data generation generic.#102
lemire merged 2 commits into
fast-pack:masterfrom
cbsmith:cbsmith-genrandom

Conversation

@cbsmith

@cbsmith cbsmith commented Feb 16, 2023

Copy link
Copy Markdown
Contributor

Per discussion, making this a separate pull request.

Also switched to using std::generate_n to fill vectors instead of a for
loop.
@lemire

lemire commented Feb 16, 2023

Copy link
Copy Markdown
Member

@cbsmith Thanks.

@cbsmith

cbsmith commented Feb 16, 2023

Copy link
Copy Markdown
Contributor Author

Hrm... not sure why the build failures are occurring. I'll take a look at this later tonight.

template<typename T>
void _genDataRandom(std::vector<T>& v, uint32_t values) {
v.clear();
std::mt19937_64 e2(123456);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not related to the PR, but the test might have discovered some hidden issues if it didn't use fixed seed. Perhaps, using device_random or time to seed generator and then, saving the seed is a better approach: If a test fails, then it should report the seed to be able to repro the test case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That seems like a good suggestion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that it is most helpful to use fixed seeds.

Comment thread unittest/test_fastpfor.cpp Outdated
Comment on lines 114 to 115
void _genDataRandom(std::vector<T>& v, uint32_t values) {
v.clear();

@pps83 pps83 Feb 19, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
void _genDataRandom(std::vector<T>& v, uint32_t values) {
v.clear();
void _genDataRandom(std::vector<T>& v, size_t valuesCount) {
v.resize(valuesCount);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should fix the crash

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I realized this just now as I got a chance to look at this again. I'm kind of surprised the tests passed on my own machine though. A little freaky.

@cbsmith

cbsmith commented Feb 20, 2023

Copy link
Copy Markdown
Contributor Author

Fixed the vector sizing error. Tests should pass now.

@lemire

lemire commented Feb 20, 2023

Copy link
Copy Markdown
Member

Running tests now.

@lemire

lemire commented Feb 20, 2023

Copy link
Copy Markdown
Member

Merging.

@lemire
lemire merged commit 9dab1fb into fast-pack:master Feb 20, 2023
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