-
-
Notifications
You must be signed in to change notification settings - Fork 836
refactor: add support for ratios evaluating as infinity in math/base/tools/evalrational-compile-c
#1970
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
refactor: add support for ratios evaluating as infinity in math/base/tools/evalrational-compile-c
#1970
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
53f9964
refactor: modified evalrational-compile-c
gunjjoshi 29dc6fa
fix: include dtype suffix when serializing infinities
kgryte 857a8ee
fix: address syntax errors
kgryte 4148fc9
test: add test fixtures and update tests to address all function types
kgryte 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
9 changes: 9 additions & 0 deletions
9
...base/tools/evalrational-compile-c/test/fixtures/coefficient_ratio_negative_infinity.c.txt
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,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static double evalrational() { | ||
return -1.0 / 0.0; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ols/evalrational-compile-c/test/fixtures/coefficient_ratio_negative_infinity_custom.c.txt
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,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static float rational123() { | ||
return -1.0f / 0.0f; | ||
} |
9 changes: 9 additions & 0 deletions
9
...base/tools/evalrational-compile-c/test/fixtures/coefficient_ratio_positive_infinity.c.txt
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,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static double evalrational() { | ||
return 1.0 / 0.0; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ols/evalrational-compile-c/test/fixtures/coefficient_ratio_positive_infinity_custom.c.txt
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,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static float rational123() { | ||
return 1.0f / 0.0f; | ||
} |
36 changes: 36 additions & 0 deletions
36
..._modules/@stdlib/math/base/tools/evalrational-compile-c/test/fixtures/evalrational4.c.txt
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,36 @@ | ||
/** | ||
* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). | ||
* | ||
* ## Notes | ||
* | ||
* - Coefficients should be sorted in ascending degree. | ||
* - The implementation uses [Horner's rule][horners-method] for efficient computation. | ||
* | ||
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static double evalrational( const double x ) { | ||
double ax; | ||
double ix; | ||
double s1; | ||
double s2; | ||
if ( x == 0.0 ) { | ||
return -1.0 / 0.0; | ||
} | ||
if ( x < 0.0 ) { | ||
ax = -x; | ||
} else { | ||
ax = x; | ||
} | ||
if ( ax <= 1.0 ) { | ||
s1 = -1.0 + (x * (2.5 + (x * (3.14 + (x * -1.0))))); | ||
s2 = 0.0 + (x * (-3.5 + (x * (2.2 + (x * 1.25))))); | ||
} else { | ||
ix = 1.0 / x; | ||
s1 = -1.0 + (ix * (3.14 + (ix * (2.5 + (ix * -1.0))))); | ||
s2 = 1.25 + (ix * (2.2 + (ix * (-3.5 + (ix * 0.0))))); | ||
} | ||
return s1 / s2; | ||
} |
Oops, something went wrong.
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.