Generate and return an allocatable
array containing the remaining parts of the input array as a sequence after removing the input pattern
at the requested occurrences.
If an input vector of instance
is specified, containing the indices of the specific instances of pattern
that must be removed, then only those instances will be removed from the array.
- 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 assumed-length
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
within which the requested instances of pattern is to be removed.
|
[in] | pattern | : The input contiguous array of rank 1 or scalar of the same type and kind as the input array containing the pattern that must be removed from the input array . |
| iseq | : The external user-specified function that takes two input explicit-shape arguments of the same type and kind as the input array and possibly, also the length of the arguments as the third argument.
It returns a scalar 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. .
If pattern is an array of rank 1 , then the last argument to iseq is the length of the input pattern , preceded by a segment of array and pattern as the first and second arguments whose lengths are given by the third argument lenPattern .
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)
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.
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
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 a user-defined equivalence test other than exact equality or 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 removed.
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 removing the second instance of pattern in array from the beginning and removing the first instance of pattern starting from the end of array .
(optional, the default value corresponds to removing all instances of pattern 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
ArrayRemoved
: The output allocatable of the same type, kind, and rank as the input array
argument containing the remaining parts of the array in sequence after removing the requested (or all) instances of pattern
.
Possible calling interfaces ⛓
ArrayRemoved
= getRemoved(array, pattern, instance, sorted
= sorted, unique
= unique)
ArrayRemoved
= getRemoved(array, pattern, iseq, instance, sorted
= sorted, unique
= unique)
Generate and return an allocatable array containing the remaining parts of the input array as a seque...
This module contains procedures and generic interfaces for removing a pattern from arrays of various ...
- 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
- setRemoved
setReplaced
getReplaced
setInserted
setSplit
Example usage ⛓
13 integer(IK) ,
allocatable :: instance(:)
15 character(:, SK),
allocatable :: string_SK , stringNew_SK , stringPattern_SK
16 character(
9, SK),
allocatable :: Array_SK(:) , ArrayNew_SK(:), ArrayPattern_SK(:)
17 integer(IK) ,
allocatable :: Array_IK(:) , ArrayNew_IK(:), ArrayPattern_IK(:)
18 complex(CK) ,
allocatable :: Array_CK(:) , ArrayNew_CK(:), ArrayPattern_CK(:)
19 real(RK) ,
allocatable :: Array_RK(:) , ArrayNew_RK(:), ArrayPattern_RK(:)
20 logical(LK) ,
allocatable :: Array_LK(:) , ArrayNew_LK(:), ArrayPattern_LK(:)
22 type(display_type) :: disp
27 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
28 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%show(
"! Remove all instances of pattern in array.")
30 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
34 string_SK
= "ParaMonte is a Machine Learning Library "
35 Array_SK
= [
"ParaMonte",
"XXXXXXXXX",
"is ",
"XXXXXXXXX",
"a ",
"XXXXXXXXX",
"Monte ",
"XXXXXXXXX",
"Carlo ",
"XXXXXXXXX",
"Library. ",
"XXXXXXXXX"]
36 Array_IK
= [
1_IK,
0_IK,
2_IK,
0_IK,
3_IK,
0_IK,
4_IK]
37 Array_RK
= [
1._RK,
0._RK,
2._RK,
0._RK,
3._RK,
0._RK,
4._RK]
38 Array_CK
= [(
1._CK,
-1._CK), (
0._CK,
-0._CK), (
2._CK,
-2._CK), (
0._CK,
-0._CK), (
3._CK,
-3._CK), (
0._CK,
-0._CK), (
4._CK,
-4._CK)]
39 Array_LK
= [
.false._LK,
.true._LK,
.false._LK,
.true._LK,
.false._LK,
.true._LK,
.false._LK]
41 stringPattern_SK
= " "
42 ArrayPattern_SK
= [
"XXXXXXXXX"]
43 ArrayPattern_IK
= [
0_IK]
44 ArrayPattern_RK
= [
0._RK]
45 ArrayPattern_CK
= [(
0._CK,
-0._CK)]
46 ArrayPattern_LK
= [
.true._LK]
49 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
50 call disp%show(
"! Remove character scalar.")
51 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
55 call disp%show( string_SK, deliml
= SK_
"""" )
57 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
58 call disp%show(
"stringNew_SK = getRemoved(string_SK, stringPattern_SK)")
59 stringNew_SK
= getRemoved(string_SK, stringPattern_SK)
61 call disp%show( stringNew_SK, deliml
= SK_
"""" )
64 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%show(
"! Remove character array.")
66 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%")
70 call disp%show( Array_SK, deliml
= SK_
"""" )
72 call disp%show( ArrayPattern_SK, deliml
= SK_
"""" )
73 call disp%show(
"ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK)")
74 ArrayNew_SK
= getRemoved(Array_SK, ArrayPattern_SK)
76 call disp%show( ArrayNew_SK, deliml
= SK_
"""" )
79 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%")
80 call disp%show(
"! Remove logical array.")
81 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%")
88 call disp%show(
"ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK)")
89 ArrayNew_LK
= getRemoved(Array_LK, ArrayPattern_LK)
94 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%")
95 call disp%show(
"! Remove integer array.")
96 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%")
103 call disp%show(
"ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK)")
104 ArrayNew_IK
= getRemoved(Array_IK, ArrayPattern_IK)
109 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%")
110 call disp%show(
"! Remove complex array.")
111 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%")
118 call disp%show(
"ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK)")
119 ArrayNew_CK
= getRemoved(Array_CK, ArrayPattern_CK)
124 call disp%show(
"!%%%%%%%%%%%%%%%%%%%")
125 call disp%show(
"! Remove real array.")
126 call disp%show(
"!%%%%%%%%%%%%%%%%%%%")
133 call disp%show(
"ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK)")
134 ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK)
141 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
142 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
143 call disp%show(
"! Remove only particular instances of pattern in array.")
144 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
145 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
148 string_SK
= "A_A_A_A_A_A_A_A_A"
149 Array_SK
= [
"A",
"_",
"A",
"_",
"A",
"_",
"A",
"_",
"A",
"_",
"A",
"_",
"A",
"_",
"A",
"_",
"A"]
150 Array_IK
= [
0_IK,
1_IK,
0_IK,
2_IK,
3_IK,
0_IK,
4_IK,
5_IK,
0_IK,
0_IK]
151 Array_RK
= [
0._RK,
1._RK,
0._RK,
2._RK,
3._RK,
0._RK,
4._RK,
5._RK,
0._RK,
0._RK]
152 Array_CK
= [(
0._CK,
-0._CK), (
1._CK,
-1._CK), (
0._CK,
-0._CK), (
2._CK,
-2._CK), (
3._CK,
-3._CK), (
0._CK,
-0._CK), (
4._CK,
-4._CK), (
5._CK,
-5._CK), (
0._CK,
-0._CK), (
0._CK,
-0._CK)]
153 Array_LK
= [
.false._LK,
.true._LK,
.false._LK,
.true._LK,
.true._LK,
.false._LK,
.true._LK,
.true._LK,
.false._LK,
.false._LK]
155 stringPattern_SK
= "_"
156 ArrayPattern_SK
= [
"_"]
157 ArrayPattern_IK
= [
0_IK]
158 ArrayPattern_RK
= [
0._RK]
159 ArrayPattern_CK
= [(
0._CK,
-0._CK)]
160 ArrayPattern_LK
= [
.false._LK]
162 instance
= [
-3,
2,
-4]
165 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
166 call disp%show(
"! Remove character scalar.")
167 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%")
171 call disp%show( string_SK, deliml
= SK_
"""" )
173 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
176 call disp%show(
"stringNew_SK = getRemoved(string_SK, stringPattern_SK, instance = instance)")
177 stringNew_SK
= getRemoved(string_SK, stringPattern_SK, instance
= instance)
179 call disp%show( stringNew_SK, deliml
= SK_
"""" )
182 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
183 call disp%show(
"! Remove vector `pattern` from character array.")
184 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
188 call disp%show( Array_SK, deliml
= SK_
"""" )
190 call disp%show( ArrayPattern_SK, deliml
= SK_
"""" )
193 call disp%show(
"ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK, instance = instance)")
194 ArrayNew_SK
= getRemoved(Array_SK, ArrayPattern_SK, instance
= instance)
196 call disp%show( ArrayNew_SK, deliml
= SK_
"""" )
199 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
200 call disp%show(
"! Remove character array with scalar `pattern`.")
201 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
205 call disp%show( Array_SK, deliml
= SK_
"""" )
206 call disp%show(
"ArrayPattern_SK(1)")
207 call disp%show( ArrayPattern_SK(
1), deliml
= SK_
"""" )
210 call disp%show(
"ArrayNew_SK = getRemoved(Array_SK, ArrayPattern_SK(1), instance = instance)")
211 ArrayNew_SK
= getRemoved(Array_SK, ArrayPattern_SK(
1), instance
= instance)
213 call disp%show( ArrayNew_SK, deliml
= SK_
"""" )
216 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
217 call disp%show(
"! Remove logical array with vector `pattern`.")
218 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
227 call disp%show(
"ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK, instance = instance)")
228 ArrayNew_LK
= getRemoved(Array_LK, ArrayPattern_LK, instance
= instance)
233 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
234 call disp%show(
"! Remove logical array with scalar `pattern`.")
235 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
240 call disp%show(
"ArrayPattern_LK(1)")
241 call disp%show( ArrayPattern_LK(
1) )
244 call disp%show(
"ArrayNew_LK = getRemoved(Array_LK, ArrayPattern_LK(1), instance = instance)")
245 ArrayNew_LK
= getRemoved(Array_LK, ArrayPattern_LK(
1), instance
= instance)
250 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
251 call disp%show(
"! Remove integer array with vector `pattern`.")
252 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
261 call disp%show(
"ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK, instance = instance)")
262 ArrayNew_IK
= getRemoved(Array_IK, ArrayPattern_IK, instance
= instance)
267 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
268 call disp%show(
"! Remove integer array with scalar `pattern`.")
269 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
274 call disp%show(
"ArrayPattern_IK(1)")
275 call disp%show( ArrayPattern_IK(
1) )
278 call disp%show(
"ArrayNew_IK = getRemoved(Array_IK, ArrayPattern_IK(1), instance = instance)")
279 ArrayNew_IK
= getRemoved(Array_IK, ArrayPattern_IK(
1), instance
= instance)
284 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
285 call disp%show(
"! Remove complex array with vector `pattern`.")
286 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
295 call disp%show(
"ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK, instance = instance)")
296 ArrayNew_CK
= getRemoved(Array_CK, ArrayPattern_CK, instance
= instance)
301 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
302 call disp%show(
"! Remove complex array with scalar `pattern`.")
303 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
308 call disp%show(
"ArrayPattern_CK(1)")
309 call disp%show( ArrayPattern_CK(
1) )
312 call disp%show(
"ArrayNew_CK = getRemoved(Array_CK, ArrayPattern_CK(1), instance = instance)")
313 ArrayNew_CK
= getRemoved(Array_CK, ArrayPattern_CK(
1), instance
= instance)
318 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
319 call disp%show(
"! Remove real array with vector `pattern`.")
320 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
329 call disp%show(
"ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, instance = instance)")
330 ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK, instance
= instance)
335 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
336 call disp%show(
"! Remove real array with scalar `pattern`.")
337 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
342 call disp%show(
"ArrayPattern_RK(1)")
343 call disp%show( ArrayPattern_RK(
1) )
346 call disp%show(
"ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), instance = instance)")
347 ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK(
1), instance
= instance)
353 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
354 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
355 call disp%show(
"! Remove specific instances with a user-defined equivalence test.")
356 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
357 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
362 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
363 call disp%show(
"! Remove case-insensitive instances of vector `pattern` within the character array.")
364 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
367 string_SK
= "ABBAbbA"
368 stringPattern_SK
= "bb"
371 call disp%show( string_SK, deliml
= SK_
"""" )
373 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
374 call disp%show(
"stringNew_SK = getRemoved(string_SK, stringPattern_SK, iseq = iseq_SK) ! case-insensitive string removal.")
375 stringNew_SK
= getRemoved(string_SK, stringPattern_SK, iseq
= iseq_SK)
377 call disp%show( stringNew_SK, deliml
= SK_
"""" )
380 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
381 call disp%show(
"! Remove specific instances of vector `pattern` within the real array.")
382 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
385 Array_RK
= [
0._RK,
1.01_RK,
1.04_RK,
0.98_RK,
1.0_RK,
1.02_RK]
386 ArrayPattern_RK
= [
-1._RK,
1._RK]
395 call disp%show(
"ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK, iseq = iseq_vec_RK, instance = instance)")
396 ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK, iseq
= iseq_vec_RK, instance
= instance)
401 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
402 call disp%show(
"! Remove specific instances of scalar `pattern` within the real array.")
403 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
408 call disp%show(
"ArrayPattern_RK(1)")
409 call disp%show( ArrayPattern_RK(
1) )
412 call disp%show(
"ArrayNew_RK = getRemoved(Array_RK, ArrayPattern_RK(1), iseq = iseq_RK, instance = instance)")
413 ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK(
1), iseq
= iseq_RK, instance
= instance)
419 pure function iseq_SK(ArraySegment, pattern)
result(equivalent)
421 character(
*, SK),
intent(in) :: pattern, ArraySegment
422 logical(LK) :: equivalent
426 function iseq_RK(arraysegment, pattern)
result(equivalent)
427 real(RK) ,
intent(in) :: pattern, arraySegment
428 logical(LK) :: equivalent
429 equivalent
= abs(abs(pattern)
- abs(arraySegment))
< 0.05_RK
432 function iseq_vec_RK(ArraySegment, pattern, lenPattern)
result(equivalent)
433 integer(IK) ,
intent(in) :: lenPattern
434 real(RK) ,
intent(in) :: pattern(lenPattern), ArraySegment(lenPattern)
435 logical(LK) :: equivalent
436 equivalent
= all(abs(abs(pattern)
- abs(ArraySegment))
< 0.05_RK)
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 Machine Learning Library "
17stringNew_SK
= getRemoved(string_SK, stringPattern_SK)
19"ParaMonteisaMachineLearningLibrary"
26"ParaMonte",
"XXXXXXXXX",
"is ",
"XXXXXXXXX",
"a ",
"XXXXXXXXX",
"Monte ",
"XXXXXXXXX",
"Carlo ",
"XXXXXXXXX",
"Library. ",
"XXXXXXXXX"
29ArrayNew_SK
= getRemoved(Array_SK, ArrayPattern_SK)
31"ParaMonte",
"is ",
"a ",
"Monte ",
"Carlo ",
"Library. "
41ArrayNew_LK
= getRemoved(Array_LK, ArrayPattern_LK)
50+1,
+0,
+2,
+0,
+3,
+0,
+4
53ArrayNew_IK
= getRemoved(Array_IK, ArrayPattern_IK)
62(
+1.0000000000000000,
-1.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000)
64(
+0.0000000000000000,
-0.0000000000000000)
65ArrayNew_CK
= getRemoved(Array_CK, ArrayPattern_CK)
67(
+1.0000000000000000,
-1.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000)
74+1.0000000000000000,
+0.0000000000000000,
+2.0000000000000000,
+0.0000000000000000,
+3.0000000000000000,
+0.0000000000000000,
+4.0000000000000000
77ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK)
79+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000
98stringNew_SK
= getRemoved(string_SK, stringPattern_SK, instance
= instance)
107"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A "
112ArrayNew_SK
= getRemoved(Array_SK, ArrayPattern_SK, instance
= instance)
114"A ",
"_ ",
"A ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"A ",
"A ",
"_ ",
"A ",
"_ ",
"A "
121"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A "
126ArrayNew_SK
= getRemoved(Array_SK, ArrayPattern_SK(
1), instance
= instance)
128"A ",
"_ ",
"A ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"A ",
"A ",
"_ ",
"A ",
"_ ",
"A "
135F, T, F, T, T, F, T, T, F, F
140ArrayNew_LK
= getRemoved(Array_LK, ArrayPattern_LK, instance
= instance)
142F, T, T, T, T, T, F, F
149F, T, F, T, T, F, T, T, F, F
154ArrayNew_LK
= getRemoved(Array_LK, ArrayPattern_LK(
1), instance
= instance)
156F, T, T, T, T, T, F, F
163+0,
+1,
+0,
+2,
+3,
+0,
+4,
+5,
+0,
+0
168ArrayNew_IK
= getRemoved(Array_IK, ArrayPattern_IK, instance
= instance)
170+0,
+1,
+2,
+3,
+4,
+5,
+0,
+0
177+0,
+1,
+0,
+2,
+3,
+0,
+4,
+5,
+0,
+0
182ArrayNew_IK
= getRemoved(Array_IK, ArrayPattern_IK(
1), instance
= instance)
184+0,
+1,
+2,
+3,
+4,
+5,
+0,
+0
191(
+0.0000000000000000,
-0.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000), (
+5.0000000000000000,
-5.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000)
193(
+0.0000000000000000,
-0.0000000000000000)
196ArrayNew_CK
= getRemoved(Array_CK, ArrayPattern_CK, instance
= instance)
198(
+0.0000000000000000,
-0.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000), (
+5.0000000000000000,
-5.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000)
205(
+0.0000000000000000,
-0.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000), (
+5.0000000000000000,
-5.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000)
207(
+0.0000000000000000,
-0.0000000000000000)
210ArrayNew_CK
= getRemoved(Array_CK, ArrayPattern_CK(
1), instance
= instance)
212(
+0.0000000000000000,
-0.0000000000000000), (
+1.0000000000000000,
-1.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000), (
+3.0000000000000000,
-3.0000000000000000), (
+4.0000000000000000,
-4.0000000000000000), (
+5.0000000000000000,
-5.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000), (
+0.0000000000000000,
-0.0000000000000000)
219+0.0000000000000000,
+1.0000000000000000,
+0.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+0.0000000000000000,
+4.0000000000000000,
+5.0000000000000000,
+0.0000000000000000,
+0.0000000000000000
224ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK, instance
= instance)
226+0.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+5.0000000000000000,
+0.0000000000000000,
+0.0000000000000000
233+0.0000000000000000,
+1.0000000000000000,
+0.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+0.0000000000000000,
+4.0000000000000000,
+5.0000000000000000,
+0.0000000000000000,
+0.0000000000000000
238ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK(
1), instance
= instance)
240+0.0000000000000000,
+1.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+4.0000000000000000,
+5.0000000000000000,
+0.0000000000000000,
+0.0000000000000000
257stringNew_SK
= getRemoved(string_SK, stringPattern_SK, iseq
= iseq_SK)
266+0.0000000000000000,
+1.0100000000000000,
+1.0400000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
268-1.0000000000000000,
+1.0000000000000000
271ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK, iseq
= iseq_vec_RK, instance
= instance)
273+0.0000000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
280+0.0000000000000000,
+1.0100000000000000,
+1.0400000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
285ArrayNew_RK
= getRemoved(Array_RK, ArrayPattern_RK(
1), iseq
= iseq_RK, instance
= instance)
287+0.0000000000000000,
+1.0100000000000000,
+1.0400000000000000,
+0.97999999999999998,
+1.0200000000000000
- Test:
- test_pm_arrayRemove
- 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,IK),SK), allocatable :: ArrayRemoved(:)
leading to an internal compiler error. For now, the remedy seems to be to redefine the interface as,
character(:, SK), allocatable :: ArrayRemoved(:)
and changing the allocation method accordingly in the implementation to,
allocate(character(len(array, kind = IK)) :: ArrayRemoved(lenArrayRemoved))
However, this introduces internal compiler error: Segmentation fault
with GNU Fortran Compiler gfortran
versions 10 and 11. Here is a code snippet to regenerate the bug in Intel Classic Fortran Compiler ifort
(uncomment the commented line to reproduce the gfortran bug),
module pm_explicitLenResult
implicit none
interface
pure module function bug(array) result(ArrayRemoved)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK) , allocatable :: ArrayRemoved(:)
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(ArrayRemoved, source = array)
end procedure
end submodule routines
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: ArrayRemoved(:)
ArrayRemoved = bug(array)
end program main
program main
This is main entry to the tests of the ParaMonte kernel library.
Remedy (as of ParaMonte Library version 2.0.0): 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 getRemoved 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(ArrayRemoved)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK), allocatable :: ArrayRemoved(:)
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(ArrayRemoved, source = array)
end procedure
end submodule routines
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: ArrayRemoved(:)
ArrayRemoved = bug(array)
end program main
- Todo:
- Low Priority: This generic interface can be extended to 2D input objects.
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 Austin
Definition at line 337 of file pm_arrayRemove.F90.