Generate and return the complement of the input set setA
with respect to an array of elements of the sorted set comprised of a range of integer values constructed by the triple start, stop, step
.
This procedures under this generic interface are particularly useful for a fast construction of the complement to a set of array indices.
The additional performance originates from avoiding the unnecessary creation of setB = getRange(start, stop, step)
by the user as the input argument to getComplement.
- Parameters
-
[in] | setA | : The input contiguous vector of type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) whose complement in the range specified by the triple (start, stop, step) will be returned as complement(:) . |
[in] | start | : The input scalar of the same type, kind, and rank as setA representing the start of the range. |
[in] | stop | : The input scalar of the same type, kind, and rank as setA representing the stop of the range. |
[in] | step | : The input scalar of the same type, kind, and rank as setA representing the jumping step size in the range. |
[in] | sorted | : The input scalar logical of default kind LK.
-
If
.false. , the input setA is assumed to be dissimilarly sorted or not sorted at all with respect to the range specified by (start, stop, step) .
-
If
.true. , the input setA is assumed to be sorted similar to the range specified by (start, stop, step) (e.g., both ascending or both descending order).
If the input sets are similarly sorted, then specifying sorted = .true._LK can lead to significantly better runtime performance.
(optional, default = .false._LK . It must be present if and only if unique is also present.) |
[in] | unique | : The input scalar logical of default kind LK.
-
If
.false. , the input setA is assumed to possibly contain duplicate elements.
-
If
.true. , all elements in the input setA are assumed to be unique.
If the elements of setA are unique, then specifying unique = .true._LK can lead to significantly better runtime performance.
The specified value for unique becomes relevant only if sorted = .true. . Its value is ignored when sorted = .false.
(optional, default = .false._LK . It must be present if and only if sorted is also present.) |
- Returns
complement
: The output allocatable
object of the same type, kind, and rank as setA
containing the complement of setA
in the range specified by the triple (start, stop, step)
(i.e., the values in the range that are not in setA
).
Possible calling interfaces ⛓
Generate and return the complement of the input set setA with respect to an array of elements of the ...
This module contains procedures and generic interfaces for computing the absolute or relative complem...
- Warning
- Beware of the possibility of arithmetic overflow and underflow when the sum or the difference of
start
and stop
falls out of the allowed representable range.
-
The input
step
must be non-zero.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
-
The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
- Note
- The performane of the procedures under this generic interface can dramatically improve if the input sets contain unique values (
unique = .true._LK
) and both sets are similarly-sorted (sorted = .true._LK
). The unique elements of an arbitrary set can be obtained via the procedures of pm_arrayUnique.
- See also
- getComplementRange
Example usage ⛓
12 integer(IK) ,
allocatable :: SetA_IK(:)
13 integer(IK) :: start, stop, step
15 type(display_type) :: disp
19 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%show(
"! Find the complement of integer vector A in B: B \ A.")
21 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 SetA_IK
= [
integer(IK) ::
4,
5,
4,
1,
2,
1,
5]
30 call disp%show(
"start = 0; stop = 3; step = 1")
31 start
= 0;
stop = 3; step
= 1
32 call disp%show(
"getComplementRange(SetA_IK, start, stop, step)")
35 call disp%show(
"start = 0; stop = 6; step = 2")
36 start
= 0;
stop = 6; step
= 2
37 call disp%show(
"getComplementRange(SetA_IK, start, stop, step)")
40 call disp%show(
"start = 0; stop = 6; step = 1")
41 start
= 0;
stop = 6; step
= 1
42 call disp%show(
"getComplementRange(SetA_IK, start, stop, step)")
45 call disp%show(
"start = 10; stop = 6; step = -1")
46 start
= 10;
stop = 6; step
= -1
47 call disp%show(
"getComplementRange(SetA_IK, start, stop, step)")
52 call disp%show(
"call setSorted(SetA_IK)")
57 call disp%show(
"start = 0; stop = 3; step = 1")
58 start
= 0;
stop = 3; step
= 1
59 call disp%show(
"getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK)")
62 call disp%show(
"start = 0; stop = 6; step = 2")
63 start
= 0;
stop = 6; step
= 2
64 call disp%show(
"getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK)")
69 call disp%show(
"SetA_IK = getUnique(SetA_IK)")
74 call disp%show(
"start = 0; stop = 3; step = 1")
75 start
= 0;
stop = 3; step
= 1
76 call disp%show(
"getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK)")
79 call disp%show(
"start = 0; stop = 6; step = 2")
80 start
= 0;
stop = 6; step
= 2
81 call disp%show(
"getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK)")
84 call disp%show(
"start = 10; stop = 15; step = 1")
85 start
= 10;
stop = 15; step
= 1
86 call disp%show(
"getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK)")
91 SetA_IK
= [
integer(IK) ::
5,
4,
3,
1,
1]
94 call disp%show(
"call setSorted(SetA_IK)")
99 call disp%show(
"start = 6; stop = -3; step = -2")
100 start
= 6;
stop = -1; step
= -2
101 call disp%show(
"getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK)")
Sort the input scalar string or contiguous vector in ascending order, or return the sorted indices of...
Generate and return a vector of unique values in the input array.
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
This module contains procedures and generic interfaces for various sorting tasks.
This module contains procedures and generic interfaces for finding unique values of an input array of...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
8+4,
+5,
+4,
+1,
+2,
+1,
+5
9start
= 0;
stop = 3; step
= 1
12start
= 0;
stop = 6; step
= 2
15start
= 0;
stop = 6; step
= 1
18start
= 10;
stop = 6; step
= -1
25+1,
+1,
+2,
+4,
+4,
+5,
+5
26start
= 0;
stop = 3; step
= 1
29start
= 0;
stop = 6; step
= 2
37start
= 0;
stop = 3; step
= 1
40start
= 0;
stop = 6; step
= 2
43start
= 10;
stop = 15; step
= 1
45+10,
+11,
+12,
+13,
+14,
+15
51start
= 6;
stop = -3; step
= -2
- Test:
- test_pm_arrayComplement
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
-
If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
-
If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
- Copyright
- Computational Data Science Lab
- Author:
- Fatemeh Bagheri, Wednesday 1:35 PM, August 11, 2021, Dallas, TX
Definition at line 1942 of file pm_arrayComplement.F90.