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

Generate an equally-weighted (verbose or flattened) array of the input weighted array of rank 1 or 2. More...

Detailed Description

Generate an equally-weighted (verbose or flattened) array of the input weighted array of rank 1 or 2.

The output object contains elements of the input array duplicated as many times as indicated by the corresponding element of weight.

Parameters
[in]array: The input contiguous array of shape (1:nsam) or (1:ndim, 1:nsam) 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,
  • a scalar character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
containing the weighted elements to be flattened.
[in]weight: The input contiguous array of shape (1:nsam) of type integer of default kind IK of the same size as size(array, dim), i.e., along the axis array must be flattened.
It contains the weights of elements of array.
The values of the elements of weight are allowed to be negative or zero, in which case, the corresponding elements will be excluded from the output verbose.
[in]weisum: The input scalar of type integer of default kind IK representing the sum of all non-negative elements of weight.
The value of weisum can be readily obtained via sum(weight, mask = weight > 0).
[in]dim: The input scalar of type integer of default kind IK representing the axis of array(:,:) along which array must be flattened.
(optional, it must be present if and only if array is of shape (:,:). If present, size(weight) == size(array, dim) must hold.)
Returns
verbose : The output array of the same type, kind, and shape as the input array containing the flattened version of the input array.
  • If array is of rank 2, then the condition size(verbose, dim) == weisum .and. size(verbose, 3 - dim) == size(array, 3 - dim) holds.
  • If array is of rank 1, then the condition size(verbose) == weisum holds.


Possible calling interfaces

verbose = getVerbose(array, weight(1:len(array)), weisum) ! scalar character objects.
verbose(:) = getVerbose(array(1:size(array)), weight(1:size(array)), weisum) ! all intrinsic array objects.
verbose(1 : merge(weisum, size(array, 3 - dim), dim == 1), 1 : merge(weisum, size(array, 3 - dim), dim == 2)) = getVerbose(array(:,:), weight(1:size(array,dim)), weisum, dim) ! all intrinsic array objects.
!
Generate an equally-weighted (verbose or flattened) array of the input weighted array of rank 1 or 2.
This module contains procedures and generic interfaces for flattening (duplicating the elements of) a...
Warning
The condition size(weight) == size(array, dim) must hold for the input arguments array and weight.
The condition weisum == sum(weight, mask = weight > 0) must hold for the input arguments weight and weisum.
The condition dim == 1 .or. dim == 2 must hold.
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
setCompact


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 = 4_IK
10 integer(IK) :: Weight(NP) = [-1_IK, 2_IK, 0_IK, 1_IK]
11 type(display_type) :: disp
12
13 disp = display_type(file = "main.out.F90")
14
15 ! Flatten 1D array.
16
17 block
18
19 character(:, SK), allocatable :: WeightedString
20 character(2, SK), allocatable :: WeightedArray_SK(:)
21 integer(IK) , allocatable :: WeightedArray_IK(:)
22 logical(LK) , allocatable :: WeightedArray_LK(:)
23 complex(CK) , allocatable :: WeightedArray_CK(:)
24 real(RK) , allocatable :: WeightedArray_RK(:)
25
26 WeightedString = "ABCD"
27 WeightedArray_SK = [ "AA", "BB", "CC", "DD" ]
28 WeightedArray_IK = [ 1, 2, 3, 4 ]
29 WeightedArray_LK = [ .false., .true., .false., .true. ]
30 WeightedArray_CK = [ 1, 2, 3, 4 ]
31 WeightedArray_RK = [ 1, 2, 3, 4 ]
32
33 call disp%skip()
34 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%")
35 call disp%show("!Flatten weighted 1D array.")
36 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%")
37 call disp%skip()
38
39 call disp%skip()
40 call disp%show("Weight")
41 call disp%show( Weight )
42 call disp%show("WeightedString")
43 call disp%show( WeightedString , deliml = SK_"""" )
44 call disp%show("getVerbose(WeightedString, Weight, sum(Weight, mask = Weight > 0_IK))")
45 call disp%show( getVerbose(WeightedString, Weight, sum(Weight, mask = Weight > 0_IK)) , deliml = SK_"""" )
46
47 call disp%skip()
48 call disp%show("Weight")
49 call disp%show( Weight )
50 call disp%show("WeightedArray_SK")
51 call disp%show( WeightedArray_SK , deliml = SK_"""" )
52 call disp%show("getVerbose(WeightedArray_SK, Weight, sum(Weight, mask = Weight > 0_IK))")
53 call disp%show( getVerbose(WeightedArray_SK, Weight, sum(Weight, mask = Weight > 0_IK)) , deliml = SK_"""" )
54
55 call disp%skip()
56 call disp%show("Weight")
57 call disp%show( Weight )
58 call disp%show("WeightedArray_IK")
59 call disp%show( WeightedArray_IK )
60 call disp%show("getVerbose(WeightedArray_IK, Weight, sum(Weight, mask = Weight > 0_IK))")
61 call disp%show( getVerbose(WeightedArray_IK, Weight, sum(Weight, mask = Weight > 0_IK)) )
62
63 call disp%skip()
64 call disp%show("Weight")
65 call disp%show( Weight )
66 call disp%show("WeightedArray_LK")
67 call disp%show( WeightedArray_LK )
68 call disp%show("getVerbose(WeightedArray_LK, Weight, sum(Weight, mask = Weight > 0_IK))")
69 call disp%show( getVerbose(WeightedArray_LK, Weight, sum(Weight, mask = Weight > 0_IK)) )
70
71 call disp%skip()
72 call disp%show("Weight")
73 call disp%show( Weight )
74 call disp%show("WeightedArray_CK")
75 call disp%show( WeightedArray_CK )
76 call disp%show("getVerbose(WeightedArray_CK, Weight, sum(Weight, mask = Weight > 0_IK))")
77 call disp%show( getVerbose(WeightedArray_CK, Weight, sum(Weight, mask = Weight > 0_IK)) )
78
79 call disp%skip()
80 call disp%show("Weight")
81 call disp%show( Weight )
82 call disp%show("WeightedArray_RK")
83 call disp%show( WeightedArray_RK )
84 call disp%show("getVerbose(WeightedArray_RK, Weight, sum(Weight, mask = Weight > 0_IK))")
85 call disp%show( getVerbose(WeightedArray_RK, Weight, sum(Weight, mask = Weight > 0_IK)) )
86
87 end block
88
89 ! Flatten 2D array.
90
91 block
92
93 character(2, SK), allocatable :: WeightedArray_SK(:,:)
94 integer(IK) , allocatable :: WeightedArray_IK(:,:)
95 logical(LK) , allocatable :: WeightedArray_LK(:,:)
96 complex(CK) , allocatable :: WeightedArray_CK(:,:)
97 real(RK) , allocatable :: WeightedArray_RK(:,:)
98
99 WeightedArray_SK = transpose(reshape([ "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" ], shape = [NP, ND]))
100 WeightedArray_LK = transpose(reshape([ .false., .true., .false., .true., .false., .true., .false., .true. ], shape = [NP, ND]))
101 WeightedArray_IK = transpose(reshape([ 1, 2, 3, 4, 5, 6, 7, 8 ], shape = [NP, ND]))
102 WeightedArray_CK = transpose(reshape([ 1, 2, 3, 4, 5, 6, 7, 8 ], shape = [NP, ND]))
103 WeightedArray_RK = transpose(reshape([ 1, 2, 3, 4, 5, 6, 7, 8 ], shape = [NP, ND]))
104
105 call disp%skip()
106 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
107 call disp%show("!Flatten weighted 2D array along the desired axis `dim`.")
108 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
109 call disp%skip()
110
111 call disp%skip()
112 call disp%show("Weight")
113 call disp%show( Weight )
114 call disp%show("WeightedArray_SK")
115 call disp%show( WeightedArray_SK , deliml = SK_"""" )
116 call disp%show("getVerbose(WeightedArray_SK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)")
117 call disp%show( getVerbose(WeightedArray_SK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK) , deliml = SK_"""" )
118
119 call disp%skip()
120 call disp%show("Weight")
121 call disp%show( Weight )
122 call disp%show("WeightedArray_IK")
123 call disp%show( WeightedArray_IK )
124 call disp%show("getVerbose(WeightedArray_IK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)")
125 call disp%show( getVerbose(WeightedArray_IK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK) )
126
127 call disp%skip()
128 call disp%show("Weight")
129 call disp%show( Weight )
130 call disp%show("WeightedArray_LK")
131 call disp%show( WeightedArray_LK )
132 call disp%show("getVerbose(WeightedArray_LK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)")
133 call disp%show( getVerbose(WeightedArray_LK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK) )
134
135 call disp%skip()
136 call disp%show("Weight")
137 call disp%show( Weight )
138 call disp%show("WeightedArray_CK")
139 call disp%show( WeightedArray_CK )
140 call disp%show("getVerbose(WeightedArray_CK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)")
141 call disp%show( getVerbose(WeightedArray_CK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK) )
142
143 call disp%skip()
144 call disp%show("Weight")
145 call disp%show( Weight )
146 call disp%show("WeightedArray_RK")
147 call disp%show( WeightedArray_RK )
148 call disp%show("getVerbose(WeightedArray_RK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)")
149 call disp%show( getVerbose(WeightedArray_RK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK) )
150
151 end block
152
153end 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!Flatten weighted 1D array.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7Weight
8-1, +2, +0, +1
9WeightedString
10"ABCD"
11getVerbose(WeightedString, Weight, sum(Weight, mask = Weight > 0_IK))
12"BBD"
13
14Weight
15-1, +2, +0, +1
16WeightedArray_SK
17"AA", "BB", "CC", "DD"
18getVerbose(WeightedArray_SK, Weight, sum(Weight, mask = Weight > 0_IK))
19"BB", "BB", "DD"
20
21Weight
22-1, +2, +0, +1
23WeightedArray_IK
24+1, +2, +3, +4
25getVerbose(WeightedArray_IK, Weight, sum(Weight, mask = Weight > 0_IK))
26+2, +2, +4
27
28Weight
29-1, +2, +0, +1
30WeightedArray_LK
31F, T, F, T
32getVerbose(WeightedArray_LK, Weight, sum(Weight, mask = Weight > 0_IK))
33T, T, T
34
35Weight
36-1, +2, +0, +1
37WeightedArray_CK
38(+1.0000000000000000, +0.0000000000000000), (+2.0000000000000000, +0.0000000000000000), (+3.0000000000000000, +0.0000000000000000), (+4.0000000000000000, +0.0000000000000000)
39getVerbose(WeightedArray_CK, Weight, sum(Weight, mask = Weight > 0_IK))
40(+2.0000000000000000, +0.0000000000000000), (+2.0000000000000000, +0.0000000000000000), (+4.0000000000000000, +0.0000000000000000)
41
42Weight
43-1, +2, +0, +1
44WeightedArray_RK
45+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000
46getVerbose(WeightedArray_RK, Weight, sum(Weight, mask = Weight > 0_IK))
47+2.0000000000000000, +2.0000000000000000, +4.0000000000000000
48
49!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50!Flatten weighted 2D array along the desired axis `dim`.
51!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
53
54Weight
55-1, +2, +0, +1
56WeightedArray_SK
57"AA", "BB", "CC", "DD"
58"EE", "FF", "GG", "HH"
59getVerbose(WeightedArray_SK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)
60"BB", "BB", "DD"
61"FF", "FF", "HH"
62
63Weight
64-1, +2, +0, +1
65WeightedArray_IK
66+1, +2, +3, +4
67+5, +6, +7, +8
68getVerbose(WeightedArray_IK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)
69+2, +2, +4
70+6, +6, +8
71
72Weight
73-1, +2, +0, +1
74WeightedArray_LK
75F, T, F, T
76F, T, F, T
77getVerbose(WeightedArray_LK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)
78T, T, T
79T, T, T
80
81Weight
82-1, +2, +0, +1
83WeightedArray_CK
84(+1.0000000000000000, +0.0000000000000000), (+2.0000000000000000, +0.0000000000000000), (+3.0000000000000000, +0.0000000000000000), (+4.0000000000000000, +0.0000000000000000)
85(+5.0000000000000000, +0.0000000000000000), (+6.0000000000000000, +0.0000000000000000), (+7.0000000000000000, +0.0000000000000000), (+8.0000000000000000, +0.0000000000000000)
86getVerbose(WeightedArray_CK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)
87(+2.0000000000000000, +0.0000000000000000), (+2.0000000000000000, +0.0000000000000000), (+4.0000000000000000, +0.0000000000000000)
88(+6.0000000000000000, +0.0000000000000000), (+6.0000000000000000, +0.0000000000000000), (+8.0000000000000000, +0.0000000000000000)
89
90Weight
91-1, +2, +0, +1
92WeightedArray_RK
93+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000
94+5.0000000000000000, +6.0000000000000000, +7.0000000000000000, +8.0000000000000000
95getVerbose(WeightedArray_RK, Weight, sum(Weight, mask = Weight > 0_IK), dim = 2_IK)
96+2.0000000000000000, +2.0000000000000000, +4.0000000000000000
97+6.0000000000000000, +6.0000000000000000, +8.0000000000000000
98
Test:
test_pm_arrayVerbose
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version 2021.2.0, GNU Fortran Compiler gfortran version 10-11
Description: See the bug described in getUnique.

Remedy (as of ParaMonte Library version 2.0.0): See the bug described in getUnique.


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:30 AM, August 20, 2016, Institute for Computational Engineering and Sciences, UT Austin, TX

Definition at line 142 of file pm_arrayVerbose.F90.


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