Generate a compacted version of the input array
where all sequentially duplicate entries along the specified dimension of array
are condensed to a single entry in the output compact
.
- Parameters
-
[in,out] | array | : The input contiguous array of shape (:) or (:,:) 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 scalar character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU).
On input, it contains the elements to be condensed.
On output, the first csize entries of array contain the condensed elements of the original input array , such that no two adjacent entries in array from entry 1 to entry csize are duplicates. |
[out] | weight | : The output contiguous array of shape (:) of type integer of default kind IK of the same size as array .
On output, the first csize elements of weight contain the weights of the elements of the output condensed array such that getVerbose(array(1:csize), weight(1:csize), sum(weight)) returns the original array .
|
[out] | csize | : The output scalar of type integer of default kind IK such that,
-
weight(1:csize) contains the weight of the condensed elements of the input array , and
-
array(1:csize) or array(:,1:csize) or array(1:csize,:) contains the condensed elements of the input array .
|
[in] | dim | : The input scalar of type integer of default kind IK representing the axis of array(:,:) along which array must be compacted.
(optional, it must be present if and only if array is of shape (:,:) .) |
Possible calling interfaces ⛓
call setCompact(array(:,:), weight(:), csize, dim)
!
Generate a compacted version of the input array where all sequentially duplicate entries along the sp...
This module contains procedures and generic interfaces for condensing (removing duplicate sequential ...
- Warning
- The condition
dim == 1 .or. dim == 2
must hold.
The condition size(weight) == size(array)
must hold when array
is rank 1
.
The condition size(weight) == size(array, dim)
must hold when array
is rank 2
.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
-
The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
- See also
- getCompact
getVerbose
Example usage ⛓
10 integer(IK) ,
parameter :: ND
= 2_IK, NP
= 8_IK
11 integer(IK) :: Weight(NP)
12 integer(IK) :: newsize
13 type(display_type) :: disp
21 character(:, SK),
allocatable :: string
22 character(
2, SK),
allocatable :: Array_SK(:)
23 integer(IK) ,
allocatable :: Array_IK(:)
24 logical(LK) ,
allocatable :: Array_LK(:)
25 complex(CK) ,
allocatable :: Array_CK(:)
26 real(RK) ,
allocatable :: Array_RK(:)
29 Array_SK
= [
"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC" ]
30 Array_LK
= [
.false.,
.false.,
.true.,
.false.,
.false.,
.false.,
.true.,
.false. ]
31 Array_IK
= [
1,
1,
2,
3,
3,
3,
4,
3 ]
32 Array_CK
= [
1,
1,
2,
3,
3,
3,
4,
3 ]
33 Array_RK
= [
1,
1,
2,
3,
3,
3,
4,
3 ]
36 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
37 call disp%show(
"!Condense a 1D array.")
38 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
43 call disp%show( string , deliml
= SK_
"""" )
46 call disp%show(
"call setCompact(string, Weight, newsize)")
49 call disp%show( string(
1:newsize) , deliml
= SK_
"""" )
52 call disp%show(
"getVerbose(string(1:newsize), Weight(1:newsize), sum(Weight(1:newsize)))")
53 call disp%show(
getVerbose(string(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize))) , deliml
= SK_
"""" )
57 call disp%show( Array_SK , deliml
= SK_
"""" )
60 call disp%show(
"call setCompact(Array_SK, Weight, newsize)")
62 call disp%show(
"Array_SK(1:newsize)")
63 call disp%show( Array_SK(
1:newsize) , deliml
= SK_
"""" )
66 call disp%show(
"getVerbose(Array_SK(1:newsize), Weight(1:newsize), sum(Weight(1:newsize)))")
67 call disp%show(
getVerbose(Array_SK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize))) , deliml
= SK_
"""" )
74 call disp%show(
"call setCompact(Array_IK, Weight, newsize)")
76 call disp%show(
"Array_IK(1:newsize)")
77 call disp%show( Array_IK(
1:newsize) )
80 call disp%show(
"getVerbose(Array_IK(1:newsize), Weight(1:newsize), sum(Weight(1:newsize)))")
81 call disp%show(
getVerbose(Array_IK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize))) )
88 call disp%show(
"call setCompact(Array_LK, Weight, newsize)")
90 call disp%show(
"Array_LK(1:newsize)")
91 call disp%show( Array_LK(
1:newsize) )
94 call disp%show(
"getVerbose(Array_LK(1:newsize), Weight(1:newsize), sum(Weight(1:newsize)))")
95 call disp%show(
getVerbose(Array_LK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize))) )
102 call disp%show(
"call setCompact(Array_CK, Weight, newsize)")
104 call disp%show(
"Array_CK(1:newsize)")
105 call disp%show( Array_CK(
1:newsize) )
108 call disp%show(
"getVerbose(Array_CK(1:newsize), Weight(1:newsize), sum(Weight(1:newsize)))")
109 call disp%show(
getVerbose(Array_CK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize))) )
116 call disp%show(
"call setCompact(Array_RK, Weight, newsize)")
118 call disp%show(
"Array_RK(1:newsize)")
119 call disp%show( Array_RK(
1:newsize) )
122 call disp%show(
"getVerbose(Array_RK(1:newsize), Weight(1:newsize), sum(Weight(1:newsize)))")
123 call disp%show(
getVerbose(Array_RK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize))) )
131 character(
2, SK),
allocatable :: Array_SK(:,:)
132 integer(IK) ,
allocatable :: Array_IK(:,:)
133 logical(LK) ,
allocatable :: Array_LK(:,:)
134 complex(CK) ,
allocatable :: Array_CK(:,:)
135 real(RK) ,
allocatable :: Array_RK(:,:)
137 Array_SK
= transpose(
reshape([
"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC",
"EE",
"EE",
"FF",
"GG",
"GG",
"GG",
"HH",
"GG" ], shape
= [NP, ND]))
138 Array_LK
= transpose(
reshape([
.false.,
.false.,
.true.,
.false.,
.false.,
.false.,
.true.,
.false.,
.true.,
.true.,
.false.,
.true.,
.true.,
.true.,
.false.,
.true. ], shape
= [NP, ND]))
139 Array_IK
= transpose(
reshape([
1,
1,
2,
3,
3,
3,
4,
3,
5,
5,
6,
7,
7,
7,
8,
7 ], shape
= [NP, ND]))
140 Array_CK
= transpose(
reshape([
1,
1,
2,
3,
3,
3,
4,
3,
5,
5,
6,
7,
7,
7,
8,
7 ], shape
= [NP, ND]))
141 Array_RK
= transpose(
reshape([
1,
1,
2,
3,
3,
3,
4,
3,
5,
5,
6,
7,
7,
7,
8,
7 ], shape
= [NP, ND]))
144 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
145 call disp%show(
"!Condense a 2D array along the desired axis `dim`.")
146 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
151 call disp%show( Array_SK , deliml
= SK_
"""" )
154 call disp%show(
"call setCompact(Array_SK, Weight, newsize, dim = 2_IK)")
155 call setCompact(Array_SK, Weight, newsize,
dim = 2_IK)
156 call disp%show(
"Array_SK(:,1:newsize)")
157 call disp%show( Array_SK(:,
1:newsize) , deliml
= SK_
"""" )
160 call disp%show(
"getVerbose(Array_SK(:,1:newsize), Weight(1:newsize), sum(Weight(1:newsize)), dim = 2_IK)")
161 call disp%show(
getVerbose(Array_SK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK) , deliml
= SK_
"""" )
168 call disp%show(
"call setCompact(Array_IK, Weight, newsize, dim = 2_IK)")
169 call setCompact(Array_IK, Weight, newsize,
dim = 2_IK)
170 call disp%show(
"Array_IK(:,1:newsize)")
171 call disp%show( Array_IK(:,
1:newsize) )
174 call disp%show(
"getVerbose(Array_IK(:,1:newsize), Weight(1:newsize), sum(Weight(1:newsize)), dim = 2_IK)")
175 call disp%show(
getVerbose(Array_IK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK) )
182 call disp%show(
"call setCompact(Array_LK, Weight, newsize, dim = 2_IK)")
183 call setCompact(Array_LK, Weight, newsize,
dim = 2_IK)
184 call disp%show(
"Array_LK(:,1:newsize)")
185 call disp%show( Array_LK(:,
1:newsize) )
188 call disp%show(
"getVerbose(Array_LK(:,1:newsize), Weight(1:newsize), sum(Weight(1:newsize)), dim = 2_IK)")
189 call disp%show(
getVerbose(Array_LK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK) )
196 call disp%show(
"call setCompact(Array_CK, Weight, newsize, dim = 2_IK)")
197 call setCompact(Array_CK, Weight, newsize,
dim = 2_IK)
198 call disp%show(
"Array_CK(:,1:newsize)")
199 call disp%show( Array_CK(:,
1:newsize) )
202 call disp%show(
"getVerbose(Array_CK(:,1:newsize), Weight(1:newsize), sum(Weight(1:newsize)), dim = 2_IK)")
203 call disp%show(
getVerbose(Array_CK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK) )
210 call disp%show(
"call setCompact(Array_RK, Weight, newsize, dim = 2_IK)")
211 call setCompact(Array_RK, Weight, newsize,
dim = 2_IK)
212 call disp%show(
"Array_RK(:,1:newsize)")
213 call disp%show( Array_RK(:,
1:newsize) )
216 call disp%show(
"getVerbose(Array_RK(:,1:newsize), Weight(1:newsize), sum(Weight(1:newsize)), dim = 2_IK)")
217 call disp%show(
getVerbose(Array_RK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK) )
Generate an equally-weighted (verbose or flattened) array of the input weighted array of rank 1 or 2.
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
This module contains procedures and generic interfaces for flattening (duplicating the elements of) a...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
16getVerbose(string(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)))
20"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC"
25"AA",
"BB",
"CC",
"DD",
"CC"
28getVerbose(Array_SK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)))
29"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC"
32+1,
+1,
+2,
+3,
+3,
+3,
+4,
+3
40getVerbose(Array_IK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)))
41+1,
+1,
+2,
+3,
+3,
+3,
+4,
+3
52getVerbose(Array_LK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)))
56(
+1.0000000000000000,
+0.0000000000000000), (
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
61(
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
64getVerbose(Array_CK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)))
65(
+1.0000000000000000,
+0.0000000000000000), (
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
68+1.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
73+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
76getVerbose(Array_RK(
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)))
77+1.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
85"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC"
86"EE",
"EE",
"FF",
"GG",
"GG",
"GG",
"HH",
"GG"
89call setCompact(Array_SK, Weight, newsize,
dim = 2_IK)
91"AA",
"BB",
"CC",
"DD",
"CC"
92"EE",
"FF",
"GG",
"HH",
"GG"
95getVerbose(Array_SK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK)
96"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC"
97"EE",
"EE",
"FF",
"GG",
"GG",
"GG",
"HH",
"GG"
100+1,
+1,
+2,
+3,
+3,
+3,
+4,
+3
101+5,
+5,
+6,
+7,
+7,
+7,
+8,
+7
104call setCompact(Array_IK, Weight, newsize,
dim = 2_IK)
110getVerbose(Array_IK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK)
111+1,
+1,
+2,
+3,
+3,
+3,
+4,
+3
112+5,
+5,
+6,
+7,
+7,
+7,
+8,
+7
115F, F, T, F, F, F, T, F
116T, T, F, T, T, T, F, T
119call setCompact(Array_LK, Weight, newsize,
dim = 2_IK)
125getVerbose(Array_LK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK)
126F, F, T, F, F, F, T, F
127T, T, F, T, T, T, F, T
130(
+1.0000000000000000,
+0.0000000000000000), (
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
131(
+5.0000000000000000,
+0.0000000000000000), (
+5.0000000000000000,
+0.0000000000000000), (
+6.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+8.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000)
134call setCompact(Array_CK, Weight, newsize,
dim = 2_IK)
136(
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
137(
+5.0000000000000000,
+0.0000000000000000), (
+6.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+8.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000)
140getVerbose(Array_CK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK)
141(
+1.0000000000000000,
+0.0000000000000000), (
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
142(
+5.0000000000000000,
+0.0000000000000000), (
+5.0000000000000000,
+0.0000000000000000), (
+6.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000), (
+8.0000000000000000,
+0.0000000000000000), (
+7.0000000000000000,
+0.0000000000000000)
145+1.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
146+5.0000000000000000,
+5.0000000000000000,
+6.0000000000000000,
+7.0000000000000000,
+7.0000000000000000,
+7.0000000000000000,
+8.0000000000000000,
+7.0000000000000000
149call setCompact(Array_RK, Weight, newsize,
dim = 2_IK)
151+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
152+5.0000000000000000,
+6.0000000000000000,
+7.0000000000000000,
+8.0000000000000000,
+7.0000000000000000
155getVerbose(Array_RK(:,
1:newsize), Weight(
1:newsize),
sum(Weight(
1:newsize)),
dim = 2_IK)
156+1.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
157+5.0000000000000000,
+5.0000000000000000,
+6.0000000000000000,
+7.0000000000000000,
+7.0000000000000000,
+7.0000000000000000,
+8.0000000000000000,
+7.0000000000000000
- Test:
- test_pm_arrayCompact
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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, Saturday 1:48 AM, August 20, 2016, Institute for Computational Engineering and Sciences, UT Austin, TX
Definition at line 865 of file pm_arrayCompact.F90.