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

Return a vector of unique values in the input array in place of the array itself.
More...

Detailed Description

Return a vector of unique values in the input array in place of the array itself.

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.
Furthermore, optionally return the count of each of the unique values in the input array, as well as the indices of occurrences of each of the unique values.

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 unique elements are to be returned.
[out]unique: The output array of the same type and kind as the input array containing all of its unique elements.
  • If the output argument lenUnique is present, then unique must be a contiguous array (or scalar string) whose length equals the length of the input array.
  • If the output argument lenUnique is missing, then unique must be an allocatable array (or scalar string).
[out]lenUnique: The output scalar of type integer of default kind of the same type and kind as the input array containing all of its unique elements.
(optional, if present, the specified arrays unique, count, index must be preallocated to the length of array.)
[out]count: The output array of type integer of default kind IK containing the corresponding counts of each of the uniques elements of array in the output unique array.
  • If the output argument lenUnique is present, then count must be a contiguous array (or scalar string) whose length equals the length of the input array.
  • If the output argument lenUnique is missing, then count must be an allocatable array (or scalar string).
[out]index: The output jagged-array of type cvi_type of default kind IK each element of which contains the vector of indices of the positions of occurrences of the uniques values in array.
  • If the output argument lenUnique is present, then index must be a contiguous array (or scalar string) whose length equals the length of the input array.
  • If the output argument lenUnique is missing, then index must be an allocatable array (or scalar string).
(optional, it can be missing.)
[in]order: The input integer of default kind IK.
If 0, the output array count will be not be sorted.
If -1, the output array count (and along with it, unique and index) will be sorted in descending order.
If +1, the output array count (and along with it, unique and index) will be sorted in ascending order.
(optional, default = 0_IK)
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 ==.)


Possible calling interfaces

call setUnique(array, unique(:), count(:), index = index(:), order = order) ! Requires allocatable `unique`, `count`, and `index` arguments.
call setUnique(array, unique(:), count(:), iseq, index = index(:), order = order) ! Requires allocatable `unique`, `count`, and `index` arguments.
call setUnique(array, unique(:), lenUnique, count(:), index = index(:), order = order) ! Avoids argument allocations for performance-critical tasks.
call setUnique(array, unique(:), lenUnique, count(:), iseq, index = index(:), order = order) ! Avoids argument allocations for performance-critical tasks.
!
Return a vector of unique values in the input array in place of the array itself.
This module contains procedures and generic interfaces for finding unique values of an input array of...
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.
The procedures under this generic interface are impure when the user-specified external procedure iseq is specified as input argument.
The condition lenUnique <= len/size(unique) must hold for the corresponding input/output arguments.
The condition lenUnique <= len/size(index) must hold for the corresponding input/output arguments.
The condition lenUnique <= len/size(count) must hold for the corresponding input/output arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Note that in Fortran, trailing blanks are ignored in character comparison, that is, "Fortran" == "Fortran " yields .true..
Remarks
The functions under this generic interface are slightly faster than the getUnique functional implementations.
See also
getUnique
setUnique
isUniqueAll
isUniqueAny


Example usage

1program example
2
3 use pm_kind, only: LK
4 use pm_kind, only: SK ! All kinds are supported.
5 use pm_kind, only: IK ! All kinds are supported.
6 use pm_kind, only: CK ! All kinds are supported.
7 use pm_kind, only: RK ! All kinds are supported.
8 use pm_io, only: display_type
10 use pm_container, only: Vector => cvi_type
11
12 implicit none
13
14 type(Vector) , allocatable :: index(:) ! The jagged-array of locations of occurrences of the unique elements.
15 integer(IK) , allocatable :: Count(:) ! Must be of default kind IK
16 character(:, SK), allocatable :: string_SK , stringUnique_SK
17 character(9, SK), allocatable :: Array_SK(:) , UniqueArray_SK(:) ! Can be any processor-supported kind.
18 integer(IK) , allocatable :: Array_IK(:) , UniqueArray_IK(:) ! Can be any processor-supported kind.
19 complex(CK) , allocatable :: Array_CK(:) , UniqueArray_CK(:) ! Can be any processor-supported kind.
20 real(RK) , allocatable :: Array_RK(:) , UniqueArray_RK(:) ! Can be any processor-supported kind.
21
22 type(display_type) :: disp
23
24 disp = display_type(file = "main.out.F90")
25
26 string_SK = "ParaMonte is a Monte Carlo Library."
27 Array_SK = ["ParaMonte", "PARAMONTE", "paramonte", "ParaMonte", "ParaMonte", "Paramonte"]
28 Array_IK = [1_IK, 1_IK, 3_IK, 4_IK, 4_IK, 4_IK]
29 Array_RK = [1._RK, 1._RK, 3._RK, 4._RK, 4._RK, 4._RK]
30 Array_CK = [(1._CK, -1._CK), (1._CK, -1._CK), (3._CK, -3._CK), (4._CK, -4._CK), (4._CK, -4._CK), (4._CK, -4._CK)]
31
32
33 call disp%skip()
34 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
35 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
36 call disp%show("! Find all unique elements along with their frequency and locations of occurrences in array.")
37 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
38 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
39 call disp%skip()
40
41 call disp%skip()
42 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
43 call disp%show("! Unique elements in character scalar along with their frequency and locations of occurrences.")
44 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
45 call disp%skip()
46
47 call disp%show("string_SK")
48 call disp%show( string_SK, deliml = SK_"""" )
49 call disp%show("call setUnique(string_SK, stringUnique_SK, Count, index)")
50 call setUnique(string_SK, stringUnique_SK, Count, index)
51 call disp%show("stringUnique_SK")
52 call disp%show( stringUnique_SK, deliml = SK_"""" )
53 call disp%show("Count")
54 call disp%show( Count )
55 call disp%show("index")
56 call disp%show( index )
57
58 call disp%skip()
59 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
60 call disp%show("! Unique elements in character array along with their frequency and locations of occurrences.")
61 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
62 call disp%skip()
63
64 call disp%show("Array_SK")
65 call disp%show( Array_SK, deliml = SK_"""" )
66 call disp%show("call setUnique(Array_SK, UniqueArray_SK, Count, index)")
67 call setUnique(Array_SK, UniqueArray_SK, Count, index)
68 call disp%show("UniqueArray_SK")
69 call disp%show( UniqueArray_SK, deliml = SK_"""" )
70 call disp%show("Count")
71 call disp%show( Count )
72 call disp%show("index")
73 call disp%show( index )
74
75 call disp%skip()
76 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
77 call disp%show("! Unique elements in integer array along with their frequency and locations of occurrences.")
78 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
79 call disp%skip()
80
81 call disp%show("Array_IK")
82 call disp%show( Array_IK )
83 call disp%show("call setUnique(Array_IK, UniqueArray_IK, Count, index)")
84 call setUnique(Array_IK, UniqueArray_IK, Count, index)
85 call disp%show("UniqueArray_IK")
86 call disp%show( UniqueArray_IK )
87 call disp%show("Count")
88 call disp%show( Count )
89 call disp%show("index")
90 call disp%show( index )
91
92 call disp%skip()
93 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
94 call disp%show("! Unique elements in complex array along with their frequency and locations of occurrences.")
95 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
96 call disp%skip()
97
98 call disp%show("Array_CK")
99 call disp%show( Array_CK )
100 call disp%show("call setUnique(Array_CK, UniqueArray_CK, Count, index)")
101 call setUnique(Array_CK, UniqueArray_CK, Count, index)
102 call disp%show("UniqueArray_CK")
103 call disp%show( UniqueArray_CK )
104 call disp%show("Count")
105 call disp%show( Count )
106 call disp%show("index")
107 call disp%show( index )
108
109 call disp%skip()
110 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
111 call disp%show("! Unique elements in real array along with their frequency and locations of occurrences.")
112 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
113 call disp%skip()
114
115 Array_RK = Array_RK
116 call disp%show("Array_RK")
117 call disp%show( Array_RK )
118 call disp%show("call setUnique(Array_RK, UniqueArray_RK, Count, index)")
119 call setUnique(Array_RK, UniqueArray_RK, Count, index)
120 call disp%show("UniqueArray_RK")
121 call disp%show( UniqueArray_RK )
122 call disp%show("Count")
123 call disp%show( Count )
124 call disp%show("index")
125 call disp%show( index )
126
127
128 call disp%skip()
129 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
130 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
131 call disp%show("! Find all unique elements according to the user-specified equivalence criterion.")
132 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
133 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
134 call disp%skip()
135
136 call disp%skip()
137 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
138 call disp%show("! Unique elements in real array.")
139 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
140 call disp%skip()
141
142 Array_RK = [1.01_RK, 1.04_RK, 0.98_RK, 1.0_RK, 1.02_RK, 2._RK]
143
144 call disp%show("Array_RK")
145 call disp%show( Array_RK )
146 call disp%show("call setUnique(Array_RK, UniqueArray_RK, Count, iseq = iseq_RK)")
147 call setUnique(Array_RK, UniqueArray_RK, Count, iseq = iseq_RK)
148 call disp%show("UniqueArray_RK")
149 call disp%show( UniqueArray_RK )
150 call disp%show("Count")
151 call disp%show( Count )
152
153 call disp%skip()
154 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
155 call disp%show("! Unique case-insensitive instances within the character array.")
156 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
157 call disp%skip()
158
159 string_SK = "ABBAbbA"
160
161 call disp%show("string_SK")
162 call disp%show( string_SK, deliml = SK_"""" )
163 call disp%show("call setUnique(string_SK, stringUnique_SK, Count, iseq = iseq_SK)")
164 call setUnique(string_SK, stringUnique_SK, Count, iseq = iseq_SK)
165 call disp%show("stringUnique_SK")
166 call disp%show( stringUnique_SK, deliml = SK_"""" )
167 call disp%show("Count")
168 call disp%show( Count )
169
170contains
171
172 pure function iseq_RK(element1, element2) result(iseq)
173 real(RK) , intent(in) :: element1, element2
174 logical(LK) :: iseq
175 iseq = abs(abs(element1) - abs(element2)) < 0.05_RK
176 end function
177
178 pure function iseq_SK(element1, element2) result(iseq)
179 use pm_strASCII, only: getStrLower
180 character(*, SK) , intent(in) :: element1, element2
181 logical(LK) :: iseq
182 iseq = getStrLower(element1) == getStrLower(element2)
183 end function
184
185end 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 the derived types for generating allocatable containers of scalar,...
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
This is the derived type for generating a container of a vector component of type integer of default ...
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!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Find all unique elements along with their frequency and locations of occurrences in array.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10! Unique elements in character scalar along with their frequency and locations of occurrences.
11!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13string_SK
14"ParaMonte is a Monte Carlo Library."
15call setUnique(string_SK, stringUnique_SK, Count, index)
16stringUnique_SK
17"ParMonte isClLby."
18Count
19+1, +5, +4, +2, +3, +2, +2, +2, +5, +2, +1, +1, +1, +1, +1, +1, +1
20index
21+1
22+2, +4, +14, +23, +32
23+3, +24, +31, +33
24+5, +16
25+6, +17, +26
26+7, +18
27+8, +19
28+9, +20
29+10, +13, +15, +21, +27
30+11, +29
31+12
32+22
33+25
34+28
35+30
36+34
37+35
38
39!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40! Unique elements in character array along with their frequency and locations of occurrences.
41!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42
43Array_SK
44"ParaMonte", "PARAMONTE", "paramonte", "ParaMonte", "ParaMonte", "Paramonte"
45call setUnique(Array_SK, UniqueArray_SK, Count, index)
46UniqueArray_SK
47"ParaMonte", "PARAMONTE", "paramonte", "Paramonte"
48Count
49+3, +1, +1, +1
50index
51+1, +4, +5
52+2
53+3
54+6
55
56!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57! Unique elements in integer array along with their frequency and locations of occurrences.
58!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
60Array_IK
61+1, +1, +3, +4, +4, +4
62call setUnique(Array_IK, UniqueArray_IK, Count, index)
63UniqueArray_IK
64+1, +3, +4
65Count
66+2, +1, +3
67index
68+1, +2
69+3
70+4, +5, +6
71
72!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73! Unique elements in complex array along with their frequency and locations of occurrences.
74!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76Array_CK
77(+1.0000000000000000, -1.0000000000000000), (+1.0000000000000000, -1.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+4.0000000000000000, -4.0000000000000000)
78call setUnique(Array_CK, UniqueArray_CK, Count, index)
79UniqueArray_CK
80(+1.0000000000000000, -1.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000)
81Count
82+2, +1, +3
83index
84+1, +2
85+3
86+4, +5, +6
87
88!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89! Unique elements in real array along with their frequency and locations of occurrences.
90!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92Array_RK
93+1.0000000000000000, +1.0000000000000000, +3.0000000000000000, +4.0000000000000000, +4.0000000000000000, +4.0000000000000000
94call setUnique(Array_RK, UniqueArray_RK, Count, index)
95UniqueArray_RK
96+1.0000000000000000, +3.0000000000000000, +4.0000000000000000
97Count
98+2, +1, +3
99index
100+1, +2
101+3
102+4, +5, +6
103
104!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106! Find all unique elements according to the user-specified equivalence criterion.
107!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
110
111!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112! Unique elements in real array.
113!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
115Array_RK
116+1.0100000000000000, +1.0400000000000000, +0.97999999999999998, +1.0000000000000000, +1.0200000000000000, +2.0000000000000000
117call setUnique(Array_RK, UniqueArray_RK, Count, iseq = iseq_RK)
118UniqueArray_RK
119+1.0100000000000000, +2.0000000000000000
120Count
121+5, +1
122
123!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124! Unique case-insensitive instances within the character array.
125!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127string_SK
128"ABBAbbA"
129call setUnique(string_SK, stringUnique_SK, Count, iseq = iseq_SK)
130stringUnique_SK
131"AB"
132Count
133+3, +4
134
Test:
test_pm_arrayUnique
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version 2021.7
Description: The Intel Classic Fortran Compiler ifort version 2021.7 on Microsoft WSL (and possibly other platforms) cannot properly call getRemapped(unique, ...) when unique is a contiguous character array.

Remedy (as of ParaMonte Library version 2.0.0): For now, the remappings are done separately using the Fortran syntax to bypass the problem.
This bug cost half a day of human life to identify.
Todo:
Low Priority: This generic interface can be extended to 2D input objects.
Todo:
High Priority: To avoid extra data copy and improve performance, an extra optional lenUnique output argument could be added to the procedures such that when it is present, the output arrays unique and count will not be resized from size(array) to the correct length lenUnique.
In such a case, the onus would be on the user to ensure only the elements (1:lenUnique) of the output arrays are used for any subsequent work as only these elements are meaningful. This would, however, come with the benefit of extra efficiency.


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 3550 of file pm_arrayUnique.F90.


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