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

Generate and return an array of elements of setB that are not in setA. More...

Detailed Description

Generate and return an array of elements of setB that are not in setA.

Parameters
[in]setA: The input contiguous vector of either,
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), or
  • type logical of kind any supported by the processor (e.g., LK), or
  • type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  • type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128), or
or,
  • scalar character of arbitrary length of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
whose complement in setB will be returned as the output complement.
[in]setB: The input object of the same type, kind, and rank as setA representing the set with respect to which the complement of setA is computed.
[in]sorted: The input scalar logical of default kind LK.
  1. If .false., the input sets setA and setB are assumed to be dissimilarly sorted or not sorted at all.
  2. If .true., the input sets setA and setB are assumed to be similarly sorted (e.g., both ascending or both descending order according to an arbitrary criterion).
If the input sets are similarly sorted, then specifying sorted = .true._LK can lead to significantly better runtime performance.
(optional, default = .false._LK)
[in]unique: The input scalar logical of default kind LK.
  1. If .false., each of the input sets setA and setB are assumed to possibly contain duplicate elements individually.
  2. If .true., all elements within each of the input sets setA and setB are assumed to be unique.
If the elements of each of the input sets 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).
iseq: The external user-specified function that takes two input scalar arguments of the same type and kind as the input setA.
The first input argument is an element of setA to be compared with the second argument that is an element from setB.
If setA and setB are scalars of type character, the len type-parameter of both input arguments to iseq is 1.
It returns a scalar logical of default kind LK that is .true. if the two input arguments are equivalent (e.g., equal) according to the user-defined criterion, otherwise, it is .false..
The following illustrates the generic interface of iseq,
function iseq(elementA, elementB) result(equivalent)
use pm_kind, only: LK
TYPE(KIND) , intent(in) :: elementA, elementB
logical(LK) :: equivalent
end function
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
where TYPE(KIND) represents the type and kind of the input argument setA, which can be one of the following,
use pm_kind, only: SK, IK, CK, RK
character(*, SK), intent(in) :: elementA, elementB ! when `array` is a string vector.
character(1, SK), intent(in) :: elementA, elementB ! when `array` is a string scalar.
integer(IK) , intent(in) :: elementA, elementB
complex(CK) , intent(in) :: elementA, elementB
real(RK) , intent(in) :: elementA, elementB
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
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
where the kinds SK, IK, CK, RK, can refer to any kind type parameter that is supported by the processor.
This user-defined equivalence check is extremely useful where a user-defined equivalence test other than exact equality or identity is needed, for example, when the set elements should match only within a given threshold or, when the case-sensitivity in character comparisons do not matter.
In such cases, the user can define a custom equivalence criterion within the user-defined external function iseq to achieve the goal.
(optional, the default equivalence operator is ==)
Returns
complement : The output allocatable object of the same type, kind, and rank as setA containing the complement of setA in setB (i.e., the elements of setB that are not in setA).


Possible calling interfaces

complement = getComplement(setA, setB) ! scalar assumed-length string arguments and output.
complement(:) = getComplement(setA(:), setB(:))
complement(:) = getComplement(setA(:), setB(:), iseq)
complement(:) = getComplement(setA(:), setB(:), sorted, unique)
complement(:) = getComplement(setA(:), setB(:), sorted, unique, iseq)
Generate and return an array of elements of setB that are not in setA.
This module contains procedures and generic interfaces for computing the absolute or relative complem...
Warning
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 performance 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: LK
4 use pm_kind, only: SK, IK, LK, CK => CKS, RK => RKS ! all processor types and kinds are supported.
7 use pm_io, only: display_type
8 use pm_arraySort, only: setSorted
9
10 implicit none
11
12 character(:, SK), allocatable :: StrA_SK , StrB_SK
13 character(2, SK), allocatable :: SetA_SK(:) , SetB_SK(:)
14 integer(IK) , allocatable :: SetA_IK(:) , SetB_IK(:)
15 complex(CK) , allocatable :: SetA_CK(:) , SetB_CK(:)
16 real(RK) , allocatable :: SetA_RK(:) , SetB_RK(:)
17
18 type(display_type) :: disp
19
20 disp = display_type(file = "main.out.F90")
21
22 SetA_SK = ["AA", "BB", "CC", "AA", "FF", "CC", "DD"]
23 SetB_SK = ["aa", "CC", "CC", "CC", "DD", "EE", "EE"]
24
25 call disp%skip()
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show("! Find the complement of string scalar A in B: B \ A.")
28 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%skip()
30
31 StrA_SK = "AADBCCFEEZ"
32 StrB_SK = "EADGBBCGCE"
33
34 call disp%skip()
35 call disp%show("StrA_SK")
36 call disp%show( StrA_SK, deliml = SK_"""" )
37 call disp%show("StrB_SK")
38 call disp%show( StrB_SK, deliml = SK_"""" )
39 call disp%show("getComplement(StrA_SK, StrB_SK)")
40 call disp%show( getComplement(StrA_SK, StrB_SK), deliml = SK_"""" )
41 call disp%skip()
42
43 call disp%skip()
44 call disp%show("call setSorted(StrA_SK)")
45 call setSorted(StrA_SK)
46 call disp%show("StrA_SK")
47 call disp%show( StrA_SK, deliml = SK_"""" )
48 call disp%show("call setSorted(StrB_SK)")
49 call setSorted(StrB_SK)
50 call disp%show("StrB_SK")
51 call disp%show( StrB_SK, deliml = SK_"""" )
52 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK)")
53 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK), deliml = SK_"""" )
54 call disp%skip()
55
56 call disp%skip()
57 call disp%show("StrA_SK = getUnique(StrA_SK)")
58 StrA_SK = getUnique(StrA_SK)
59 call disp%show("StrA_SK")
60 call disp%show( StrA_SK, deliml = SK_"""" )
61 call disp%show("StrB_SK = getUnique(StrB_SK)")
62 StrB_SK = getUnique(StrB_SK)
63 call disp%show("StrB_SK")
64 call disp%show( StrB_SK, deliml = SK_"""" )
65 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK)")
66 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK), deliml = SK_"""" )
67 call disp%skip()
68
69 StrA_SK = "AADBCCFEEZ"
70 StrB_SK = "AAAAAAAAAA"
71
72 call disp%skip()
73 call disp%show("StrA_SK")
74 call disp%show( StrA_SK, deliml = SK_"""" )
75 call disp%show("StrB_SK")
76 call disp%show( StrB_SK, deliml = SK_"""" )
77 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK) ! The result is wrong because both sets must contain unique elements when `unique = .true.`.")
78 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK), deliml = SK_"""" )
79 call disp%skip()
80
81 StrA_SK = "AADBCCFEEZ"
82 StrB_SK = "BAAAAAAAAA"
83
84 call disp%skip()
85 call disp%show("StrA_SK")
86 call disp%show( StrA_SK, deliml = SK_"""" )
87 call disp%show("StrB_SK")
88 call disp%show( StrB_SK, deliml = SK_"""" )
89 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK) ! The result is wrong because both sets must be similarly sorted when `sorted = .true.`.")
90 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK), deliml = SK_"""" )
91 call disp%skip()
92
93 StrA_SK = "AABCCDEEFZ"
94 StrB_SK = "ZFEEDCCBAA"
95
96 call disp%skip()
97 call disp%show("StrA_SK")
98 call disp%show( StrA_SK, deliml = SK_"""" )
99 call disp%show("StrB_SK")
100 call disp%show( StrB_SK, deliml = SK_"""" )
101 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK) ! The result is wrong because both sets must be similarly sorted when `sorted = .true.`.")
102 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK), deliml = SK_"""" )
103 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .false._LK, unique = .false._LK)")
104 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .false._LK, unique = .false._LK), deliml = SK_"""" )
105 call disp%skip()
106
107 call disp%skip()
108 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
109 call disp%show("! Find the complement of string vector A in B: B \ A.")
110 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
111 call disp%skip()
112
113 call disp%skip()
114 call disp%show("SetA_SK")
115 call disp%show( SetA_SK, deliml = SK_"""" )
116 call disp%show("SetB_SK")
117 call disp%show( SetB_SK, deliml = SK_"""" )
118 call disp%show("getComplement(SetA_SK, SetB_SK)")
119 call disp%show( getComplement(SetA_SK, SetB_SK), deliml = SK_"""" )
120 call disp%skip()
121
122 call disp%skip()
123 call disp%show("call setSorted(SetA_SK)")
124 call setSorted(SetA_SK)
125 call disp%show("SetA_SK")
126 call disp%show( SetA_SK, deliml = SK_"""" )
127 call disp%show("call setSorted(SetB_SK)")
128 call setSorted(SetB_SK)
129 call disp%show("SetB_SK")
130 call disp%show( SetB_SK, deliml = SK_"""" )
131 call disp%show("getComplement(SetA_SK, SetB_SK, sorted = .true._LK, unique = .false._LK)")
132 call disp%show( getComplement(SetA_SK, SetB_SK, sorted = .true._LK, unique = .false._LK), deliml = SK_"""" )
133 call disp%skip()
134
135 call disp%skip()
136 call disp%show("SetA_SK = getUnique(SetA_SK)")
137 SetA_SK = getUnique(SetA_SK)
138 call disp%show("SetA_SK")
139 call disp%show( SetA_SK, deliml = SK_"""" )
140 call disp%show("SetB_SK = getUnique(SetB_SK)")
141 SetB_SK = getUnique(SetB_SK)
142 call disp%show("SetB_SK")
143 call disp%show( SetB_SK, deliml = SK_"""" )
144 call disp%show("getComplement(SetA_SK, SetB_SK, sorted = .true._LK, unique = .true._LK)")
145 call disp%show( getComplement(SetA_SK, SetB_SK, sorted = .true._LK, unique = .true._LK), deliml = SK_"""" )
146 call disp%skip()
147
148 call disp%skip()
149 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
150 call disp%show("! Find the complement of integer vector A in B: B \ A.")
151 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
152 call disp%skip()
153
154 SetA_IK = [integer(IK) :: 4, 5, 4, 1, 2, 1, 5]
155 SetB_IK = [integer(IK) :: 6, 3, 4, 2, 1, 2, 6]
156
157 call disp%skip()
158 call disp%show("SetA_IK")
159 call disp%show( SetA_IK )
160 call disp%show("SetB_IK")
161 call disp%show( SetB_IK )
162 call disp%show("getComplement(SetA_IK, SetB_IK)")
163 call disp%show( getComplement(SetA_IK, SetB_IK) )
164 call disp%skip()
165
166 call disp%skip()
167 call disp%show("call setSorted(SetA_IK)")
168 call setSorted(SetA_IK)
169 call disp%show("SetA_IK")
170 call disp%show( SetA_IK )
171 call disp%show("call setSorted(SetB_IK)")
172 call setSorted(SetB_IK)
173 call disp%show("SetB_IK")
174 call disp%show( SetB_IK )
175 call disp%show("getComplement(SetA_IK, SetB_IK, sorted = .true._LK, unique = .false._LK)")
176 call disp%show( getComplement(SetA_IK, SetB_IK, sorted = .true._LK, unique = .false._LK) )
177 call disp%skip()
178
179 call disp%skip()
180 call disp%show("SetA_IK = getUnique(SetA_IK)")
181 SetA_IK = getUnique(SetA_IK)
182 call disp%show("SetA_IK")
183 call disp%show( SetA_IK )
184 call disp%show("SetB_IK = getUnique(SetB_IK)")
185 SetB_IK = getUnique(SetB_IK)
186 call disp%show("SetB_IK")
187 call disp%show( SetB_IK )
188 call disp%show("getComplement(SetA_IK, SetB_IK, sorted = .true._LK, unique = .true._LK)")
189 call disp%show( getComplement(SetA_IK, SetB_IK, sorted = .true._LK, unique = .true._LK) )
190 call disp%skip()
191
192 call disp%skip()
193 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
194 call disp%show("! Find the complement of complex vector A in B: B \ A.")
195 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
196 call disp%skip()
197
198 SetA_CK = [complex(CK) :: (4, -4), (5, -5), (4, -4), (1, -1), (2, -2), (8, -8), (1, -1), (5, -5)]
199 SetB_CK = [complex(CK) :: (6, -6), (3, -3), (4, -4), (2, -2), (1, -1), (7, -7), (2, -2), (6, -6)]
200
201 call disp%skip()
202 call disp%show("SetA_CK")
203 call disp%show( SetA_CK )
204 call disp%show("SetB_CK")
205 call disp%show( SetB_CK )
206 call disp%show("getComplement(SetA_CK, SetB_CK)")
207 call disp%show( getComplement(SetA_CK, SetB_CK) )
208 call disp%skip()
209
210 call disp%skip()
211 call disp%show("call setSorted(SetA_CK)")
212 call setSorted(SetA_CK)
213 call disp%show("SetA_CK")
214 call disp%show( SetA_CK )
215 call disp%show("call setSorted(SetB_CK)")
216 call setSorted(SetB_CK)
217 call disp%show("SetB_CK")
218 call disp%show( SetB_CK )
219 call disp%show("getComplement(SetA_CK, SetB_CK, sorted = .true._LK, unique = .false._LK)")
220 call disp%show( getComplement(SetA_CK, SetB_CK, sorted = .true._LK, unique = .false._LK) )
221 call disp%skip()
222
223 call disp%skip()
224 call disp%show("SetA_CK = getUnique(SetA_CK)")
225 SetA_CK = getUnique(SetA_CK)
226 call disp%show("SetA_CK")
227 call disp%show( SetA_CK )
228 call disp%show("SetB_CK = getUnique(SetB_CK)")
229 SetB_CK = getUnique(SetB_CK)
230 call disp%show("SetB_CK")
231 call disp%show( SetB_CK )
232 call disp%show("getComplement(SetA_CK, SetB_CK, sorted = .true._LK, unique = .true._LK)")
233 call disp%show( getComplement(SetA_CK, SetB_CK, sorted = .true._LK, unique = .true._LK) )
234 call disp%skip()
235
236 call disp%skip()
237 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
238 call disp%show("! Find the complement of real vector A in B: B \ A.")
239 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
240 call disp%skip()
241
242 SetA_RK = [real(RK) :: 4, 5, 4, 1, 2, 8, 1, 5]
243 SetB_RK = [real(RK) :: 6, 3, 4, 2, 1, 7, 2, 6]
244
245 call disp%skip()
246 call disp%show("SetA_RK")
247 call disp%show( SetA_RK )
248 call disp%show("SetB_RK")
249 call disp%show( SetB_RK )
250 call disp%show("getComplement(SetA_RK, SetB_RK)")
251 call disp%show( getComplement(SetA_RK, SetB_RK) )
252 call disp%skip()
253
254 call disp%skip()
255 call disp%show("call setSorted(SetA_RK)")
256 call setSorted(SetA_RK)
257 call disp%show("SetA_RK")
258 call disp%show( SetA_RK )
259 call disp%show("call setSorted(SetB_RK)")
260 call setSorted(SetB_RK)
261 call disp%show("SetB_RK")
262 call disp%show( SetB_RK )
263 call disp%show("getComplement(SetA_RK, SetB_RK, sorted = .true._LK, unique = .false._LK)")
264 call disp%show( getComplement(SetA_RK, SetB_RK, sorted = .true._LK, unique = .false._LK) )
265 call disp%skip()
266
267 call disp%skip()
268 call disp%show("SetA_RK = getUnique(SetA_RK)")
269 SetA_RK = getUnique(SetA_RK)
270 call disp%show("SetA_RK")
271 call disp%show( SetA_RK )
272 call disp%show("SetB_RK = getUnique(SetB_RK)")
273 SetB_RK = getUnique(SetB_RK)
274 call disp%show("SetB_RK")
275 call disp%show( SetB_RK )
276 call disp%show("getComplement(SetA_RK, SetB_RK, sorted = .true._LK, unique = .true._LK)")
277 call disp%show( getComplement(SetA_RK, SetB_RK, sorted = .true._LK, unique = .true._LK) )
278 call disp%skip()
279
280 call disp%skip()
281 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
282 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
283 call disp%show("! Find the complement using a custom equivalence check.")
284 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
285 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
286 call disp%skip()
287
288 StrA_SK = "AADBCCFEEZ"
289 StrB_SK = "eadgbbcgce"
290
291 call disp%skip()
292 call disp%show("StrA_SK")
293 call disp%show( StrA_SK, deliml = SK_"""" )
294 call disp%show("StrB_SK")
295 call disp%show( StrB_SK, deliml = SK_"""" )
296 call disp%show("getComplement(StrA_SK, StrB_SK)")
297 call disp%show( getComplement(StrA_SK, StrB_SK), deliml = SK_"""" )
298 call disp%show("getComplement(StrA_SK, StrB_SK, iseq = iseq_SK)")
299 call disp%show( getComplement(StrA_SK, StrB_SK, iseq = iseq_SK), deliml = SK_"""" )
300 call disp%skip()
301
302 call disp%skip()
303 call disp%show("call setSorted(StrA_SK)")
304 call setSorted(StrA_SK)
305 call disp%show("StrA_SK")
306 call disp%show( StrA_SK, deliml = SK_"""" )
307 call disp%show("call setSorted(StrB_SK)")
308 call setSorted(StrB_SK)
309 call disp%show("StrB_SK")
310 call disp%show( StrB_SK, deliml = SK_"""" )
311 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK)")
312 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK), deliml = SK_"""" )
313 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK, iseq = iseq_SK)")
314 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK, iseq = iseq_SK), deliml = SK_"""" )
315 call disp%skip()
316
317 call disp%skip()
318 call disp%show("StrA_SK = getUnique(StrA_SK)")
319 StrA_SK = getUnique(StrA_SK)
320 call disp%show("StrA_SK")
321 call disp%show( StrA_SK, deliml = SK_"""" )
322 call disp%show("StrB_SK = getUnique(StrB_SK)")
323 StrB_SK = getUnique(StrB_SK)
324 call disp%show("StrB_SK")
325 call disp%show( StrB_SK, deliml = SK_"""" )
326 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK)")
327 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK), deliml = SK_"""" )
328 call disp%show("getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK, iseq = iseq_SK)")
329 call disp%show( getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK, iseq = iseq_SK), deliml = SK_"""" )
330 call disp%skip()
331
332contains
333
334 pure function iseq_SK(element1, element2) result(iseq)
335 use pm_strASCII, only: getCharLower
336 character(1, SK) , intent(in) :: element1, element2
337 logical(LK) :: iseq
338 iseq = getCharLower(element1) == getCharLower(element2)
339 end function
340
341end 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
Generate and return the input character where the uppercase English alphabet is converted to lowercas...
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
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This module contains the uncommon and hardly representable ASCII characters as well as procedures for...
Definition: pm_strASCII.F90:61
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 string scalar A in B: B \ A.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7StrA_SK
8"AADBCCFEEZ"
9StrB_SK
10"EADGBBCGCE"
11getComplement(StrA_SK, StrB_SK)
12"GG"
13
14
15call setSorted(StrA_SK)
16StrA_SK
17"AABCCDEEFZ"
18call setSorted(StrB_SK)
19StrB_SK
20"ABBCCDEEGG"
21getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK)
22"GG"
23
24
25StrA_SK = getUnique(StrA_SK)
26StrA_SK
27"ABCDEFZ"
28StrB_SK = getUnique(StrB_SK)
29StrB_SK
30"ABCDEG"
31getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK)
32"G"
33
34
35StrA_SK
36"AADBCCFEEZ"
37StrB_SK
38"AAAAAAAAAA"
39getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK) ! The result is wrong because both sets must contain unique elements when `unique = .true.`.
40"AAAAAAAA"
41
42
43StrA_SK
44"AADBCCFEEZ"
45StrB_SK
46"BAAAAAAAAA"
47getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK) ! The result is wrong because both sets must be similarly sorted when `sorted = .true.`.
48"AAAAAAAAA"
49
50
51StrA_SK
52"AABCCDEEFZ"
53StrB_SK
54"ZFEEDCCBAA"
55getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK) ! The result is wrong because both sets must be similarly sorted when `sorted = .true.`.
56"FEEDCCBAA"
57getComplement(StrA_SK, StrB_SK, sorted = .false._LK, unique = .false._LK)
58""
59
60
61!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62! Find the complement of string vector A in B: B \ A.
63!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65
66SetA_SK
67"AA", "BB", "CC", "AA", "FF", "CC", "DD"
68SetB_SK
69"aa", "CC", "CC", "CC", "DD", "EE", "EE"
70getComplement(SetA_SK, SetB_SK)
71"aa", "EE", "EE"
72
73
74call setSorted(SetA_SK)
75SetA_SK
76"AA", "AA", "BB", "CC", "CC", "DD", "FF"
77call setSorted(SetB_SK)
78SetB_SK
79"CC", "CC", "CC", "DD", "EE", "EE", "aa"
80getComplement(SetA_SK, SetB_SK, sorted = .true._LK, unique = .false._LK)
81"EE", "EE", "aa"
82
83
84SetA_SK = getUnique(SetA_SK)
85SetA_SK
86"AA", "BB", "CC", "DD", "FF"
87SetB_SK = getUnique(SetB_SK)
88SetB_SK
89"CC", "DD", "EE", "aa"
90getComplement(SetA_SK, SetB_SK, sorted = .true._LK, unique = .true._LK)
91"EE", "aa"
92
93
94!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95! Find the complement of integer vector A in B: B \ A.
96!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
98
99SetA_IK
100+4, +5, +4, +1, +2, +1, +5
101SetB_IK
102+6, +3, +4, +2, +1, +2, +6
103getComplement(SetA_IK, SetB_IK)
104+6, +3, +6
105
106
107call setSorted(SetA_IK)
108SetA_IK
109+1, +1, +2, +4, +4, +5, +5
110call setSorted(SetB_IK)
111SetB_IK
112+1, +2, +2, +3, +4, +6, +6
113getComplement(SetA_IK, SetB_IK, sorted = .true._LK, unique = .false._LK)
114+3, +6, +6
115
116
117SetA_IK = getUnique(SetA_IK)
118SetA_IK
119+1, +2, +4, +5
120SetB_IK = getUnique(SetB_IK)
121SetB_IK
122+1, +2, +3, +4, +6
123getComplement(SetA_IK, SetB_IK, sorted = .true._LK, unique = .true._LK)
124+3, +6
125
126
127!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128! Find the complement of complex vector A in B: B \ A.
129!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131
132SetA_CK
133(+4.00000000, -4.00000000), (+5.00000000, -5.00000000), (+4.00000000, -4.00000000), (+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+8.00000000, -8.00000000), (+1.00000000, -1.00000000), (+5.00000000, -5.00000000)
134SetB_CK
135(+6.00000000, -6.00000000), (+3.00000000, -3.00000000), (+4.00000000, -4.00000000), (+2.00000000, -2.00000000), (+1.00000000, -1.00000000), (+7.00000000, -7.00000000), (+2.00000000, -2.00000000), (+6.00000000, -6.00000000)
136getComplement(SetA_CK, SetB_CK)
137(+6.00000000, -6.00000000), (+3.00000000, -3.00000000), (+7.00000000, -7.00000000), (+6.00000000, -6.00000000)
138
139
140call setSorted(SetA_CK)
141SetA_CK
142(+1.00000000, -1.00000000), (+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+4.00000000, -4.00000000), (+4.00000000, -4.00000000), (+5.00000000, -5.00000000), (+5.00000000, -5.00000000), (+8.00000000, -8.00000000)
143call setSorted(SetB_CK)
144SetB_CK
145(+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+2.00000000, -2.00000000), (+3.00000000, -3.00000000), (+4.00000000, -4.00000000), (+6.00000000, -6.00000000), (+6.00000000, -6.00000000), (+7.00000000, -7.00000000)
146getComplement(SetA_CK, SetB_CK, sorted = .true._LK, unique = .false._LK)
147(+3.00000000, -3.00000000), (+6.00000000, -6.00000000), (+6.00000000, -6.00000000), (+7.00000000, -7.00000000)
148
149
150SetA_CK = getUnique(SetA_CK)
151SetA_CK
152(+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+4.00000000, -4.00000000), (+5.00000000, -5.00000000), (+8.00000000, -8.00000000)
153SetB_CK = getUnique(SetB_CK)
154SetB_CK
155(+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+3.00000000, -3.00000000), (+4.00000000, -4.00000000), (+6.00000000, -6.00000000), (+7.00000000, -7.00000000)
156getComplement(SetA_CK, SetB_CK, sorted = .true._LK, unique = .true._LK)
157(+3.00000000, -3.00000000), (+6.00000000, -6.00000000), (+7.00000000, -7.00000000)
158
159
160!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161! Find the complement of real vector A in B: B \ A.
162!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163
164
165SetA_RK
166+4.00000000, +5.00000000, +4.00000000, +1.00000000, +2.00000000, +8.00000000, +1.00000000, +5.00000000
167SetB_RK
168+6.00000000, +3.00000000, +4.00000000, +2.00000000, +1.00000000, +7.00000000, +2.00000000, +6.00000000
169getComplement(SetA_RK, SetB_RK)
170+6.00000000, +3.00000000, +7.00000000, +6.00000000
171
172
173call setSorted(SetA_RK)
174SetA_RK
175+1.00000000, +1.00000000, +2.00000000, +4.00000000, +4.00000000, +5.00000000, +5.00000000, +8.00000000
176call setSorted(SetB_RK)
177SetB_RK
178+1.00000000, +2.00000000, +2.00000000, +3.00000000, +4.00000000, +6.00000000, +6.00000000, +7.00000000
179getComplement(SetA_RK, SetB_RK, sorted = .true._LK, unique = .false._LK)
180+3.00000000, +6.00000000, +6.00000000, +7.00000000
181
182
183SetA_RK = getUnique(SetA_RK)
184SetA_RK
185+1.00000000, +2.00000000, +4.00000000, +5.00000000, +8.00000000
186SetB_RK = getUnique(SetB_RK)
187SetB_RK
188+1.00000000, +2.00000000, +3.00000000, +4.00000000, +6.00000000, +7.00000000
189getComplement(SetA_RK, SetB_RK, sorted = .true._LK, unique = .true._LK)
190+3.00000000, +6.00000000, +7.00000000
191
192
193!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195! Find the complement using a custom equivalence check.
196!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198
199
200StrA_SK
201"AADBCCFEEZ"
202StrB_SK
203"eadgbbcgce"
204getComplement(StrA_SK, StrB_SK)
205"eadgbbcgce"
206getComplement(StrA_SK, StrB_SK, iseq = iseq_SK)
207"gg"
208
209
210call setSorted(StrA_SK)
211StrA_SK
212"AABCCDEEFZ"
213call setSorted(StrB_SK)
214StrB_SK
215"abbccdeegg"
216getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK)
217"abbccdeegg"
218getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .false._LK, iseq = iseq_SK)
219"gg"
220
221
222StrA_SK = getUnique(StrA_SK)
223StrA_SK
224"ABCDEFZ"
225StrB_SK = getUnique(StrB_SK)
226StrB_SK
227"abcdeg"
228getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK)
229"abcdeg"
230getComplement(StrA_SK, StrB_SK, sorted = .true._LK, unique = .true._LK, iseq = iseq_SK)
231"g"
232
233
Test:
test_pm_arrayComplement
Bug:

Status: Unresolved
Source: GNU Fortran Compiler gfortran version 10.3-12, Intel Classic Fortran Compiler ifort version 2021-2022
Description: Intel Classic Fortran Compiler ifort and GNU Fortran Compiler gfortran share a common bug with opposing behavior.
Intel Classic Fortran Compiler ifort cannot handle assumed-length allocatable output arguments of type character.
GNU Fortran Compiler gfortran cannot handle deferred-length allocatable output arguments of type character.

Remedy (as of ParaMonte Library version 2.0.0): For now, a preprocessor macro defines two separate interfaces for the two compilers so that both compilers can compile this file.
This minor interface difference should not impact the usage of this module with different compilers.


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 182 of file pm_arrayComplement.F90.


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