Skip to content
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

implemented clip function #355

Merged
merged 17 commits into from
May 1, 2021
Merged

Conversation

aman-godara
Copy link
Member

@aman-godara aman-godara commented Mar 21, 2021

Status: Code written is open for review
Regarding: #319
Provided Specifications: checkout #319 (comment)

Status:

  • Implemented clip function in stdlib_math.fypp file
  • added both invalid & valid tests for clip function in test_stdlib_math.f90 file (this .f90 file was created using fypp preprocessor from test_math.fypp file)
  • Make sure the new module builds and tests out using CMakefile builds.
  • Documented clip function in newly created stdlib_math.md file.
  • Make sure the new module builds and tests out using Makefile builds.

@awvwgk

This comment has been minimized.

@aman-godara aman-godara force-pushed the develop_clip branch 2 times, most recently from ebe924a to ba0b259 Compare March 22, 2021 17:20
@milancurcic
Copy link
Member

Thanks @aman-godara. Please write your questions and comments in the issue thread (here) instead of the source code.

@aman-godara
Copy link
Member Author

I have created the 7 functions as requested in #319 (comment) i.e. there is a function for each of the int8, int16, .... , real128 kinds.

Now for my query consider a case where xmin is (let's say) int8 and xmax is (let's say) int16. Now xmin and xmax both belong to the same type (integer) but different kind (int8 and int16 respectively). Will this case be automatically handled by fortran somehow (may be by converting xmin to int16) or should I write a function (similar to the 7 functions that I have already created) to handle a case like this?

@milancurcic
Copy link
Member

Will this case be automatically handled by fortran somehow (may be by converting xmin to int16) or should I write a function (similar to the 7 functions that I have already created) to handle a case like this?

It won't be handled automatically. You'd need to write specific functions for each combination of types and kinds. For integer variants that would be 4^3 = 64 specific functions and for real variants that would be 3^3 = 27 specific functions. And it gets worse if you want to do something like clip(real, int, int).

I don't think it's worth it. Let's simply require all three arguments to be of the same type and kind.

@awvwgk
Copy link
Member

awvwgk commented Mar 22, 2021

Note that you haven't included the new module with the CMake build system yet:

# Create a list of the files to be preprocessed
set(fppFiles
stdlib_bitsets.fypp

As well as the manual Makefiles here:

SRCFYPP =\
stdlib_bitsets_64.fypp \

The module will not be preprocessed and compiled with the current setup.

@aman-godara
Copy link
Member Author

aman-godara commented Mar 22, 2021

Let's simply require all three arguments to be of the same type and kind.

Should I write some validation check in the function to ensure that user gets a warning whenever same type and same kind condition is violated OR will fortran throw an error automatically?

@milancurcic
Copy link
Member

Should I write some validation check in the function to ensure that user gets a warning whenever same type and same kind condition is violated OR will fortran throw an error automatically?

There will be a compile-time error.

@aman-godara aman-godara force-pushed the develop_clip branch 3 times, most recently from 9136fe5 to 477864a Compare March 23, 2021 14:11
@awvwgk awvwgk linked an issue Mar 23, 2021 that may be closed by this pull request
@aman-godara
Copy link
Member Author

aman-godara commented Mar 24, 2021

Should I continue to submit test_math.fypp file directly (currently PR has test_math.fypp file)
OR
Should I submit the .f90 version of test_math.fypp file (which can be created by fypp test_math.fypp test_math.f90 command) since ADDTEST doesn't support .fypp files?

Let me make some updates to demonstrate what I am proposing.

@aman-godara aman-godara force-pushed the develop_clip branch 3 times, most recently from f586e6f to 554f301 Compare March 25, 2021 05:19
…ts.txt and Makefile.manual of tests directory
@aman-godara aman-godara force-pushed the develop_clip branch 3 times, most recently from f8b69c9 to 1b0d0a5 Compare March 26, 2021 11:19
@aman-godara

This comment has been minimized.

@aman-godara aman-godara marked this pull request as ready for review March 26, 2021 13:27
@awvwgk awvwgk added the reviewers needed This patch requires extra eyes label Apr 21, 2021
Copy link
Member

@ivan-pi ivan-pi left a comment

Choose a reason for hiding this comment

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

Just a few minor suggestions, but otherwise looks good to me.

@milancurcic
Copy link
Member

Looking at the test_math.f90 in more detail now, I'm confused why you chose to wrap calls to check() in subroutines that don't seem to do anything else. For example, you have:

    subroutine test_clip_int8(x, xmin, xmax, compare)
        integer(int8), intent(in) :: x, xmin, xmax, compare

        call check(clip(x, xmin, xmax) == compare)

    end subroutine test_clip_int8

and then the same exact subroutine for other type kinds. Then you do

call test_clip_int8(2_int8, -2_int8, 5_int8, 2_int8)

But why not just do

call check(clip(2_int8, -2_int8, 5_int8) == 2_int8)

and get rid of the unnecessary boilerplate? Further, you can now do:

call check(clip(2_int8, -2_int8, 5_int8) == 5_int8, 'Test clip_int8 failed.', warn=.true.)

which will print a helpful message (while not stopping the program) if some of the tests fail.

@aman-godara

This comment has been minimized.

@aman-godara aman-godara requested a review from ivan-pi April 24, 2021 09:45
Copy link
Member

@milancurcic milancurcic left a comment

Choose a reason for hiding this comment

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

I think this is good to go, thank you Aman and reviewers!

@milancurcic
Copy link
Member

We still need one more approval to merge this.

Copy link
Member

@awvwgk awvwgk 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 to get merged.

@awvwgk awvwgk dismissed ivan-pi’s stale review May 1, 2021 15:07

Requests were addressed

@milancurcic
Copy link
Member

Thank you @aman-godara and reviewers!

@milancurcic milancurcic merged commit 5f3e2f5 into fortran-lang:master May 1, 2021
@awvwgk awvwgk removed the reviewers needed This patch requires extra eyes label May 1, 2021
@aman-godara aman-godara deleted the develop_clip branch May 1, 2021 16:22
@aman-godara aman-godara restored the develop_clip branch July 4, 2021 15:50
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.

Proposal for clamp
6 participants