-
Notifications
You must be signed in to change notification settings - Fork 225
add is_sorted tests and optimize sorting suite #1167
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
Draft
srinjoy933
wants to merge
2
commits into
fortran-lang:master
Choose a base branch
from
srinjoy933:is_sort
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+404
−56
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,10 +24,9 @@ module's `string_type` type. | |||||||||
|
|
||||||||||
| ## Overview of the module | ||||||||||
|
|
||||||||||
| The module `stdlib_sorting` defines several public entities, two | ||||||||||
| default integer parameters, `int_index` and `int_index_low`, and four overloaded | ||||||||||
| subroutines: `ORD_SORT`, `SORT`, `RADIX_SORT` and `SORT_INDEX`. The | ||||||||||
| overloaded subroutines also each have several specific names for | ||||||||||
| default integer parameters, `int_index` and `int_index_low`, and five overloaded | ||||||||||
| procedures: `ORD_SORT`, `SORT`, `RADIX_SORT`, `SORT_INDEX`, and `IS_SORTED`. The | ||||||||||
| overloaded procedures also each have several specific names for | ||||||||||
| versions corresponding to different types of array arguments. | ||||||||||
|
|
||||||||||
| ### The parameters `int_index` and `int_index_low` | ||||||||||
|
|
@@ -57,6 +56,7 @@ data: | |||||||||
| that are effectively unordered before the sort; | ||||||||||
| * `RADIX_SORT` is intended to sort fixed width intrinsic data | ||||||||||
| types (integers and reals). | ||||||||||
| * `IS_SORTED` is a utility function to check if an array is already sorted, returning a logical scalar. | ||||||||||
|
|
||||||||||
| #### Licensing | ||||||||||
|
|
||||||||||
|
|
@@ -624,6 +624,44 @@ Sorting an array of a derived type based on the data in one component | |||||||||
| ! Sort a_data based on the sorting of that component | ||||||||||
| a_data(:) = a_data( index(1:size(a_data)) ) | ||||||||||
| end subroutine sort_a_data | ||||||||||
| #### `is_sorted` - checks if an input array is sorted | ||||||||||
|
Member
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
|
||||||||||
|
|
||||||||||
| ##### Status | ||||||||||
|
|
||||||||||
| Experimental | ||||||||||
|
|
||||||||||
| ##### Description | ||||||||||
|
|
||||||||||
| Returns a logical scalar indicating whether the input `array` is sorted in order of increasing, or decreasing, value. | ||||||||||
|
|
||||||||||
| ##### Syntax | ||||||||||
|
|
||||||||||
| `result = ` [[stdlib_sorting(module):is_sorted(interface)]] `( array[, reverse] )` | ||||||||||
|
|
||||||||||
| ##### Class | ||||||||||
|
|
||||||||||
| Pure generic function. | ||||||||||
|
|
||||||||||
| ##### Arguments | ||||||||||
|
|
||||||||||
| `array` : shall be a rank one array of any of the types: | ||||||||||
| `integer(int8)`, `integer(int16)`, `integer(int32)`, `integer(int64)`, | ||||||||||
| `real(sp)`, `real(dp)`, `real(qp)`, `character(*)`, `type(string_type)`, | ||||||||||
| `type(bitset_64)`, or `type(bitset_large)`. | ||||||||||
| It is an `intent(in)` argument. | ||||||||||
|
|
||||||||||
| `reverse` (optional): shall be a scalar of type default logical. It | ||||||||||
| is an `intent(in)` argument. If present with a value of `.true.`, the function | ||||||||||
| will check if `array` is sorted in order of non-increasing values. Otherwise, it will check if `array` is sorted in order of non-decreasing values. | ||||||||||
|
|
||||||||||
| ##### Return Value | ||||||||||
|
|
||||||||||
| The result is a scalar of type default logical. It returns `.true.` if the array is sorted according to the requested order, and `.false.` otherwise. Returns `.true.` for arrays of size 0 or 1. If `array` is of any type `REAL` and contains a `NaN`, the result is `.false.`. | ||||||||||
|
|
||||||||||
| ##### Example | ||||||||||
|
|
||||||||||
| ```fortran | ||||||||||
| {!example/sorting/example_is_sorted.f90!} | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
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
Oops, something went wrong.
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.
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.