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
-
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),
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 ⛓
!
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 ⛓
9 integer(IK) ,
parameter :: ND
= 2_IK, NP
= 8_IK
10 type(display_type) :: disp
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(:)
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 ]
33 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
34 call disp%show(
"!Condense a 1D array.")
35 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
40 call disp%show( string , deliml
= SK_
"""" )
46 call disp%show( Array_SK , deliml
= SK_
"""" )
47 call disp%show(
"getCompact(Array_SK)")
53 call disp%show(
"getCompact(Array_IK)")
59 call disp%show(
"getCompact(Array_LK)")
65 call disp%show(
"getCompact(Array_CK)")
71 call disp%show(
"getCompact(Array_RK)")
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(:,:)
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]))
93 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
94 call disp%show(
"!Condense a 2D array along the desired axis `dim`.")
95 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
100 call disp%show( Array_SK , deliml
= SK_
"""" )
101 call disp%show(
"getCompact(Array_SK, dim = 2_IK)")
107 call disp%show(
"getCompact(Array_IK, dim = 2_IK)")
113 call disp%show(
"getCompact(Array_LK, dim = 2_IK)")
119 call disp%show(
"getCompact(Array_CK, dim = 2_IK)")
125 call disp%show(
"getCompact(Array_RK, dim = 2_IK)")
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 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 ⛓
13"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC"
15"AA",
"BB",
"CC",
"DD",
"CC"
18+1,
+1,
+2,
+3,
+3,
+3,
+4,
+3
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)
30(
+1.0000000000000000,
+0.0000000000000000), (
+2.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000), (
+4.0000000000000000,
+0.0000000000000000), (
+3.0000000000000000,
+0.0000000000000000)
33+1.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
35+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
43"AA",
"AA",
"BB",
"CC",
"CC",
"CC",
"DD",
"CC"
44"EE",
"EE",
"FF",
"GG",
"GG",
"GG",
"HH",
"GG"
46"AA",
"BB",
"CC",
"DD",
"CC"
47"EE",
"FF",
"GG",
"HH",
"GG"
50+1,
+1,
+2,
+3,
+3,
+3,
+4,
+3
51+5,
+5,
+6,
+7,
+7,
+7,
+8,
+7
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)
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)
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
74+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+3.0000000000000000
75+5.0000000000000000,
+6.0000000000000000,
+7.0000000000000000,
+8.0000000000000000,
+7.0000000000000000
- 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.
-
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 122 of file pm_arrayCompact.F90.