Generate and return an arrayNew
of the same type and kind as the input array
, in which the requested instances of the input pattern
have been replaced with the input replacement
.
If an input vector of instance
is specified, representing the specific instances of pattern to change, then only those specific instances will be changed.
- Parameters
-
[in] | array | : The input contiguous array of rank 1 of either
-
type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
-
type
logical of kind any supported by the processor (e.g., LK), or
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), 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),
within which the specific instances of the input pattern must be replaced.
|
[in] | pattern | : The input contiguous array of rank 1 of the same type and kind as the input array , containing the pattern whose instances will have to be replaced in the input array .
|
[in] | replacement | : The input contiguous array of rank 1 of the same type and kind as the input array , containing the replacement that will replace in the instances of pattern in the input array .
|
| iseq | : The external user-specified function that takes either two input assumed-length character arguments (if the input array is also an assumed-length character ) or two array-valued explicit-shape arguments of the same type and kind as the input array .
It must return a scalar of type logical of default kind LK that is .true. if all elements of the two input arguments are equivalent (e.g., equal) according to the user-defined criterion, otherwise, it is .false. .
The the input array is array-valued, then the last argument to iseq is the length of the input pattern .
The following illustrates the generic interface of iseq where pattern is array-valued,
function iseq(segment, pattern, lenPattern) result(equivalent)
integer(IK) , intent(in) :: lenPattern
TYPE(KIND) , intent(in) :: segment(lenPattern), pattern(lenPattern)
logical(LK) :: equivalent
end function
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
where TYPE(KIND) represents the type and kind of the input argument array , which can be one of the following, character(*, SK), intent(in) :: segment(lenPattern), pattern(lenPattern)
integer(IK) , intent(in) :: segment(lenPattern), pattern(lenPattern)
logical(LK) , intent(in) :: segment(lenPattern), pattern(lenPattern)
complex(CK) , intent(in) :: segment(lenPattern), pattern(lenPattern)
real(RK) , intent(in) :: segment(lenPattern), pattern(lenPattern)
where the kinds SKG , IKG , LKG , CKG , RK , can refer to any kind type parameter that is supported by the processor.
The following illustrates the generic interface of iseq where pattern is scalar-valued (including Fortran scalar strings),
function iseq(segment, pattern) result(equivalent)
TYPE(KIND) , intent(in) :: segment, pattern
logical(LK) :: equivalent
end function
where TYPE(KIND) represents the type and kind of the input argument array , which can be one of the following,
character(*, SK), intent(in) :: segment, pattern
integer(IK) , intent(in) :: segment, pattern
logical(LK) , intent(in) :: segment, pattern
complex(CK) , intent(in) :: segment, pattern
real(RK) , intent(in) :: segment, pattern
integer, parameter RK The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter CK The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
integer, parameter SK The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
where the kinds SK , IK , LK , CK , RK , can refer to any kind type parameter that is supported by the processor.
This user-defined equivalence check is extremely useful where an equivalence test other than exact identity is needed, for example, when the array segments should match the input pattern only within a given threshold or, when the case-sensitivity in character comparisons do not matter.
In such cases, user can define a custom equivalence criterion within the user-defined external function iseq to achieve the goal.
(optional, the default equivalence operator is .eqv. if the input array is logical , otherwise == ) |
[in] | instance | : The input contiguous array of rank 1 of type integer of default kind IK, containing the instances of the input pattern in the input array that should be replaced with the input replacement .
Any element of instance that points to an out-of-scope instance of pattern in the input array will be ignored.
Any element of instance that is negatively valued will be counted from end of the input array .
For example, instance = [2,-1] requests replacing the second instance of pattern in array from the beginning and replacing the first instance of pattern starting from the end of array .
(optional, the default value corresponds to replacing all instances of pattern with replacement in array ) |
[in] | sorted | : The input logical of default kind LK indicating whether the elements of the specified input instance are all in ascending-order.
This includes the negative elements of instance after they are translated to the corresponding positive instances from the beginning of the input array .
Setting sorted = .true. will lead to faster runtime of the procedure.
However, the onus will be strictly on the user to ensure all elements of instance are in ascending-order.
This is generally not an easy guarantee to make if there are negative elements in instance .
Therefore, set sorted = .true. only if you can guarantee the validity of the condition.
(optional, default = .false. . It can be present as input argument only if the input argument instance is present.) |
[in] | unique | : The input logical of default kind LK indicating whether the elements of the specified input instance are all unique.
This includes the negative elements of instance after they are translated to the corresponding positive instances from the beginning of the input array .
Setting unique = .true. will lead to faster runtime of the procedure.
However, the onus will be strictly on the user to ensure all elements of instance are unique.
This is generally not an easy guarantee to make if there are negative elements in instance .
Therefore, set unique = .true. only if you can guarantee the validity of the condition.
(optional, default = .false. . It can be present as input argument only if the input argument instance is present.) |
- Returns
arrayNew
: The output allocatable
array of the same type and kind as the input array
in which all requested instances of the input pattern
have been replaced with the input replacement
.
Possible calling interfaces ⛓
arrayNew
= getReplaced(array, pattern, replacement, iseq)
arrayNew
= getReplaced(array, pattern, replacement, instance, sorted
= sorted, unique
= unique)
arrayNew
= getReplaced(array, pattern, replacement, iseq, instance, sorted
= sorted, unique
= unique)
Generate and return an arrayNew of the same type and kind as the input array, in which the requested ...
This module contains procedures and generic interfaces for replacing patterns within arrays of variou...
- Warning
- 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.
-
The procedures under this generic interface are
impure
when the user-specified external
procedure iseq
is specified as input argument.
-
Note that in Fortran, trailing blanks are ignored in character comparison, that is,
"Fortran" == "Fortran "
yields .true.
.
- See also
- setReplaced
setInserted
setRemoved
setSplit
Example usage ⛓
13 integer(IK) ,
allocatable :: instance(:)
14 character(:, SK),
allocatable :: string_SK , stringPattern_SK , stringReplacement_SK
15 character(
9, SK),
allocatable :: Array_SK(:) , ArrayPattern_SK(:), ArrayReplacement_SK(:)
16 integer(IK) ,
allocatable :: Array_IK(:) , ArrayPattern_IK(:), ArrayReplacement_IK(:)
17 complex(CK) ,
allocatable :: Array_CK(:) , ArrayPattern_CK(:), ArrayReplacement_CK(:)
18 real(RK) ,
allocatable :: Array_RK(:) , ArrayPattern_RK(:), ArrayReplacement_RK(:)
19 logical(LK) ,
allocatable :: Array_LK(:) , ArrayPattern_LK(:), ArrayReplacement_LK(:)
21 type(display_type) :: disp
26 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
28 call disp%show(
"! Replace all instances of pattern in array.")
29 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
33 string_SK
= "ParaMonte is a Monte Carlo Library."
34 Array_SK
= [
"ParaMonte",
"is ",
"a ",
"Monte ",
"Carlo ",
"Library. "]
35 Array_IK
= [
1_IK,
2_IK,
3_IK,
4_IK]
36 Array_RK
= [
1._RK,
2._RK,
3._RK,
4._RK]
37 Array_CK
= [(
1._CK,
-1._CK), (
2._CK,
-2._CK), (
3._CK,
-3._CK), (
4._CK,
-4._CK)]
38 Array_LK
= [
.false._LK,
.true._LK,
.true._LK,
.false._LK]
40 stringPattern_SK
= "a Monte Carlo"
41 ArrayPattern_SK
= [
"a ",
"Monte ",
"Carlo "]
42 ArrayPattern_IK
= [
3_IK]
43 ArrayPattern_RK
= [
3._RK]
44 ArrayPattern_CK
= [(
3._CK,
-3._CK)]
45 ArrayPattern_LK
= [
.true._LK,
.true._LK]
47 stringReplacement_SK
= "now a Machine Learning"
48 ArrayReplacement_SK
= [
"now ",
"a ",
"Machine ",
"Learning "]
49 ArrayReplacement_IK
= [
-1_IK,
0_IK,
1_IK]
50 ArrayReplacement_RK
= [
-1._RK,
0._RK,
1._RK]
51 ArrayReplacement_CK
= [(
-1._CK,
+1._CK), (
0._CK,
0._CK), (
+1._CK,
-1._CK)]
52 ArrayReplacement_LK
= [
.false._LK]
55 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%")
56 call disp%show(
"! Replace character scalar.")
57 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%")
61 call disp%show( string_SK, deliml
= SK_
"""" )
63 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
64 call disp%show(
"stringReplacement_SK")
65 call disp%show( stringReplacement_SK, deliml
= SK_
"""" )
66 call disp%show(
"getReplaced(string_SK, stringPattern_SK, stringReplacement_SK)")
67 call disp%show(
getReplaced(string_SK, stringPattern_SK, stringReplacement_SK), deliml
= SK_
"""" )
70 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
71 call disp%show(
"! Replace character array.")
72 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
76 call disp%show( Array_SK, deliml
= SK_
"""" )
78 call disp%show( ArrayPattern_SK, deliml
= SK_
"""" )
79 call disp%show(
"ArrayReplacement_SK")
80 call disp%show( ArrayReplacement_SK, deliml
= SK_
"""" )
81 call disp%show(
"getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK)")
82 call disp%show(
"getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK)")
85 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%")
86 call disp%show(
"! Replace logical array.")
87 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%")
94 call disp%show(
"ArrayReplacement_LK")
95 call disp%show( ArrayReplacement_LK )
96 call disp%show(
"getReplaced(Array_LK, ArrayPattern_LK, ArrayReplacement_LK)")
100 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%")
101 call disp%show(
"! Replace integer array.")
102 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%")
109 call disp%show(
"ArrayReplacement_IK")
110 call disp%show( ArrayReplacement_IK )
111 call disp%show(
"getReplaced(Array_IK, ArrayPattern_IK, ArrayReplacement_IK)")
115 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%")
116 call disp%show(
"! Replace complex array.")
117 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%")
124 call disp%show(
"ArrayReplacement_CK")
125 call disp%show( ArrayReplacement_CK )
126 call disp%show(
"getReplaced(Array_CK, ArrayPattern_CK, ArrayReplacement_CK)")
130 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
131 call disp%show(
"! Replace real array.")
132 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
139 call disp%show(
"ArrayReplacement_RK")
140 call disp%show( ArrayReplacement_RK )
141 call disp%show(
"getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK)")
145 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
146 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
147 call disp%show(
"! Replace only particular instances of pattern in array.")
148 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
149 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
152 string_SK
= "1ParaMonte-2ParaMonte-3ParaMonte-4ParaMonte-5ParaMonte"
154 Array_IK
= [
1_IK,
1_IK,
1_IK,
1_IK,
1_IK]
155 Array_RK
= [
1._RK,
1._RK,
1._RK,
1._RK,
1._RK]
156 Array_CK
= [(
+1._CK,
-1._CK), (
+1._CK,
-1._CK), (
+1._CK,
-1._CK), (
+1._CK,
-1._CK), (
+1._CK,
-1._CK)]
158 stringPattern_SK
= "ParaMonte"
160 ArrayPattern_IK
= [
1_IK]
161 ArrayPattern_RK
= [
1._RK]
162 ArrayPattern_CK
= [(
+1._CK,
-1._CK)]
164 stringReplacement_SK
= ""
166 ArrayReplacement_IK
= [
-2_IK,
-3_IK]
167 ArrayReplacement_RK
= [
-2._RK,
-3._RK]
168 ArrayReplacement_CK
= [(
-2._CK,
+2._CK), (
-3._CK,
+3._CK)]
172 instance
= [
-1_IK,
-2_IK,
2_IK]
175 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
176 call disp%show(
"! Replace specific instances within the character scalar.")
177 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
181 call disp%show( string_SK, deliml
= SK_
"""" )
183 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
184 call disp%show(
"stringReplacement_SK")
185 call disp%show( stringReplacement_SK, deliml
= SK_
"""" )
188 call disp%show(
"getReplaced(string_SK, stringPattern_SK, stringReplacement_SK, instance)")
189 call disp%show(
getReplaced(string_SK, stringPattern_SK, stringReplacement_SK, instance), deliml
= SK_
"""" )
192 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
193 call disp%show(
"! Replace specific instances within the character array.")
194 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
198 call disp%show( Array_SK, deliml
= SK_
"""" )
200 call disp%show( ArrayPattern_SK, deliml
= SK_
"""" )
201 call disp%show(
"ArrayReplacement_SK")
202 call disp%show( ArrayReplacement_SK, deliml
= SK_
"""" )
205 call disp%show(
"getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK, instance)")
206 Array_SK
= getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK, instance)
207 call disp%show( Array_SK, deliml
= SK_
"""" )
210 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
211 call disp%show(
"! Replace specific instances within the integer array.")
212 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
219 call disp%show(
"ArrayReplacement_IK")
220 call disp%show( ArrayReplacement_IK )
223 call disp%show(
"getReplaced(Array_IK, ArrayPattern_IK, ArrayReplacement_IK, instance)")
227 call disp%show(
"Array_IK = [integer(IK) :: 5, 8, 4, 7, 5, 5, 5]")
228 Array_IK
= [
integer(IK) ::
5,
8,
4,
7,
5,
5,
5]
229 call disp%show(
"ArrayPattern_IK = [5_IK]")
230 ArrayPattern_IK
= [
5_IK]
231 call disp%show(
"ArrayReplacement_IK")
232 ArrayReplacement_IK
= [
integer(IK) ::]
233 call disp%show(
"instance = [integer(IK) :: -2, 3, 2, -13, -11, 6, 4, -7, 8]")
234 instance
= [
integer(IK) ::
-2,
3,
2,
-13,
-11,
6,
4,
-7,
8]
235 call disp%show(
"getReplaced(Array_IK, ArrayPattern_IK(1), ArrayReplacement_IK, instance, sorted = .false._LK, unique = .false._LK)")
236 call disp%show(
getReplaced(Array_IK, ArrayPattern_IK(
1), ArrayReplacement_IK, instance, sorted
= .false._LK, unique
= .false._LK) )
239 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
240 call disp%show(
"! Replace specific instances within the logical array.")
241 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
244 call disp%show(
"Array_LK = [logical(LK) :: .false., .true., .true., .false., .false., .true., .false., .false., .false., .true., .false., .false., .false., .true., .false.]")
245 Array_LK
= [
logical(
LK) ::
.false.,
.true.,
.true.,
.false.,
.false.,
.true.,
.false.,
.false.,
.false.,
.true.,
.false.,
.false.,
.false.,
.true.,
.false.]
246 call disp%show(
"ArrayPattern_LK = [logical(LK) :: .true.]")
247 ArrayPattern_LK
= [
logical(
LK) ::
.true.]
248 call disp%show(
"ArrayReplacement_LK")
249 ArrayReplacement_LK
= [
logical(
LK) ::]
250 call disp%show(
"instance = [integer(IK) :: 3]")
251 instance
= [
integer(IK) ::
3]
252 call disp%show(
"getReplaced(Array_LK, ArrayPattern_LK, ArrayReplacement_LK, instance, sorted = .false._LK, unique = .false._LK)")
253 call disp%show(
getReplaced(Array_LK, ArrayPattern_LK, ArrayReplacement_LK, instance, sorted
= .false._LK, unique
= .false._LK) )
256 call disp%show(
"Array_LK = [logical(LK) :: .false.]")
257 Array_LK
= [
logical(
LK) ::
.false.]
258 call disp%show(
"ArrayPattern_LK = [logical(LK) :: .false.]")
259 ArrayPattern_LK
= [
logical(
LK) ::
.false.]
260 call disp%show(
"ArrayReplacement_LK = [logical(LK) ::]")
261 ArrayReplacement_LK
= [
logical(
LK) ::]
262 call disp%show(
"instance = [integer(IK) :: 0]")
263 instance
= [
integer(IK) ::
0]
264 call disp%show(
"getReplaced(Array_LK, ArrayPattern_LK(1), ArrayReplacement_LK, instance, sorted = .false._LK, unique = .false._LK)")
265 call disp%show(
getReplaced(Array_LK, ArrayPattern_LK(
1), ArrayReplacement_LK, instance, sorted
= .false._LK, unique
= .false._LK) )
268 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
269 call disp%show(
"! Replace specific instances within the complex array.")
270 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
277 call disp%show(
"ArrayReplacement_CK")
278 call disp%show( ArrayReplacement_CK )
281 call disp%show(
"getReplaced(Array_CK, ArrayPattern_CK, ArrayReplacement_CK, instance)")
285 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
286 call disp%show(
"! Replace specific instances within the real array.")
287 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
294 call disp%show(
"ArrayReplacement_RK")
295 call disp%show( ArrayReplacement_RK )
298 call disp%show(
"getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK, instance)")
302 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
303 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
304 call disp%show(
"! Replace specific instances with a user-defined equality test.")
305 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
306 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
310 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
311 call disp%show(
"! Replace specific instances within the real array.")
312 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
315 Array_RK
= [
1.01_RK,
1.04_RK,
0.98_RK,
1.0_RK,
1.02_RK]
316 ArrayPattern_RK
= [
-1._RK,
1._RK]
317 ArrayReplacement_RK
= [
0._RK,
0._RK]
324 call disp%show(
"ArrayReplacement_RK")
325 call disp%show( ArrayReplacement_RK )
328 call disp%show(
"getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK, iseq = iseq_RK, instance = instance)")
329 call disp%show(
getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK, iseq
= iseq_RK, instance
= instance) )
332 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
333 call disp%show(
"! Replace case-insensitive instances within the character array.")
334 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
337 string_SK
= "ABBAbbA"
338 stringPattern_SK
= "bb"
339 stringReplacement_SK
= "x"
342 call disp%show( string_SK, deliml
= SK_
"""" )
344 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
345 call disp%show(
"stringReplacement_SK")
346 call disp%show( stringReplacement_SK, deliml
= SK_
"""" )
347 call disp%show(
"getReplaced(string_SK, stringPattern_SK, stringReplacement_SK, iseq = iseq_SK)")
348 call disp%show(
getReplaced(string_SK, stringPattern_SK, stringReplacement_SK, iseq
= iseq_SK), deliml
= SK_
"""" )
352 function iseq_RK(Segment, pattern, lenPattren)
result(equivalent)
353 integer(IK) ,
intent(in) :: lenPattren
354 real(RK) ,
intent(in) :: Segment(lenPattren)
355 real(RK) ,
intent(in) :: pattern(lenPattren)
356 logical(LK) :: equivalent
357 equivalent
= all(abs(abs(pattern)
- abs(Segment))
< 0.05_RK)
360 function iseq_SK(segment, pattern)
result(equivalent)
362 character(
*, SK),
intent(in) :: segment, pattern
363 logical(LK) :: equivalent
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.
Generate and return the input string where the uppercase English alphabets are all converted to lower...
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 contains the uncommon and hardly representable ASCII characters as well as procedures for...
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 ⛓
14"ParaMonte is a Monte Carlo Library."
18"now a Machine Learning"
19getReplaced(string_SK, stringPattern_SK, stringReplacement_SK)
20"ParaMonte is now a Machine Learning Library."
27"ParaMonte",
"is ",
"a ",
"Monte ",
"Carlo ",
"Library. "
29"a ",
"Monte ",
"Carlo "
31"now ",
"a ",
"Machine ",
"Learning "
32getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK)
33getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK)
45getReplaced(Array_LK, ArrayPattern_LK, ArrayReplacement_LK)
58getReplaced(Array_IK, ArrayPattern_IK, ArrayReplacement_IK)
66(
+1.0000000000000000,
-1.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000)
68(
+3.0000000000000000,
-3.0000000000000000)
70(
-1.0000000000000000,
+1.0000000000000000), (
+0.0000000000000000,
+0.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000)
71getReplaced(Array_CK, ArrayPattern_CK, ArrayReplacement_CK)
72(
+1.0000000000000000,
-1.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
-1.0000000000000000,
+1.0000000000000000), (
+0.0000000000000000,
+0.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000)
79+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000
83-1.0000000000000000,
+0.0000000000000000,
+1.0000000000000000
84getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK)
85+1.0000000000000000,
+2.0000000000000000,
-1.0000000000000000,
+0.0000000000000000,
+1.0000000000000000,
+4.0000000000000000
99"1ParaMonte-2ParaMonte-3ParaMonte-4ParaMonte-5ParaMonte"
106getReplaced(string_SK, stringPattern_SK, stringReplacement_SK, instance)
107"1ParaMonte-2-3ParaMonte-4-5"
114"ParaMonte",
"is ",
"a ",
"Monte ",
"Carlo ",
"Library. "
116"a ",
"Monte ",
"Carlo "
118"now ",
"a ",
"Machine ",
"Learning "
121getReplaced(Array_SK, ArrayPattern_SK, ArrayReplacement_SK, instance)
122"ParaMonte",
"is ",
"now ",
"a ",
"Machine ",
"Learning ",
"Library. "
136getReplaced(Array_IK, ArrayPattern_IK, ArrayReplacement_IK, instance)
137+1,
-2,
-3,
+1,
-2,
-3,
-2,
-3
139Array_IK
= [
integer(IK) ::
5,
8,
4,
7,
5,
5,
5]
140ArrayPattern_IK
= [
5_IK]
142instance
= [
integer(IK) ::
-2,
3,
2,
-13,
-11,
6,
4,
-7,
8]
143getReplaced(Array_IK, ArrayPattern_IK(
1), ArrayReplacement_IK, instance, sorted
= .false._LK, unique
= .false._LK)
150Array_LK
= [
logical(
LK) ::
.false.,
.true.,
.true.,
.false.,
.false.,
.true.,
.false.,
.false.,
.false.,
.true.,
.false.,
.false.,
.false.,
.true.,
.false.]
151ArrayPattern_LK
= [
logical(
LK) ::
.true.]
153instance
= [
integer(IK) ::
3]
154getReplaced(Array_LK, ArrayPattern_LK, ArrayReplacement_LK, instance, sorted
= .false._LK, unique
= .false._LK)
155F, T, T, F, F, F, F, F, T, F, F, F, T, F
157Array_LK
= [
logical(
LK) ::
.false.]
158ArrayPattern_LK
= [
logical(
LK) ::
.false.]
159ArrayReplacement_LK
= [
logical(
LK) ::]
160instance
= [
integer(IK) ::
0]
161getReplaced(Array_LK, ArrayPattern_LK(
1), ArrayReplacement_LK, instance, sorted
= .false._LK, unique
= .false._LK)
169(
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000)
171(
+1.0000000000000000,
-1.0000000000000000)
173(
-2.0000000000000000,
+2.0000000000000000), (
-3.0000000000000000,
+3.0000000000000000)
176getReplaced(Array_CK, ArrayPattern_CK, ArrayReplacement_CK, instance)
177(
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000)
184+1.0000000000000000,
+1.0000000000000000,
+1.0000000000000000,
+1.0000000000000000,
+1.0000000000000000
188-2.0000000000000000,
-3.0000000000000000
191getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK, instance)
192+1.0000000000000000,
+1.0000000000000000,
+1.0000000000000000,
+1.0000000000000000,
+1.0000000000000000
206+1.0100000000000000,
+1.0400000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
208-1.0000000000000000,
+1.0000000000000000
210+0.0000000000000000,
+0.0000000000000000
213getReplaced(Array_RK, ArrayPattern_RK, ArrayReplacement_RK, iseq
= iseq_RK, instance
= instance)
214+0.0000000000000000,
+0.0000000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
226getReplaced(string_SK, stringPattern_SK, stringReplacement_SK, iseq
= iseq_SK)
- Test:
- test_pm_arrayReplace
- Bug:
Status: Unresolved
Source: Intel Classic Fortran Compiler ifort
version 2021.2.0, GNU Fortran Compiler gfortran
version 10, 11
Description: The Intel Classic Fortran Compiler ifort
version 2021.2.0 has a bug for the following interface definition,
character(len(array)) , allocatable :: arrayNew(:)
leading to an internal compiler error.
Remedy (as of ParaMonte Library version 2.0.0): For now, the remedy seems to be to redefine the interface as,
character(:, SK), allocatable :: arrayNew(:)
and changing the allocation method accordingly in the implementation to,
allocate(character(len(array, kind = IK)) :: arrayNew(lenArrayNew))
However, this introduces internal compiler error: Segmentation fault
with gfortran versions 10 and 11. Here is a code snippet to regenerate the bug in Intel ifort (uncomment the commented line to reproduce the gfortran bug),
module pm_explicitLenResult
implicit none
interface
pure module function bug(array) result(arrayNew)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK) , allocatable :: arrayNew(:)
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(arrayNew, source = array)
end procedure
end submodule routines
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: arrayNew(:)
arrayNew = bug(array)
end program main
program main
This is main entry to the tests of the ParaMonte kernel library.
It turns out that both gfortran and Intel do not tolerate the separation of interface from implementation in the above code snippet. If one duplicates the interface in the implementation submodule, then both compilers compile and run the code with no errors. This is the remedy that is currently used in this getReplaced generic interface (interface duplication where the bug exists). Here is a workaround example for the bug in the above code snippet,
module pm_explicitLenResult
implicit none
interface
pure module function bug(array) result(arrayNew)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array)) , allocatable :: arrayNew(:)
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(arrayNew, source = array)
end procedure
end submodule routines
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: arrayNew(:)
arrayNew = bug(array)
end program main
- Bug:
Status: Unresolved
Source: GNU Fortran Compiler gfortran
version 10, 11
Description: The GNU Fortran Compiler gfortran
cannot run examples that use procedure dummy arguments iseq()
with explicit interface, yielding the following error:
Fortran runtime error: array bound mismatch for dimension 1 of array 'segment' (0/7021782950660276225)
The Intel Classic Fortran Compiler ifort
version 2021.6 can successfully compile and run the examples.
Remedy (as of ParaMonte Library version 2.0.0): For now, all iseq()
procedure dummy argument interfaces are kept implicit.
- Todo:
- The internal compiler error with Intel Classic Fortran Compiler
ifort
and GNU Fortran Compiler gfortran
has to be fixed in the future versions.
- Todo:
- Low Priority: This generic interface can be extended to 2D input objects.
- Todo:
- High Priority: This generic interface can be extended to scalar input
pattern
and replacement
arguments.
Such an extension will likely lead to runtime performance gain for cases where pattern
and replacement
are arrays of length 1
.
See pm_arraySplit for a relevant benchmark about this matter.
- Todo:
- High Priority: A benchmark comparing the performance of setReplaced with and without
sorted, unique
optional input arguments should be added.
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, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin
Definition at line 986 of file pm_arrayReplace.F90.