ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_arrayComplement::getComplementRange Interface Reference

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. More...

Detailed Description

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.
  1. 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).
  2. 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.
  1. If .false., the input setA is assumed to possibly contain duplicate elements.
  2. 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

complement(:) = getComplementRange(setA(:), start, stop, step)
complement(:) = getComplementRange(setA(:), start, stop, step, sorted, unique)
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

1program example
2
3 use pm_kind, only: SK, LK
4 use pm_kind, only: IK ! all processor types and kinds are supported.
5 use pm_io, only: display_type
7 use pm_arraySort, only: setSorted
9
10 implicit none
11
12 integer(IK) , allocatable :: SetA_IK(:)
13 integer(IK) :: start, stop, step
14
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 call disp%skip()
19 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%show("! Find the complement of integer vector A in B: B \ A.")
21 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
22 call disp%skip()
23
24 SetA_IK = [integer(IK) :: 4, 5, 4, 1, 2, 1, 5]
25
26 call disp%skip()
27 call disp%show("SetA_IK")
28 call disp%show( SetA_IK )
29
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)")
33 call disp%show( getComplementRange(SetA_IK, start, stop, step) )
34
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)")
38 call disp%show( getComplementRange(SetA_IK, start, stop, step) )
39
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)")
43 call disp%show( getComplementRange(SetA_IK, start, stop, step) )
44
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)")
48 call disp%show( getComplementRange(SetA_IK, start, stop, step) )
49 call disp%skip()
50
51 call disp%skip()
52 call disp%show("call setSorted(SetA_IK)")
53 call setSorted(SetA_IK)
54 call disp%show("SetA_IK")
55 call disp%show( SetA_IK )
56
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)")
60 call disp%show( getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK) )
61
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)")
65 call disp%show( getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK) )
66 call disp%skip()
67
68 call disp%skip()
69 call disp%show("SetA_IK = getUnique(SetA_IK)")
70 SetA_IK = getUnique(SetA_IK)
71 call disp%show("SetA_IK")
72 call disp%show( SetA_IK )
73
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)")
77 call disp%show( getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK) )
78
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)")
82 call disp%show( getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK) )
83
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)")
87 call disp%show( getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK) )
88
89 call disp%skip()
90
91 SetA_IK = [integer(IK) :: 5, 4, 3, 1, 1]
92
93 call disp%skip()
94 call disp%show("call setSorted(SetA_IK)")
95 call setSorted(SetA_IK)
96 call disp%show("SetA_IK")
97 call disp%show( SetA_IK )
98
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)")
102 call disp%show( getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK) )
103 call disp%skip()
104
105end program example
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.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
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...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3! Find the complement of integer vector A in B: B \ A.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7SetA_IK
8+4, +5, +4, +1, +2, +1, +5
9start = 0; stop = 3; step = 1
10getComplementRange(SetA_IK, start, stop, step)
11+0, +3
12start = 0; stop = 6; step = 2
13getComplementRange(SetA_IK, start, stop, step)
14+0, +6
15start = 0; stop = 6; step = 1
16getComplementRange(SetA_IK, start, stop, step)
17+0, +3, +6
18start = 10; stop = 6; step = -1
19getComplementRange(SetA_IK, start, stop, step)
20+10, +9, +8, +7, +6
21
22
23call setSorted(SetA_IK)
24SetA_IK
25+1, +1, +2, +4, +4, +5, +5
26start = 0; stop = 3; step = 1
27getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK)
28+0, +3
29start = 0; stop = 6; step = 2
30getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK)
31+0, +6
32
33
34SetA_IK = getUnique(SetA_IK)
35SetA_IK
36+1, +2, +4, +5
37start = 0; stop = 3; step = 1
38getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK)
39+0, +3
40start = 0; stop = 6; step = 2
41getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK)
42+0, +6
43start = 10; stop = 15; step = 1
44getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .true._LK)
45+10, +11, +12, +13, +14, +15
46
47
48call setSorted(SetA_IK)
49SetA_IK
50+1, +1, +3, +4, +5
51start = 6; stop = -3; step = -2
52getComplementRange(SetA_IK, start, stop, step, sorted = .true._LK, unique = .false._LK)
53+6, +2, +0
54
55
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.

  1. 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.
  2. 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.

Author:
Fatemeh Bagheri, Wednesday 1:35 PM, August 11, 2021, Dallas, TX

Definition at line 1942 of file pm_arrayComplement.F90.


The documentation for this interface was generated from the following file: