Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Refactor noise #26

Merged
merged 10 commits into from
Nov 30, 2021
Merged

Refactor noise #26

merged 10 commits into from
Nov 30, 2021

Conversation

ETY-13
Copy link
Collaborator

@ETY-13 ETY-13 commented Nov 13, 2021

Refactored noise to c++17:
noise.c and noise.h are converted into cpp and hpp files. Noise is made into a class with the functions encapsulated as member functions. The initnoise() function is converted into a constructor for Noise.

Alias functions:
Alias free (global) functions, initnoise(), noise(), Dnoise(), turbulence(), are created to provide backward compatibility to older codes that call these functions, without needing to use the dot method. These functions are marked as deprecated.

Testing:
test_noise.cpp contain the test for both the c and c++17 version of noise. The test uses rand(), which can lead to different outcome depending on the compiler, even though seeded. The outcomes should be the same for both c and c++17 versions, ensuring that nothing changes from c to c++17. To make the test work, run the test on c version, change the number so the test passes for c, then run the test again on c++17 version, which should also pass.

Copy link
Collaborator

@cinderbdt cinderbdt left a comment

Choose a reason for hiding this comment

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

This looks good. Thanks @ETY-13.

EPR/Library/tests/Makeray.txt Outdated Show resolved Hide resolved
Copy link
Owner

@dgpalmieri dgpalmieri left a comment

Choose a reason for hiding this comment

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

Looks good overall, only a couple small changes!

EPR/Library/noise.cpp Outdated Show resolved Hide resolved
EPR/Library/noise.cpp Show resolved Hide resolved
EPR/Library/noise.cpp Show resolved Hide resolved
}

TEST_CASE("Testing noise: Simple test"){
srand(10);
Copy link
Owner

Choose a reason for hiding this comment

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

+1 avoiding rand() and srand()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will need to use srand() since the c version uses rand(). This make sure that random sequence will be the same when running the test for the c version (and also the c++ version). It is hard to test randomness without it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@dgpalmieri
Copy link
Owner

I think that part of updating this module would be upgrading from rand() to random_device. If you pass a seed around, will a random_device seeded in noise.cpp generate the same sequence if you use the same seed in the test file?

@cinderbdt
Copy link
Collaborator

I think that part of updating this module would be upgrading from rand() to random_device. If you pass a seed around, will a random_device seeded in noise.cpp generate the same sequence if you use the same seed in the test file?

I'm confused why we would be wanting to generate the "same" randomness. We can determine if the same quality of random comes out? relevant SO

@cinderbdt cinderbdt mentioned this pull request Nov 18, 2021
Copy link
Collaborator

@cinderbdt cinderbdt left a comment

Choose a reason for hiding this comment

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

I defer to the open review by @dgpalmieri. This review is closed.

@dgpalmieri
Copy link
Owner

dgpalmieri commented Nov 19, 2021

I'm confused why we would be wanting to generate the "same" randomness.

My thought was that that would make it easy to test, but if there's a better way (that is reasonable in our timeframe), I completely agree that testing that we can generate two identical random sequences is not exactly testing that the numbers are actually "random".

@mattp0
Copy link
Collaborator

mattp0 commented Nov 28, 2021

I'm confused why we would be wanting to generate the "same" randomness.

My thought was that that would make it easy to test, but if there's a better way (that is reasonable in our timeframe), I completely agree that testing that we can generate two identical random sequences is not exactly testing that the numbers are actually "random".

I agree that seeding random makes testing easier

Copy link
Owner

@dgpalmieri dgpalmieri left a comment

Choose a reason for hiding this comment

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

LGTM!

@mattp0 mattp0 merged commit 88f82a9 into main Nov 30, 2021
@dgpalmieri dgpalmieri deleted the refactor_noise branch December 1, 2021 06:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants