-
-
Notifications
You must be signed in to change notification settings - Fork 142
Utils Bindings #180
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
Merged
Merged
Utils Bindings #180
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c1bee63
utils bindings
codeboy5 184ef44
style fix
codeboy5 d5f8c9c
more bindings and tests
codeboy5 7da5fe7
more bindings and tests
codeboy5 65923f3
bindings for add,subtract and sqaure
codeboy5 b5cf907
style fix and TODO added
codeboy5 36cb188
throwing runtime error during invalid operations
codeboy5 61e825c
removed TODO
codeboy5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import pytest | ||
| import pydp as dp | ||
| import math | ||
|
|
||
|
|
||
| def test_default_epsilon(): | ||
| assert dp.util.default_epsilon() == math.log(3) | ||
|
|
||
|
|
||
| def test_next_power_positive(): | ||
| kTolerance = 1e-5 | ||
| npp1 = dp.util.get_next_power_of_two(3.0) | ||
| npp2 = dp.util.get_next_power_of_two(5.0) | ||
| npp3 = dp.util.get_next_power_of_two(7.9) | ||
| assert abs(npp1 - 4) < kTolerance | ||
| assert abs(npp2 - 8) < kTolerance | ||
| assert abs(npp3 - 8) < kTolerance | ||
|
|
||
|
|
||
| def test_next_power_exact_positive(): | ||
| kTolerance = 1e-5 | ||
| npep1 = dp.util.get_next_power_of_two(2.0) | ||
| npep2 = dp.util.get_next_power_of_two(8.0) | ||
| assert abs(npep1 - 2) < kTolerance | ||
| assert abs(npep2 - 8) < kTolerance | ||
|
|
||
|
|
||
| def test_next_power_one(): | ||
| kTolerance = 1e-5 | ||
| npo = dp.util.get_next_power_of_two(1.0) | ||
| assert abs(npo - 1) < kTolerance | ||
|
|
||
|
|
||
| def test_next_power_negative(): | ||
| kTolerance = 1e-5 | ||
| npn1 = dp.util.get_next_power_of_two(0.4) | ||
| npn2 = dp.util.get_next_power_of_two(0.2) | ||
| assert abs(npn1 - 0.5) < kTolerance | ||
| assert abs(npn2 - 0.25) < kTolerance | ||
|
|
||
|
|
||
| def test_next_power_exact_negative(): | ||
| kTolerance = 1e-5 | ||
| npn1 = dp.util.get_next_power_of_two(0.5) | ||
| npn2 = dp.util.get_next_power_of_two(0.125) | ||
| assert abs(npn1 - 0.5) < kTolerance | ||
| assert abs(npn2 - 0.125) < kTolerance | ||
|
|
||
|
|
||
| def test_round_positive(): | ||
| kTolerance = 1e-5 | ||
| rp1 = dp.util.round_to_nearest_multiple(4.9, 2.0) | ||
| rp2 = dp.util.round_to_nearest_multiple(5.1, 2.0) | ||
| assert abs(rp1 - 4) < kTolerance | ||
| assert abs(rp2 - 6) < kTolerance | ||
|
|
||
|
|
||
| def test_round_negative(): | ||
| kTolerance = 1e-5 | ||
| rn1 = dp.util.round_to_nearest_multiple(-4.9, 2.0) | ||
| rn2 = dp.util.round_to_nearest_multiple(-5.1, 2.0) | ||
| assert abs(rn1 + 4) < kTolerance | ||
| assert abs(rn2 + 6) < kTolerance | ||
|
|
||
|
|
||
| def test_round_positive_ties(): | ||
| kTolerance = 1e-5 | ||
| rpt = dp.util.round_to_nearest_multiple(5.0, 2.0) | ||
| assert abs(rpt - 6.0) < kTolerance | ||
|
|
||
|
|
||
| def test_round_negative_ties(): | ||
| kTolerance = 1e-5 | ||
| rnt = dp.util.round_to_nearest_multiple(-5.0, 2.0) | ||
| assert abs(rnt + 4.0) < kTolerance | ||
|
|
||
|
|
||
| def test_statistics(): | ||
| a = [1.0, 5.0, 7.0, 9.0, 13.0] | ||
| assert dp.util.mean(a) == 7.0 | ||
| assert dp.util.variance(a) == 16.0 | ||
| assert dp.util.standard_deviation(a) == 4.0 | ||
| assert dp.util.order_statistics(0.6, a) == 8.0 | ||
| assert dp.util.order_statistics(0, a) == 1.0 | ||
| assert dp.util.order_statistics(1, a) == 13.0 | ||
|
|
||
|
|
||
| def test_vector_filter(): | ||
| v = [1.0, 2.0, 2.0, 3.0] | ||
| selection = [False, True, True, False] | ||
| expected = [2.0, 2.0] | ||
| assert expected == dp.util.vector_filter(v, selection) | ||
|
|
||
|
|
||
| def test_vector_to_string(): | ||
| v = [1.0, 2.0, 2.0, 3.0] | ||
| expected = "[1, 2, 2, 3]" | ||
| assert dp.util.vector_to_string(v) == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.