-
Notifications
You must be signed in to change notification settings - Fork 188
[stdlib_math] add is_close
routines.
#488
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
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d395740
add `is_close` in `stdlib_math`.
zoziha 9cebec7
Fix a warning in `arange` and avoid type conversion.
zoziha 909d492
Merge branch 'master' into add_close
zoziha 7c8a8fb
Merge branch 'master' into add_close
zoziha c3d0bdd
Update stdlib_math.is_close, like python math.isclose
zoziha 71021bb
Merge branch 'master' into add_close
zoziha f9acfbe
Fix src/makefile.manual
zoziha e583de5
Merge branch 'add_close' of https://github.com/fortran-fans/stdlib in…
zoziha d477d5a
Add `all_close` function in `stdlib_math`.
zoziha 6fe1529
Merge branch 'master' into add_close
zoziha 064e7f3
Change the `all_close` implementation: gcc9 not support `select rank`.
zoziha 7e36e58
Merge branch 'add_close' of https://github.com/fortran-fans/stdlib in…
zoziha 122837d
Add `pure` label for `all_close`.
zoziha 6eb25dd
Merge branch 'master' into add_close
zoziha adfb820
Add `equal_nan` argument,
zoziha 53874c9
Merge branch 'master' into add_close
zoziha 268cedc
Update tests for **_close,
zoziha 549ee96
Remove old tests for **_close.
zoziha 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
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
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,24 @@ | ||
#:include "common.fypp" | ||
#:set RANKS = range(1, MAXRANK + 1) | ||
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES | ||
|
||
submodule (stdlib_math) stdlib_math_all_close | ||
|
||
implicit none | ||
|
||
contains | ||
|
||
#:for k1, t1 in RC_KINDS_TYPES | ||
#:for r1 in RANKS | ||
logical pure module function all_close_${r1}$_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol) result(close) | ||
|
||
${t1}$, intent(in) :: a${ranksuffix(r1)}$, b${ranksuffix(r1)}$ | ||
real(${k1}$), intent(in), optional :: rel_tol, abs_tol | ||
|
||
close = all(is_close(a, b, rel_tol, abs_tol)) | ||
|
||
end function all_close_${r1}$_${t1[0]}$${k1}$ | ||
#:endfor | ||
#:endfor | ||
|
||
end submodule stdlib_math_all_close |
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,33 @@ | ||||||
#:include "common.fypp" | ||||||
|
||||||
submodule(stdlib_math) stdlib_math_is_close | ||||||
|
||||||
contains | ||||||
|
||||||
#! Determines whether the values of `a` and `b` are close. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
#:for k1, t1 in REAL_KINDS_TYPES | ||||||
elemental module function is_close_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol) result(close) | ||||||
${t1}$, intent(in) :: a, b | ||||||
real(${k1}$), intent(in), optional :: rel_tol, abs_tol | ||||||
logical :: close | ||||||
|
||||||
close = abs(a - b) <= max( abs(optval(rel_tol, 1.0e-9_${k1}$)*max(abs(a), abs(b))), & | ||||||
abs(optval(abs_tol, 0.0_${k1}$)) ) | ||||||
|
||||||
end function is_close_${t1[0]}$${k1}$ | ||||||
#:endfor | ||||||
|
||||||
#:for k1, t1 in CMPLX_KINDS_TYPES | ||||||
elemental module function is_close_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol) result(close) | ||||||
${t1}$, intent(in) :: a, b | ||||||
real(${k1}$), intent(in), optional :: rel_tol, abs_tol | ||||||
logical :: close | ||||||
|
||||||
close = is_close_r${k1}$(a%re, b%re, rel_tol, abs_tol) .and. & | ||||||
is_close_r${k1}$(a%im, b%im, rel_tol, abs_tol) | ||||||
|
||||||
end function is_close_${t1[0]}$${k1}$ | ||||||
#:endfor | ||||||
|
||||||
end submodule stdlib_math_is_close |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
ADDTEST(stdlib_math) | ||
ADDTEST(linspace) | ||
ADDTEST(logspace) | ||
ADDTEST(math_arange) | ||
ADDTEST(math_arange) | ||
ADDTEST(math_is_close) | ||
ADDTEST(math_all_close) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
PROGS_SRC = test_stdlib_math.f90 test_linspace.f90 test_logspace.f90 \ | ||
test_math_arange.f90 | ||
test_math_arange.f90 \ | ||
test_math_is_close.f90 \ | ||
test_math_all_close.f90 | ||
|
||
|
||
include ../Makefile.manual.test.mk |
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.