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

Generate and return .true. if and only if at least one element of the input sequence is unique among others.
More...

Detailed Description

Generate and return .true. if and only if at least one element of the input sequence is unique among others.

The uniqueness of the values can be optionally determined by the user by specifying the external input function that checks the equivalence of a pair of elements of the input array.

Parameters
[in]array: The input contiguous array of shape (:) of either
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
  • type logical of kind any supported by the processor (e.g., LK), or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), 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,
  • a scalar assumed-length character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
whose elements uniqueness are to be tested.
iseq: The external user-specified function that takes two input scalar arguments of the same type and kind as the input array.
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(element1, element2) result(equivalent)
use pm_kind, only: LK
TYPE(KIND) , intent(in) :: element1, element2
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) :: element1, element2 ! when `array` is a string vector.
character(1, SK), intent(in) :: element1, element2 ! when `array` is a string scalar.
integer(IK) , intent(in) :: element1, element2
logical(LK) , intent(in) :: element1, element2
complex(CK) , intent(in) :: element1, element2
real(RK) , intent(in) :: element1, element2
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, LK, 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 array 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 .eqv. if the input array is logical, otherwise ==.)
Returns
uniqueAny : The output scalar logical of default kind LK that is .true. if and only if any elements of the input sequence are unique.


Possible calling interfaces

uniqueAny = isUniqueAny(array)
uniqueAny = isUniqueAny(array, iseq)
Generate and return .true. if and only if at least one element of the input sequence is unique among ...
This module contains procedures and generic interfaces for finding unique values of an input array of...
Remarks
The procedures under discussion are pure.
Warning
The procedures under this generic interface are impure when the user-specified external procedure iseq is specified as input argument.
Note that in Fortran, trailing blanks are ignored in character comparison, that is, "Fortran" == "Fortran " yields .true..
See also
getUnique
setUnique
isUniqueAny


Example usage

1program example
2
3 use pm_kind, only: LK
4 use pm_kind, only: SK ! Any kinds are supported.
5 use pm_kind, only: IK ! Any kinds are supported.
6 use pm_kind, only: CK ! Any kinds are supported.
7 use pm_kind, only: RKG => RK ! Any kinds are supported.
8 use pm_io, only: display_type
10
11 implicit none
12
13 type(display_type) :: disp
14
15 disp = display_type(file = "main.out.F90")
16
17 call disp%skip()
18 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
19 call disp%show("! Unique elements in character scalar.")
20 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
21 call disp%skip()
22
23 call disp%show("isUniqueAny('')")
24 call disp%show( isUniqueAny('') )
25
26 call disp%show("isUniqueAny('a')")
27 call disp%show( isUniqueAny('a') )
28
29 call disp%show("isUniqueAny('abcd')")
30 call disp%show( isUniqueAny('abcd') )
31
32 call disp%show("isUniqueAny('abbd')")
33 call disp%show( isUniqueAny('abbd') )
34
35 call disp%show("isUniqueAny('aaa ')")
36 call disp%show( isUniqueAny('aaa ') )
37
38 call disp%show("isUniqueAny('abc ')")
39 call disp%show( isUniqueAny('abc ') )
40
41 call disp%show("isUniqueAny('aaa')")
42 call disp%show( isUniqueAny('aaa') )
43
44 call disp%skip()
45 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
46 call disp%show("! Unique elements in character array.")
47 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
48 call disp%skip()
49
50 call disp%show("isUniqueAny([character(1)::])")
51 call disp%show( isUniqueAny([character(1)::]) )
52
53 call disp%show("isUniqueAny(['a'])")
54 call disp%show( isUniqueAny(['a']) )
55
56 call disp%show("isUniqueAny(['a', 'b', 'c', 'd', ' '])")
57 call disp%show( isUniqueAny(['a', 'b', 'c', 'd', ' ']) )
58
59 call disp%show("isUniqueAny(['a', 'b', 'b', 'd', ' '])")
60 call disp%show( isUniqueAny(['a', 'b', 'b', 'd', ' ']) )
61
62 call disp%show("isUniqueAny(['a', 'a', 'a', 'a', ' '])")
63 call disp%show( isUniqueAny(['a', 'a', 'a', 'a', ' ']) )
64
65 call disp%show("isUniqueAny([character(2) :: 'a', 'b', 'c', 'd', 'a '])")
66 call disp%show( isUniqueAny([character(2) :: 'a', 'b', 'c', 'd', 'a ']) )
67
68 call disp%show("isUniqueAny(['a', 'a', 'a', 'a'])")
69 call disp%show( isUniqueAny(['a', 'a', 'a', 'a']) )
70
71 call disp%skip()
72 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
73 call disp%show("! Unique elements in integer array.")
74 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
75 call disp%skip()
76
77 call disp%show("isUniqueAny([integer::])")
78 call disp%show( isUniqueAny([integer::]) )
79
80 call disp%show("isUniqueAny([1])")
81 call disp%show( isUniqueAny([1]) )
82
83 call disp%show("isUniqueAny([1, 2, 3, 4, 0])")
84 call disp%show( isUniqueAny([1, 2, 3, 4, 0]) )
85
86 call disp%show("isUniqueAny([1, 2, 2, 4, 0])")
87 call disp%show( isUniqueAny([1, 2, 2, 4, 0]) )
88
89 call disp%show("isUniqueAny([1, 1, 1, 1, 0])")
90 call disp%show( isUniqueAny([1, 1, 1, 1, 0]) )
91
92 call disp%show("isUniqueAny([1, 1, 1, 1])")
93 call disp%show( isUniqueAny([1, 1, 1, 1]) )
94
95 call disp%skip()
96 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
97 call disp%show("! Unique elements in logical array.")
98 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%skip()
100
101 call disp%show("isUniqueAny([logical::])")
102 call disp%show( isUniqueAny([logical::]) )
103
104 call disp%show("isUniqueAny([.true.])")
105 call disp%show( isUniqueAny([.true.]) )
106
107 call disp%show("isUniqueAny([.true., .false., .true., .false.])")
108 call disp%show( isUniqueAny([.true., .false., .true., .false.]) )
109
110 call disp%show("isUniqueAny([.false., .false., .false., .true.])")
111 call disp%show( isUniqueAny([.false., .false., .false., .true.]) )
112
113 call disp%show("isUniqueAny([.true., .true., .true., .false.])")
114 call disp%show( isUniqueAny([.true., .true., .true., .false.]) )
115
116 call disp%show("isUniqueAny([.false., .false., .false.])")
117 call disp%show( isUniqueAny([.false., .false., .false.]) )
118
119 call disp%show("isUniqueAny([.true., .true., .true.])")
120 call disp%show( isUniqueAny([.true., .true., .true.]) )
121
122 call disp%skip()
123 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
124 call disp%show("! Unique elements in complex array.")
125 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
126 call disp%skip()
127
128 call disp%show("isUniqueAny([complex::])")
129 call disp%show( isUniqueAny([complex::]) )
130
131 call disp%show("isUniqueAny([(1., -1)])")
132 call disp%show( isUniqueAny([(1., -1)]) )
133
134 call disp%show("isUniqueAny([(1., -1.), (2., -2.), (3., -3.), (4., -4.), (0., 0.)])")
135 call disp%show( isUniqueAny([(1., -1.), (2., -2.), (3., -3.), (4., -4.), (0., 0.)]) )
136
137 call disp%show("isUniqueAny([(1., -1.), (2., -2.), (2., -2.), (4., -4.), (0., 0.)])")
138 call disp%show( isUniqueAny([(1., -1.), (2., -2.), (2., -2.), (4., -4.), (0., 0.)]) )
139
140 call disp%show("isUniqueAny([(1., -1.), (1., -1.), (1., -1.), (1., -1.), (0., 0.)])")
141 call disp%show( isUniqueAny([(1., -1.), (1., -1.), (1., -1.), (1., -1.), (0., 0.)]) )
142
143 call disp%show("isUniqueAny([(1., -1.), (1., -1.), (1., -1.), (1., -1.)])")
144 call disp%show( isUniqueAny([(1., -1.), (1., -1.), (1., -1.), (1., -1.)]) )
145
146 call disp%skip()
147 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
148 call disp%show("! Unique elements in real array.")
149 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
150 call disp%skip()
151
152 call disp%show("isUniqueAny([real::])")
153 call disp%show( isUniqueAny([real::]) )
154
155 call disp%show("isUniqueAny([1.])")
156 call disp%show( isUniqueAny([1.]) )
157
158 call disp%show("isUniqueAny([1., 2., 3., 4., 0.])")
159 call disp%show( isUniqueAny([1., 2., 3., 4., 0.]) )
160
161 call disp%show("isUniqueAny([1., 2., 2., 4., 0.])")
162 call disp%show( isUniqueAny([1., 2., 2., 4., 0.]) )
163
164 call disp%show("isUniqueAny([1., 1., 1., 1., 0.])")
165 call disp%show( isUniqueAny([1., 1., 1., 1., 0.]) )
166
167 call disp%show("isUniqueAny([1., 1., 1., 1.])")
168 call disp%show( isUniqueAny([1., 1., 1., 1.]) )
169
170 call disp%skip()
171 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
172 call disp%show("! Unique elements in real array.")
173 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
174 call disp%skip()
175
176 call disp%show("isUniqueAny([real(RKG) :: 1.01, 1.04, 0.98, 1.0, 1.02, 2.], iseq = iseq_RK)")
177 call disp%show( isUniqueAny([real(RKG) :: 1.01, 1.04, 0.98, 1.0, 1.02, 2.], iseq = iseq_RK) )
178
179 call disp%skip()
180 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
181 call disp%show("! Unique case-insensitive instances within the character array.")
182 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
183 call disp%skip()
184
185 call disp%show("isUniqueAny('ABBAbbA', iseq = iseq_SK)")
186 call disp%show( isUniqueAny('ABBAbbA', iseq = iseq_SK), deliml = SK_"""" )
187
188contains
189
190 pure function iseq_RK(element1, element2) result(iseq)
191 real(RKG) , intent(in) :: element1, element2
192 logical(LK) :: iseq
193 iseq = abs(abs(element1) - abs(element2)) < 0.05_RKG
194 end function
195
196 pure function iseq_SK(element1, element2) result(iseq)
197 use pm_strASCII, only: getStrLower
198 character(*, SK) , intent(in) :: element1, element2
199 logical(LK) :: iseq
200 iseq = getStrLower(element1) == getStrLower(element2)
201 end function
202
203end program example
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 string where the uppercase English alphabets are all converted to lower...
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 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! Unique elements in character scalar.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
7F
9T
10isUniqueAny('abcd')
11T
12isUniqueAny('abbd')
13T
14isUniqueAny('aaa ')
15T
16isUniqueAny('abc ')
17T
18isUniqueAny('aaa')
19F
20
21!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22! Unique elements in character array.
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25isUniqueAny([character(1)::])
26F
27isUniqueAny(['a'])
28T
29isUniqueAny(['a', 'b', 'c', 'd', ' '])
30T
31isUniqueAny(['a', 'b', 'b', 'd', ' '])
32T
33isUniqueAny(['a', 'a', 'a', 'a', ' '])
34T
35isUniqueAny([character(2) :: 'a', 'b', 'c', 'd', 'a '])
36T
37isUniqueAny(['a', 'a', 'a', 'a'])
38F
39
40!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41! Unique elements in integer array.
42!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43
44isUniqueAny([integer::])
45F
46isUniqueAny([1])
47T
48isUniqueAny([1, 2, 3, 4, 0])
49T
50isUniqueAny([1, 2, 2, 4, 0])
51T
52isUniqueAny([1, 1, 1, 1, 0])
53T
54isUniqueAny([1, 1, 1, 1])
55F
56
57!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58! Unique elements in logical array.
59!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
61isUniqueAny([logical::])
62F
63isUniqueAny([.true.])
64T
65isUniqueAny([.true., .false., .true., .false.])
66F
67isUniqueAny([.false., .false., .false., .true.])
68T
69isUniqueAny([.true., .true., .true., .false.])
70T
71isUniqueAny([.false., .false., .false.])
72F
73isUniqueAny([.true., .true., .true.])
74F
75
76!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77! Unique elements in complex array.
78!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80isUniqueAny([complex::])
81F
82isUniqueAny([(1., -1)])
83T
84isUniqueAny([(1., -1.), (2., -2.), (3., -3.), (4., -4.), (0., 0.)])
85T
86isUniqueAny([(1., -1.), (2., -2.), (2., -2.), (4., -4.), (0., 0.)])
87T
88isUniqueAny([(1., -1.), (1., -1.), (1., -1.), (1., -1.), (0., 0.)])
89T
90isUniqueAny([(1., -1.), (1., -1.), (1., -1.), (1., -1.)])
91F
92
93!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94! Unique elements in real array.
95!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97isUniqueAny([real::])
98F
99isUniqueAny([1.])
100T
101isUniqueAny([1., 2., 3., 4., 0.])
102T
103isUniqueAny([1., 2., 2., 4., 0.])
104T
105isUniqueAny([1., 1., 1., 1., 0.])
106T
107isUniqueAny([1., 1., 1., 1.])
108F
109
110!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111! Unique elements in real array.
112!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114isUniqueAny([real(RKG) :: 1.01, 1.04, 0.98, 1.0, 1.02, 2.], iseq = iseq_RK)
115T
116
117!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118! Unique case-insensitive instances within the character array.
119!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121isUniqueAny('ABBAbbA', iseq = iseq_SK)
122"F"
123
Test:
test_pm_arrayUnique


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:
Amir Shahmoradi, September 1, 2017, 11:35 PM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 1770 of file pm_arrayUnique.F90.


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