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)
verbose(:)
= getVerbose(array(
1:
size(array)), weight(
1:
size(array)), weisum)
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)
!
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 ⛓
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
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(:)
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 ]
34 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%")
35 call disp%show(
"!Flatten weighted 1D array.")
36 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%")
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_
"""" )
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_
"""" )
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)) )
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)) )
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)) )
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)) )
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(:,:)
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]))
106 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
107 call disp%show(
"!Flatten weighted 2D array along the desired axis `dim`.")
108 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
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_
"""" )
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) )
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) )
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) )
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) )
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 ⛓
11getVerbose(WeightedString, Weight,
sum(Weight, mask
= Weight
> 0_IK))
18getVerbose(WeightedArray_SK, Weight,
sum(Weight, mask
= Weight
> 0_IK))
25getVerbose(WeightedArray_IK, Weight,
sum(Weight, mask
= Weight
> 0_IK))
32getVerbose(WeightedArray_LK, Weight,
sum(Weight, mask
= Weight
> 0_IK))
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)
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
59getVerbose(WeightedArray_SK, Weight,
sum(Weight, mask
= Weight
> 0_IK),
dim = 2_IK)
68getVerbose(WeightedArray_IK, Weight,
sum(Weight, mask
= Weight
> 0_IK),
dim = 2_IK)
77getVerbose(WeightedArray_LK, Weight,
sum(Weight, mask
= Weight
> 0_IK),
dim = 2_IK)
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)
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
- 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.
-
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:30 AM, August 20, 2016, Institute for Computational Engineering and Sciences, UT Austin, TX
Definition at line 142 of file pm_arrayVerbose.F90.