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

Generate and return .true. for each element of the input sequence whose value is unique among all sequence element values, otherwise return .false..
More...

Detailed Description

Generate and return .true. for each element of the input sequence whose value is unique among all sequence element values, otherwise return .false..

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
unique : The output logical vector of default kind LK of the same size as the length of the input sequence, each element of which is .true. if and only if the corresponding element of the input sequence has a unique value.


Possible calling interfaces

unique(:) = isUnique(array)
unique(:) = isUnique(array, iseq)
Generate and return .true. for each element of the input sequence whose value is unique among all seq...
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
isUnique
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
9 use pm_arrayUnique, only: isUnique
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("isUnique('')")
24 call disp%show( isUnique('') )
25
26 call disp%show("isUnique('a')")
27 call disp%show( isUnique('a') )
28
29 call disp%show("isUnique('abcd')")
30 call disp%show( isUnique('abcd') )
31
32 call disp%show("isUnique('abbd')")
33 call disp%show( isUnique('abbd') )
34
35 call disp%show("isUnique('aaa ')")
36 call disp%show( isUnique('aaa ') )
37
38 call disp%show("isUnique('abc ')")
39 call disp%show( isUnique('abc ') )
40
41 call disp%show("isUnique('aaa')")
42 call disp%show( isUnique('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("isUnique([character(1)::])")
51 call disp%show( isUnique([character(1)::]) )
52
53 call disp%show("isUnique(['a'])")
54 call disp%show( isUnique(['a']) )
55
56 call disp%show("isUnique(['a', 'b', 'c', 'd', ' '])")
57 call disp%show( isUnique(['a', 'b', 'c', 'd', ' ']) )
58
59 call disp%show("isUnique(['a', 'b', 'b', 'd', ' '])")
60 call disp%show( isUnique(['a', 'b', 'b', 'd', ' ']) )
61
62 call disp%show("isUnique(['a', 'a', 'a', 'a', ' '])")
63 call disp%show( isUnique(['a', 'a', 'a', 'a', ' ']) )
64
65 call disp%show("isUnique([character(2) :: 'a', 'b', 'c', 'd', 'a '])")
66 call disp%show( isUnique([character(2) :: 'a', 'b', 'c', 'd', 'a ']) )
67
68 call disp%show("isUnique(['a', 'a', 'a', 'a'])")
69 call disp%show( isUnique(['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("isUnique([integer::])")
78 call disp%show( isUnique([integer::]) )
79
80 call disp%show("isUnique([1])")
81 call disp%show( isUnique([1]) )
82
83 call disp%show("isUnique([1, 2, 3, 4, 0])")
84 call disp%show( isUnique([1, 2, 3, 4, 0]) )
85
86 call disp%show("isUnique([1, 2, 2, 4, 0])")
87 call disp%show( isUnique([1, 2, 2, 4, 0]) )
88
89 call disp%show("isUnique([1, 1, 1, 1, 0])")
90 call disp%show( isUnique([1, 1, 1, 1, 0]) )
91
92 call disp%show("isUnique([1, 1, 1, 1])")
93 call disp%show( isUnique([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("isUnique([logical::])")
102 call disp%show( isUnique([logical::]) )
103
104 call disp%show("isUnique([.true.])")
105 call disp%show( isUnique([.true.]) )
106
107 call disp%show("isUnique([.true., .false., .true., .false.])")
108 call disp%show( isUnique([.true., .false., .true., .false.]) )
109
110 call disp%show("isUnique([.false., .false., .false., .true.])")
111 call disp%show( isUnique([.false., .false., .false., .true.]) )
112
113 call disp%show("isUnique([.true., .true., .true., .false.])")
114 call disp%show( isUnique([.true., .true., .true., .false.]) )
115
116 call disp%show("isUnique([.false., .false., .false.])")
117 call disp%show( isUnique([.false., .false., .false.]) )
118
119 call disp%show("isUnique([.true., .true., .true.])")
120 call disp%show( isUnique([.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("isUnique([complex::])")
129 call disp%show( isUnique([complex::]) )
130
131 call disp%show("isUnique([(1., -1)])")
132 call disp%show( isUnique([(1., -1)]) )
133
134 call disp%show("isUnique([(1., -1.), (2., -2.), (3., -3.), (4., -4.), (0., 0.)])")
135 call disp%show( isUnique([(1., -1.), (2., -2.), (3., -3.), (4., -4.), (0., 0.)]) )
136
137 call disp%show("isUnique([(1., -1.), (2., -2.), (2., -2.), (4., -4.), (0., 0.)])")
138 call disp%show( isUnique([(1., -1.), (2., -2.), (2., -2.), (4., -4.), (0., 0.)]) )
139
140 call disp%show("isUnique([(1., -1.), (1., -1.), (1., -1.), (1., -1.), (0., 0.)])")
141 call disp%show( isUnique([(1., -1.), (1., -1.), (1., -1.), (1., -1.), (0., 0.)]) )
142
143 call disp%show("isUnique([(1., -1.), (1., -1.), (1., -1.), (1., -1.)])")
144 call disp%show( isUnique([(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("isUnique([real::])")
153 call disp%show( isUnique([real::]) )
154
155 call disp%show("isUnique([1.])")
156 call disp%show( isUnique([1.]) )
157
158 call disp%show("isUnique([1., 2., 3., 4., 0.])")
159 call disp%show( isUnique([1., 2., 3., 4., 0.]) )
160
161 call disp%show("isUnique([1., 2., 2., 4., 0.])")
162 call disp%show( isUnique([1., 2., 2., 4., 0.]) )
163
164 call disp%show("isUnique([1., 1., 1., 1., 0.])")
165 call disp%show( isUnique([1., 1., 1., 1., 0.]) )
166
167 call disp%show("isUnique([1., 1., 1., 1.])")
168 call disp%show( isUnique([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("isUnique([real(RKG) :: 1.01, 1.04, 0.98, 1.0, 1.02, 2.], iseq = iseq_RK)")
177 call disp%show( isUnique([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("isUnique('ABBAbbA', iseq = iseq_SK)")
186 call disp%show( isUnique('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
6isUnique('')
7
8isUnique('a')
9T
10isUnique('abcd')
11T, T, T, T
12isUnique('abbd')
13T, F, F, T
14isUnique('aaa ')
15F, F, F, T
16isUnique('abc ')
17T, T, T, T
18isUnique('aaa')
19F, F, F
20
21!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22! Unique elements in character array.
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25isUnique([character(1)::])
26
27isUnique(['a'])
28T
29isUnique(['a', 'b', 'c', 'd', ' '])
30T, T, T, T, T
31isUnique(['a', 'b', 'b', 'd', ' '])
32T, F, F, T, T
33isUnique(['a', 'a', 'a', 'a', ' '])
34F, F, F, F, T
35isUnique([character(2) :: 'a', 'b', 'c', 'd', 'a '])
36F, T, T, T, F
37isUnique(['a', 'a', 'a', 'a'])
38F, F, F, F
39
40!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41! Unique elements in integer array.
42!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43
44isUnique([integer::])
45
46isUnique([1])
47T
48isUnique([1, 2, 3, 4, 0])
49T, T, T, T, T
50isUnique([1, 2, 2, 4, 0])
51T, F, F, T, T
52isUnique([1, 1, 1, 1, 0])
53F, F, F, F, T
54isUnique([1, 1, 1, 1])
55F, F, F, F
56
57!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58! Unique elements in logical array.
59!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
61isUnique([logical::])
62
63isUnique([.true.])
64T
65isUnique([.true., .false., .true., .false.])
66F, F, F, F
67isUnique([.false., .false., .false., .true.])
68F, F, F, T
69isUnique([.true., .true., .true., .false.])
70F, F, F, T
71isUnique([.false., .false., .false.])
72F, F, F
73isUnique([.true., .true., .true.])
74F, F, F
75
76!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77! Unique elements in complex array.
78!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80isUnique([complex::])
81
82isUnique([(1., -1)])
83T
84isUnique([(1., -1.), (2., -2.), (3., -3.), (4., -4.), (0., 0.)])
85T, T, T, T, T
86isUnique([(1., -1.), (2., -2.), (2., -2.), (4., -4.), (0., 0.)])
87T, F, F, T, T
88isUnique([(1., -1.), (1., -1.), (1., -1.), (1., -1.), (0., 0.)])
89F, F, F, F, T
90isUnique([(1., -1.), (1., -1.), (1., -1.), (1., -1.)])
91F, F, F, F
92
93!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94! Unique elements in real array.
95!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97isUnique([real::])
98
99isUnique([1.])
100T
101isUnique([1., 2., 3., 4., 0.])
102T, T, T, T, T
103isUnique([1., 2., 2., 4., 0.])
104T, F, F, T, T
105isUnique([1., 1., 1., 1., 0.])
106F, F, F, F, T
107isUnique([1., 1., 1., 1.])
108F, F, F, F
109
110!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111! Unique elements in real array.
112!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114isUnique([real(RKG) :: 1.01, 1.04, 0.98, 1.0, 1.02, 2.], iseq = iseq_RK)
115F, F, F, F, F, T
116
117!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118! Unique case-insensitive instances within the character array.
119!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121isUnique('ABBAbbA', iseq = iseq_SK)
122"F", "F", "F", "F", "F", "F", "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 Austin

Definition at line 139 of file pm_arrayUnique.F90.


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