-
Notifications
You must be signed in to change notification settings - Fork 173
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
Bitsets3 #239
Bitsets3 #239
Conversation
Added stdlib_bitsets.f90, stdlib_bitset_64.f90, and stdlib_bitset_large.f90 and modified CMakeLists.txt and Makefile.manual so they should compile the files. [ticket: X]
Added tests/bitsets/test_stdlib_bitset*.f90, tests/bitsets/CMakeLists.txt, and tests/bitsets/Makefile.manual and modified tests/CMakeLists.txt and tests/Makefile.manual to compile the test programs. [ticket: X]
Eliminated unused variables in stdlib_bitset_64.f90, stdlib_bitset_large.f90 and rename variables called ablock to block_ in stdlib_bitset_large.f90 [ticket: X]
Added stdlib/doc/specs/stdlib_bitsets.md [ticket: X]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @wclodius2 for this PR. I will try to review it this weekend or next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a misspelling of the word 'occurred' in this file: "occured" (line 1092)
EDIT: this file
Looks good.
… On Oct 4, 2020, at 11:49 AM, Jeremie Vandenplas ***@***.***> wrote:
@jvdp1 commented on this pull request.
In src/tests/Makefile.manual <#239 (comment)>:
> @@ -10,6 +11,7 @@ all:
test:
$(MAKE) -f Makefile.manual --directory=ascii test
+ $(MAKE) -f Makefile.manual --directoru=bitsets test
⬇️ Suggested change
- $(MAKE) -f Makefile.manual --directoru=bitsets test
+ $(MAKE) -f Makefile.manual --directory=bitsets test
This should allow the Github actions to be successful
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#239 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APTQDOWITSG6CMZ2MNAX2VLSJCYSBANCNFSM4R6QFU5A>.
|
We should really discuss the error handling further in #219 . The 'go to' usage in this function... I'm not a fan xD. I think only one labeled part is needed to achieve the 'return with status' vs 'stop program with error message' desired behavior, with the aid of a error handling module, we could set the message and a flag to switch between the two possible actions, reusing the code. I will bring some working code snippet soon (I hope). |
What is xD? The error handling has several aspects that could be commented on:
It is of course possible to use fypp preprocessing to generate templates for the assignments to and from logical arrays. The assignment procedures are few enough and simple enough that I thought it best to avoid a dependence on the preprocessor, but that is a matter of taste. The addition of more assignments, say to and from integers would probably change my opinion. |
ASCII version of 😆smiling face with closed eyes 1-5. Yes, the current way increases the amount of code, however the main logic can be still clear if we do something like that: subroutine fail_behavior(..., status)
! doing a lot of stuff here
! ...
! case X: found some fatal error
error_handler % status = ERROR_CODE_TO_X
error_handler % message = "Oh no! X happened"
go to 404
! case Y: found other general error
error_handler % status = ERROR_CODE_TO_Y
error_handler % message = "Oh no! Y happened"
go to 404
404 if (present(status)) then
status = error_handler % status
return
else
error stop error_handler % message
end if
end subroutine This is a way we can avoid the code duplication, reusing the go to branching. Note that error_handler should be a object that couples the information about what happened (not reflecting in any way the API I got in mind for a final version).
IMHO, we should use the template system every time that not using it leads to code duplication, since it gets easier to modify and extend the code in the future. (DRY principle). |
FWIW for the error handling what I thought you were proposing was something like
where I can change the code to use |
Indeed, actually this is even better because we don't need retype the branching logic with "go to" statements in every function that may fail and is doable (working example here). To avoid having any boilerplate along the function's main logic, the module that have a specific need should build a function that calls this base function subroutine value_error(expected, got, status)
....
write(message, '("value_error: Expected ",G0,", but got ",G0," instead.")') expected, got
call error_handler(message, ...)
end subroutine
You can clone your repo here, modify it locally and push the commits (It will probably sync with the open PR) |
You can rename and remove a file locally with your OS, and then add/remove, commit, and push with git. |
When I try
I get the error message
Is there something wrong with my syntax/repository name? |
This is the wrong URL, please do the following:
|
…set*.f90 Changed makeefiles to preprocess ths stdlib_bitset*.fypp files to stdlib_bitset*.f90 files. [ticket: X]
Renamed files stdlib_bitset*.f90 to fypp preprocessor stdlib_bitset*.fypp files [ticket: X]
Changed stdlib_bitsets.fypp, stdlib_bitset_64.fypp, and stdlib_bitset_large.fypp to generate the assignment procedures of logical arrays to and from bitsets. [ticket: X]
Removed stdlib_bitsets.f90, stdlib_bitset_64.f90, and stdlib_bitset_large.f90 as they are now generated by the preprocessor. [ticket: X]
Defined an error_handler subroutine in stdlib_bitsets.fypp and used it to handle errors in stdlib_bitset_64.fypp and stdlib_bitset_large.fypp. Also was more consistent in documenting status argument results. Added char_string_too_large_error to status results. [ticket: X]
Was more consistent in using bulleted lists in documenting status error codes. Added char_string_too_large_error to the error codes. [ticket: X]
Working with fypp made it easier to add unwanted trailing blanks. I removed them. [ticket: X]
Introduced the parameters max_digits and overflow_bits to be used in checking for overflows on reads and writes. The parameters need to be changed if bits_kind is changed, and preferred parameters for bits_kind==int64 are defined, but commented out. [ticket: X]
Replaced go to 100 with exit in both stdlib_bitsets_64.fypp and stdlib_bitsets_large.fypp. [ticket: X]
@@ -0,0 +1,744 @@ | |||
program test_stdlib_bitset_64 | |||
use, intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use, intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 | |
use stdlib_kinds, only : int8, int16, int32, int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some additional comments on the tests. All options seem to be covered by the tests. I added some suggestions.
On overall I am pleased with this PR. Thank you @wclodius2!
It means I wrote the code when I was tired and wanted someone else to check my reasoning. It is parsing a decimal representation of the size in bits, and I want to be certain that the size does not exceed what can be represented by an integer of `bits_kind`. That could happen for example if parsing a file with `bits_kind==int32` and the file was written with `bits_kind==int64`. We want to be sure that the representation for `bits_kind==int32` does not exceed `2**31-1`. My reasoning is that it will exceed that value if:
1. it has ten digits and is about to read another digit increasing its value by a factor of ten
2. It has nine digits and has a value greater than `2**31/10`
3. It had a value of `2**31/10` and reading the next digit causes an integer overflow of nine or less resulting in a negative value.
… On Oct 20, 2020, at 11:46 AM, Jeremie Vandenplas ***@***.***> wrote:
@jvdp1 commented on this pull request.
In src/stdlib_bitsets_large.fypp <#239 (comment)>:
> + end do find_start
+
+ if ( pos > len(string) - 8 ) go to 999
+
+ if ( string(pos:pos) /= 's' .AND. string(pos:pos) /= 'S' ) go to 999
+
+ pos = pos + 1
+ bits = 0
+ digits = 0
+
+ do
+ select case( iachar( string(pos:pos) ) )
+ case(ia0:ia9)
+ digits = digits + 1
+ if ( digits == max_digits .AND. bits > overflow_bits ) go to 996
+!! May not be quite right
⬇️ Suggested change
-!! May not be quite right
+!! May not be quite right
What does this comment mean? What could be not quite right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#239 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APTQDOUBL3KX6BCX26LADBTSLXEG5ANCNFSM4R6QFU5A>.
|
Replaced the use of iso_fortran_env with stdlib_kinds. [ticket: X]
Changed handling of potential integer overflows on reads for bits_kind==int64, changing max_digits from 20 to 19. Removed comment that my treatment may not be quite right. Also fixed a typo in an error message. [ticket: X]
I have now resolved my qualms about my handling of potential integer overflows on reads. I have changed |
Jeremie suggested numerous changes. I implemented most of them. [ticket: X]
@jvdp1 thanks for the thorough review. |
At the suggestion of Jeremie I replaced a number of go tos. [ticket: X]
Kreplaced go tos at the suggestion of Jeremie. [ticket: X]
Documented the use of the "named" forms, .EQ., .NE., .GT., .GE., .LT., .LE., as alternatives to the symbolic forms, ==, /=, >, >=, <, <= of the comparison operations. [ticket: X]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed and made edits to the spec document. I have also built the code run the tests (successfully). For as far as I understand bitsets, I think the API is good.
I did not review the code. Due to the combination of limited time, large size of this PR, and my unfamiliarity with bitsets, I don't think I can do proper code review without putting in substantial effort. But I trust @wclodius2 and @jvdp1 that they did great work.
I recommend this PR to be merged a week from now.
A bit set for each index `bit` in the range `0…bits-1` has a value of 0 or 1. A value of 1 for index `bit` can be considered as including the `bit` value in the subset, i.e., the value `1110` can be considered as defining the subset (1, 2, 3). This was how Wirth defined sets in Pascal.
… On Nov 13, 2020, at 11:42 AM, Milan Curcic ***@***.***> wrote:
@milancurcic commented on this pull request.
In doc/specs/stdlib_bitsets.md <#239 (comment)>:
> +equivalently be considered as a sequence of logical values or as a
+subset of the integers 0 ... `bits-1`. The bits are indexed from 0 to
or as a subset of the integers 0 ... bits-1.
This confuses me. The equivalent integer values are 0 and 1, not 0 through bits-1, correct?
Do you mean to say something like this?
"It can equivalently be considered as a sequence of logical values or as a sequence of integers 0 and 1 with indices in the range 0... bits-1?"
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#239 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APTQDOTR4LOOIPRJ6D2QW63SPV42PANCNFSM4R6QFU5A>.
|
Okay, thanks, I understand now. All good. |
Your example "i.e., the value "It can equivalently be considered as a sequence of logical values or as a subset of the integers 0 ... |
Sounds good to me. |
I will go ahead and merge this considering there aren't any objections. Thank you @wclodius2 and all the reviewers. |
Branch to implement bitset data types. Committed the following new source files:
src/stdlib_bitsets.f90
src/stdlib_bitset_64.f90
src/stdlib_bitset_large.f90
Added the following new test files:
src/tests/bitsets/CMakeLists.txt
src/tests/bitsets/Makefile.manual
src/tests/bitsets/test_stdlib_bitset_64.f90
src/tests/bitsets/test_stdlib_bitset_large.f90
Added the following new documentation file:
doc/specs/stdlib_bitssets.md
Modified the following compilation files:
src/CMakeLists.txt
src/Makefile.manual
src/tests/CMakeLists.txt
src/tests/Makefile.manual