-
Notifications
You must be signed in to change notification settings - Fork 181
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
Support sorting arrays of bitsets #723
Conversation
- BITSET_KINDS_TYPES is not needed to support sorting bitsets.
- tests for `ord_sort` procedure - tests for `sort` procedure - tests for `sort_index` procedure - verification procedures for ascending and reverse sorting
to reduce the time for testing
to support assignment of the same variable, i.e., `set=set`
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. On overall LGTM. Here are a few comments.
src/stdlib_bitsets.fypp
Outdated
@@ -1170,8 +1170,8 @@ module stdlib_bitsets | |||
!! Version: experimental | |||
!! | |||
!! Used to define assignment for `bitset_large`. | |||
type(bitset_large), intent(out) :: set1 | |||
type(bitset_large), intent(in) :: set2 | |||
type(bitset_large), intent(inout) :: set1 |
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.
Why is this needed?
And if it is needed, I guess the corresponding interfaces should be also modified for bitset_64
.
It might be wise to open another PR with these changes only related to stdlib_bitset
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.
Should the corresponding specs be modified too?
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.
This change and the change you mentioned below have been done to fix unexpected behavior when assigning the bitset_large
type.
Without this fix, the tests for sorting bitset_large
in the following environment will fail:
- msys2-build (MSYS, x86_64) in ci_windows.yml
- msys2-build (MINGW32, i686) in ci_windows.yml
- msys2-build (MINGW32, i686) in ci_windows.yml
- Build (macos-latest, 11, cmake) in CI.yml
- Build (macos-latest, 12, cmake) in CI.yml
As you said, opening a new issue for further discussion is better.
I share the reason for those modification.
The component blocks
of set1
with the intent(out)
attribute is not allocated at the beginning of the assignment procedure. Therefore, when size( set2 % blocks, kind=bits_kind )
is executed, an error occurs that blocks
have not been allocated. To avoid this error, I modified the intent
attribute from intent(out)
to intent(inout)
.
Although I could not find a direct description of this situation in the Fortran Standard, the following statements are relevant:
The INTENT attribute for an allocatable dummy argument applies to both the allocation status and the
definition status. An actual argument that corresponds to an INTENT (OUT) allocatable dummy argument
is deallocated on procedure invocation (9.7.3.2).
When a variable of derived type is deallocated, any allocated allocatable subobject is deallocated. If an error condition occurs during deallocation, it is processor dependent whether an allocated allocatable subobject is deallocated.
The INTENT (OUT) attribute for a nonpointer dummy argument specifies that the dummy argument becomes undefined on invocation of the procedure, except for any subcomponents that are default-initialized (7.5.4.6).
An error still occurred in the assignment procedure after the modification.
allocate( set1 % blocks( size( set2 % blocks, kind=bits_kind ) ) )
gives the error "set1%blocks
is already allocated" when the same variable of the bitset_large
type was specified on both sides of the assignment operator. This sometimes happens when the array indices for the bitset array to be sorted are the same.
Since set1
and set2
are the same when the same array element is now specified on both sides of the assignment operator, it is natural that this error occurs.
Therefore, the automatic allocation functionality is used instead of explicit allocation.
Similar modifications are not required for type(bitset_64)
. This is because type(bitset_64)
uses an integer corresponding integer(int64)
for storing bitset and thus uses a built-in assignment operation.
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.
Ok. Thank you for the explanation. A new PR with a test replicating this issue would be useful.
Otherwise, this PR looks good to me.
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 followed your comment and opened another issue #726 with replication instructions because discussing it in more detail would be better.
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Nice that it solves the issue. |
I understand the review policy, but I have already merged the changes made in #727. How should I handle those? |
Sorry for the confusion. #727 should be merged first, with the remove |
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.
To support sorting arrays of bitsets,
type(bitset_64)
andtype(bitset_large)
are added as arguments of procedures in thestdlib_sorting
.The tasks done are summarized as follows:
ALT_NAME
in thestdlib_sorting
modules.stdlib_sorting
module.intent
fromout
toinout
in the procedure for overloading the assignment operator for bitset types.array(1)=array(1)
is performed.closes #720