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

Generate a compact 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. More...

Detailed Description

Generate a compact 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]array: The input contiguous array of shape (:) or (:,:) of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) or
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
  3. type logical of kind any supported by the processor (e.g., LK) or
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128)
or,
  1. scalar character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
containing the array that has to be compactified.
[in]dim: The input scalar of type integer of default kind IK representing the axis of array(:,:) along which array must be compactified.
(optional, it must be present if and only if array is of shape (:,:).)
Returns
compact : The output array of the same type, kind, and shape as the input array containing the compactified version of the input array.


Possible calling interfaces

compact = getCompact(array) ! scalar character objects.
compact(:) = getCompact(array(:)) ! all intrinsic array objects.
compact(:,:) = getCompact(array(:,:), dim) ! all intrinsic array objects.
!
Generate a compact version of the input array where all sequentially duplicate entries along the spec...
This module contains procedures and generic interfaces for condensing (removing duplicate sequential ...
Warning
The condition dim == 1 .or. dim == 2 must hold.
This condition is 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
setCompact
getVerbose


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, CK, RK ! all processor kinds are supported.
4 use pm_io, only: display_type
6
7 implicit none
8
9 integer(IK) , parameter :: ND = 2_IK, NP = 8_IK
10 type(display_type) :: disp
11
12 disp = display_type(file = "main.out.F90")
13
14 ! Condense 1D array.
15
16 block
17
18 character(:, SK), allocatable :: string
19 character(2, SK), allocatable :: Array_SK(:)
20 integer(IK) , allocatable :: Array_IK(:)
21 logical(LK) , allocatable :: Array_LK(:)
22 complex(CK) , allocatable :: Array_CK(:)
23 real(RK) , allocatable :: Array_RK(:)
24
25 string = "AABCCCDC"
26 Array_SK = [ "AA", "AA", "BB", "CC", "CC", "CC", "DD", "CC" ]
27 Array_LK = [ .false., .false., .true., .false., .false., .false., .true., .false. ]
28 Array_IK = [ 1, 1, 2, 3, 3, 3, 4, 3 ]
29 Array_CK = [ 1, 1, 2, 3, 3, 3, 4, 3 ]
30 Array_RK = [ 1, 1, 2, 3, 3, 3, 4, 3 ]
31
32 call disp%skip()
33 call disp%show("!%%%%%%%%%%%%%%%%%%%%")
34 call disp%show("!Condense a 1D array.")
35 call disp%show("!%%%%%%%%%%%%%%%%%%%%")
36 call disp%skip()
37
38 call disp%skip()
39 call disp%show("string")
40 call disp%show( string , deliml = SK_"""" )
41 call disp%show("getCompact(string)")
42 call disp%show( getCompact(string) , deliml = SK_"""" )
43
44 call disp%skip()
45 call disp%show("Array_SK")
46 call disp%show( Array_SK , deliml = SK_"""" )
47 call disp%show("getCompact(Array_SK)")
48 call disp%show( getCompact(Array_SK) , deliml = SK_"""" )
49
50 call disp%skip()
51 call disp%show("Array_IK")
52 call disp%show( Array_IK )
53 call disp%show("getCompact(Array_IK)")
54 call disp%show( getCompact(Array_IK) )
55
56 call disp%skip()
57 call disp%show("Array_LK")
58 call disp%show( Array_LK )
59 call disp%show("getCompact(Array_LK)")
60 call disp%show( getCompact(Array_LK) )
61
62 call disp%skip()
63 call disp%show("Array_CK")
64 call disp%show( Array_CK )
65 call disp%show("getCompact(Array_CK)")
66 call disp%show( getCompact(Array_CK) )
67
68 call disp%skip()
69 call disp%show("Array_RK")
70 call disp%show( Array_RK )
71 call disp%show("getCompact(Array_RK)")
72 call disp%show( getCompact(Array_RK) )
73
74 end block
75
76 ! Flatten 2D array.
77
78 block
79
80 character(2, SK), allocatable :: Array_SK(:,:)
81 integer(IK) , allocatable :: Array_IK(:,:)
82 logical(LK) , allocatable :: Array_LK(:,:)
83 complex(CK) , allocatable :: Array_CK(:,:)
84 real(RK) , allocatable :: Array_RK(:,:)
85
86 Array_SK = transpose(reshape([ "AA", "AA", "BB", "CC", "CC", "CC", "DD", "CC", "EE", "EE", "FF", "GG", "GG", "GG", "HH", "GG" ], shape = [NP, ND]))
87 Array_LK = transpose(reshape([ .false., .false., .true., .false., .false., .false., .true., .false., .true., .true., .false., .true., .true., .true., .false., .true. ], shape = [NP, ND]))
88 Array_IK = transpose(reshape([ 1, 1, 2, 3, 3, 3, 4, 3, 5, 5, 6, 7, 7, 7, 8, 7 ], shape = [NP, ND]))
89 Array_CK = transpose(reshape([ 1, 1, 2, 3, 3, 3, 4, 3, 5, 5, 6, 7, 7, 7, 8, 7 ], shape = [NP, ND]))
90 Array_RK = transpose(reshape([ 1, 1, 2, 3, 3, 3, 4, 3, 5, 5, 6, 7, 7, 7, 8, 7 ], shape = [NP, ND]))
91
92 call disp%skip()
93 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
94 call disp%show("!Condense a 2D array along the desired axis `dim`.")
95 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
96 call disp%skip()
97
98 call disp%skip()
99 call disp%show("Array_SK")
100 call disp%show( Array_SK , deliml = SK_"""" )
101 call disp%show("getCompact(Array_SK, dim = 2_IK)")
102 call disp%show( getCompact(Array_SK, dim = 2_IK) , deliml = SK_"""" )
103
104 call disp%skip()
105 call disp%show("Array_IK")
106 call disp%show( Array_IK )
107 call disp%show("getCompact(Array_IK, dim = 2_IK)")
108 call disp%show( getCompact(Array_IK, dim = 2_IK) )
109
110 call disp%skip()
111 call disp%show("Array_LK")
112 call disp%show( Array_LK )
113 call disp%show("getCompact(Array_LK, dim = 2_IK)")
114 call disp%show( getCompact(Array_LK, dim = 2_IK) )
115
116 call disp%skip()
117 call disp%show("Array_CK")
118 call disp%show( Array_CK )
119 call disp%show("getCompact(Array_CK, dim = 2_IK)")
120 call disp%show( getCompact(Array_CK, dim = 2_IK) )
121
122 call disp%skip()
123 call disp%show("Array_RK")
124 call disp%show( Array_RK )
125 call disp%show("getCompact(Array_RK, dim = 2_IK)")
126 call disp%show( getCompact(Array_RK, dim = 2_IK) )
127
128 end block
129
130end 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
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 defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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
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!Condense a 1D array.
4!%%%%%%%%%%%%%%%%%%%%
5
6
7string
8"AABCCCDC"
9getCompact(string)
10"ABCDC"
11
12Array_SK
13"AA", "AA", "BB", "CC", "CC", "CC", "DD", "CC"
14getCompact(Array_SK)
15"AA", "BB", "CC", "DD", "CC"
16
17Array_IK
18+1, +1, +2, +3, +3, +3, +4, +3
19getCompact(Array_IK)
20+1, +2, +3, +4, +3
21
22Array_LK
23F, F, T, F, F, F, T, F
24getCompact(Array_LK)
25F, T, F, T, F
26
27Array_CK
28(+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)
29getCompact(Array_CK)
30(+1.0000000000000000, +0.0000000000000000), (+2.0000000000000000, +0.0000000000000000), (+3.0000000000000000, +0.0000000000000000), (+4.0000000000000000, +0.0000000000000000), (+3.0000000000000000, +0.0000000000000000)
31
32Array_RK
33+1.0000000000000000, +1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +3.0000000000000000, +3.0000000000000000, +4.0000000000000000, +3.0000000000000000
34getCompact(Array_RK)
35+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +3.0000000000000000
36
37!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38!Condense a 2D array along the desired axis `dim`.
39!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41
42Array_SK
43"AA", "AA", "BB", "CC", "CC", "CC", "DD", "CC"
44"EE", "EE", "FF", "GG", "GG", "GG", "HH", "GG"
45getCompact(Array_SK, dim = 2_IK)
46"AA", "BB", "CC", "DD", "CC"
47"EE", "FF", "GG", "HH", "GG"
48
49Array_IK
50+1, +1, +2, +3, +3, +3, +4, +3
51+5, +5, +6, +7, +7, +7, +8, +7
52getCompact(Array_IK, dim = 2_IK)
53+1, +2, +3, +4, +3
54+5, +6, +7, +8, +7
55
56Array_LK
57F, F, T, F, F, F, T, F
58T, T, F, T, T, T, F, T
59getCompact(Array_LK, dim = 2_IK)
60F, T, F, T, F
61T, F, T, F, T
62
63Array_CK
64(+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)
65(+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)
66getCompact(Array_CK, dim = 2_IK)
67(+1.0000000000000000, +0.0000000000000000), (+2.0000000000000000, +0.0000000000000000), (+3.0000000000000000, +0.0000000000000000), (+4.0000000000000000, +0.0000000000000000), (+3.0000000000000000, +0.0000000000000000)
68(+5.0000000000000000, +0.0000000000000000), (+6.0000000000000000, +0.0000000000000000), (+7.0000000000000000, +0.0000000000000000), (+8.0000000000000000, +0.0000000000000000), (+7.0000000000000000, +0.0000000000000000)
69
70Array_RK
71+1.0000000000000000, +1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +3.0000000000000000, +3.0000000000000000, +4.0000000000000000, +3.0000000000000000
72+5.0000000000000000, +5.0000000000000000, +6.0000000000000000, +7.0000000000000000, +7.0000000000000000, +7.0000000000000000, +8.0000000000000000, +7.0000000000000000
73getCompact(Array_RK, dim = 2_IK)
74+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +3.0000000000000000
75+5.0000000000000000, +6.0000000000000000, +7.0000000000000000, +8.0000000000000000, +7.0000000000000000
76
Test:
test_pm_arrayCompact
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:
Amir Shahmoradi, Saturday 1:48 AM, August 20, 2016, Institute for Computational Engineering and Sciences, UT Austin, TX

Definition at line 122 of file pm_arrayCompact.F90.


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