Generate and return an allocatable
array containing the indices of the locations within the input array where the input pattern
exists.
If an input vector of instance
is specified, containing the indices of the specific instances of pattern
that must be found, then the indices of only those specific instances will be returned.
The instances of pattern
are found via linear search.
Therefore, the procedures under this generic interface have a worst-case complexity of O(size(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
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 assumed-length
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
within which the starting indices of the requested instances of pattern is to be found.
|
[in] | pattern | : The input object of the same or lower rank than the input array , and of the same type and kind as array containing the pattern that must be found within 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, if the arguments are array-valued.
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)
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
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 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 specific instances of the input pattern in the input array that should be found.
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 .
Any element of instance that is duplicated will yield duplicated output array indices if pattern is found, otherwise will be ignored.
For example, instance = [2,-1] requests finding the indices of second instance of pattern in array from the beginning and the first instance of pattern starting from the end of array .
(optional, the default value corresponds to finding 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.
See also the relevant benchmark at pm_arrayFind.
(optional, default = .false. . It can be present as input argument only if the input argument instance is present.) |
[in] | positive | : The input logical of default kind LK indicating whether the elements of the specified input instance are all positive.
Setting positive = .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 positive.
This is generally not an easy guarantee to make if there are negative elements in instance .
Therefore, set positive = .true. only if you can guarantee the validity of the condition.
See also the relevant benchmark at pm_arrayFind.
(optional, default = .false. . It can be present as input argument only if the input argument instance is present.) |
[in] | blindness | : The input positive integer of default kind IK representing the length of the segment of array that should be ignored after finding an instance of the input pattern in the array.
Setting blindness = len(pattern) (for assumed-length character pattern ) or blindness = size(pattern) (for other types of array-valued pattern ) will lead to a search for exclusive non-overlapping instances of pattern in the input array .
See the examples below for more illustration of the utility of this input argument.
(optional, default = 1_IK ) |
- Returns
loc
: The output allocatable
array of shape (1:*)
of type integer
of default kind IK, containing the indices of the input array
where the requested instances of pattern
start.
The output loc
is a vector of size 0
if there are no instances of the input pattern
in the array
.
Possible calling interfaces ⛓
loc
= getLoc(array, pattern, blindness
= blindness)
loc
= getLoc(array, pattern, iseq, blindness
= blindness)
loc
= getLoc(array, pattern, instance(:), sorted
= sorted, positive
= positive, blindness
= blindness)
loc
= getLoc(array, pattern, iseq, instance(:), sorted
= sorted, positive
= positive, blindness
= blindness)
loc
= getLoc(array(:), pattern, blindness
= blindness)
loc
= getLoc(array(:), pattern, iseq, blindness
= blindness)
loc
= getLoc(array(:), pattern, instance(:), sorted
= sorted, positive
= positive, blindness
= blindness)
loc
= getLoc(array(:), pattern, iseq, instance(:), sorted
= sorted, positive
= positive, blindness
= blindness)
loc
= getLoc(array(:), pattern(:), blindness
= blindness)
loc
= getLoc(array(:), pattern(:), iseq, blindness
= blindness)
loc
= getLoc(array(:), pattern(:), instance(:), sorted
= sorted, positive
= positive, blindness
= blindness)
loc
= getLoc(array(:), pattern(:), iseq, instance(:), sorted
= sorted, positive
= positive, blindness
= blindness)
!
Generate and return an allocatable array containing the indices of the locations within the input arr...
This module contains procedures and generic interfaces for finding locations of a pattern in arrays o...
- Warning
- The condition
0 < blindness
must hold for the corresponding input arguments.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
-
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.
.
-
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.
- Note
- If the input
array
does not contain any (of the requested) instances of the input pattern
, the output loc
will be an allocated
array of size 0
.
- See also
- setLoc
getBin
setReplaced
getReplaced
setInserted
setSplit
Example usage ⛓
13 integer(IK) ,
allocatable :: instance(:) , Loc(:)
15 character(:, SK),
allocatable :: string_SK , stringPattern_SK
16 character(
9, SK),
allocatable :: array_SK(:) , arrayPattern_SK(:)
17 integer(IK) ,
allocatable :: array_IK(:) , arrayPattern_IK(:)
18 complex(CK) ,
allocatable :: array_CK(:) , arrayPattern_CK(:)
19 real(RK) ,
allocatable :: array_RK(:) , arrayPattern_RK(:)
20 logical(LK) ,
allocatable :: array_LK(:) , arrayPattern_LK(:)
22 type(display_type) :: disp
27 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
28 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%show(
"! Find 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(
"! Find 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(
"Loc = getLoc(string_SK, stringPattern_SK)")
59 Loc
= getLoc(string_SK, stringPattern_SK)
64 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%show(
"! Find 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(
"Loc = getLoc(array_SK, arrayPattern_SK)")
74 Loc
= getLoc(array_SK, arrayPattern_SK)
79 call disp%show(
"!%%%%%%%%%%%%%%%%%%%")
80 call disp%show(
"! Find logical array.")
81 call disp%show(
"!%%%%%%%%%%%%%%%%%%%")
88 call disp%show(
"Loc = getLoc(array_LK, arrayPattern_LK)")
89 Loc
= getLoc(array_LK, arrayPattern_LK)
94 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
95 call disp%show(
"! Find integer array.")
96 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
103 call disp%show(
"Loc = getLoc(array_IK, arrayPattern_IK)")
104 Loc
= getLoc(array_IK, arrayPattern_IK)
109 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
110 call disp%show(
"! Find complex array.")
111 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%")
118 call disp%show(
"Loc = getLoc(array_CK, arrayPattern_CK)")
119 Loc
= getLoc(array_CK, arrayPattern_CK)
124 call disp%show(
"!%%%%%%%%%%%%%%%%%%%")
125 call disp%show(
"! Find real array.")
126 call disp%show(
"!%%%%%%%%%%%%%%%%%%%")
133 call disp%show(
"Loc = getLoc(array_RK, arrayPattern_RK)")
134 Loc
= getLoc(array_RK, arrayPattern_RK)
141 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
142 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
143 call disp%show(
"! Find 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(
"! Find 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(
"Loc = getLoc(string_SK, stringPattern_SK, instance = instance)")
177 Loc
= getLoc(string_SK, stringPattern_SK, instance
= instance)
182 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
183 call disp%show(
"! Find 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(
"Loc = getLoc(array_SK, arrayPattern_SK, instance = instance)")
194 Loc
= getLoc(array_SK, arrayPattern_SK, instance
= instance)
199 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
200 call disp%show(
"! Find 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(
"Loc = getLoc(array_SK, arrayPattern_SK(1), instance = instance)")
211 Loc
= getLoc(array_SK, arrayPattern_SK(
1), instance
= instance)
216 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
217 call disp%show(
"! Find logical array with vector `pattern`.")
218 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
227 call disp%show(
"Loc = getLoc(array_LK, arrayPattern_LK, instance = instance)")
228 Loc
= getLoc(array_LK, arrayPattern_LK, instance
= instance)
233 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
234 call disp%show(
"! Find 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(
"Loc = getLoc(array_LK, arrayPattern_LK(1), instance = instance)")
245 Loc
= getLoc(array_LK, arrayPattern_LK(
1), instance
= instance)
250 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
251 call disp%show(
"! Find integer array with vector `pattern`.")
252 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
261 call disp%show(
"Loc = getLoc(array_IK, arrayPattern_IK, instance = instance)")
262 Loc
= getLoc(array_IK, arrayPattern_IK, instance
= instance)
267 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
268 call disp%show(
"! Find 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(
"Loc = getLoc(array_IK, arrayPattern_IK(1), instance = instance)")
279 Loc
= getLoc(array_IK, arrayPattern_IK(
1), instance
= instance)
284 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
285 call disp%show(
"! Find complex array with vector `pattern`.")
286 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
295 call disp%show(
"Loc = getLoc(array_CK, arrayPattern_CK, instance = instance)")
296 Loc
= getLoc(array_CK, arrayPattern_CK, instance
= instance)
301 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
302 call disp%show(
"! Find 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(
"Loc = getLoc(array_CK, arrayPattern_CK(1), instance = instance)")
313 Loc
= getLoc(array_CK, arrayPattern_CK(
1), instance
= instance)
318 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
319 call disp%show(
"! Find real array with vector `pattern`.")
320 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
329 call disp%show(
"Loc = getLoc(array_RK, arrayPattern_RK, instance = instance)")
330 Loc
= getLoc(array_RK, arrayPattern_RK, instance
= instance)
335 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
336 call disp%show(
"! Find 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(
"Loc = getLoc(array_RK, arrayPattern_RK(1), instance = instance)")
347 Loc
= getLoc(array_RK, arrayPattern_RK(
1), instance
= instance)
353 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
354 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
355 call disp%show(
"! Adjust the blindness to exclusively find non-overlapping instances of `pattern`.")
356 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
357 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
361 string_SK
= "AAAAAAAA"
362 stringPattern_SK
= "AAA"
365 call disp%show( string_SK, deliml
= SK_
"""" )
367 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
368 call disp%show(
"Loc = getLoc(string_SK, stringPattern_SK, blindness = 1_IK) ! The default blindness episode after each detection is `blindness = 1_IK`")
369 Loc
= getLoc(string_SK, stringPattern_SK, blindness
= 1_IK)
374 call disp%show( string_SK, deliml
= SK_
"""" )
376 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
377 call disp%show(
"Loc = getLoc(string_SK, stringPattern_SK, blindness = size(stringPattern_SK, kind = IK)) ! Find only non-overlapping patterns.")
378 Loc
= getLoc(string_SK, stringPattern_SK, blindness
= len(stringPattern_SK,
kind = IK))
383 call disp%show( string_SK, deliml
= SK_
"""" )
385 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
386 call disp%show(
"Loc = getLoc(string_SK, stringPattern_SK, blindness = 2_IK) ! Find instances with jumps of size 2.")
387 Loc
= getLoc(string_SK, stringPattern_SK, blindness
= 2_IK)
393 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
394 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
395 call disp%show(
"! Find specific instances with a user-defined equivalence test.")
396 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
397 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
402 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
403 call disp%show(
"! Find case-insensitive instances of vector `pattern` within the character array.")
404 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
407 string_SK
= "ABBAbbA"
408 stringPattern_SK
= "bb"
411 call disp%show( string_SK, deliml
= SK_
"""" )
413 call disp%show( stringPattern_SK, deliml
= SK_
"""" )
414 call disp%show(
"Loc = getLoc(string_SK, stringPattern_SK, iseq = iseq_SK)")
415 Loc
= getLoc(string_SK, stringPattern_SK, iseq
= iseq_SK)
420 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
421 call disp%show(
"! Find specific instances of vector `pattern` within the real array.")
422 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
425 array_RK
= [
0._RK,
1.01_RK,
1.04_RK,
0.98_RK,
1.0_RK,
1.02_RK]
426 arrayPattern_RK
= [
-1._RK,
1._RK]
435 call disp%show(
"Loc = getLoc(array_RK, arrayPattern_RK, iseq = iseq_vec_RK, instance = instance)")
436 Loc
= getLoc(array_RK, arrayPattern_RK, iseq
= iseq_vec_RK, instance
= instance)
441 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
442 call disp%show(
"! Find specific instances of scalar `pattern` within the real array.")
443 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
448 call disp%show(
"arrayPattern_RK(1)")
449 call disp%show( arrayPattern_RK(
1) )
452 call disp%show(
"Loc = getLoc(array_RK, arrayPattern_RK(1), iseq = iseq_RK, instance = instance)")
453 Loc
= getLoc(array_RK, arrayPattern_RK(
1), iseq
= iseq_RK, instance
= instance)
459 pure function iseq_SK(ArraySegment, pattern)
result(equivalent)
461 character(
*, SK),
intent(in) :: pattern, ArraySegment
462 logical(LK) :: equivalent
466 function iseq_RK(arraysegment, pattern)
result(equivalent)
467 real(RK) ,
intent(in) :: pattern, arraySegment
468 logical(LK) :: equivalent
469 equivalent
= abs(abs(pattern)
- abs(arraySegment))
< 0.05_RK
472 function iseq_vec_RK(ArraySegment, pattern, lenPattern)
result(equivalent)
473 integer(IK) ,
intent(in) :: lenPattern
474 real(RK) ,
intent(in) :: pattern(lenPattern), ArraySegment(lenPattern)
475 logical(LK) :: equivalent
476 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 "
17Loc
= getLoc(string_SK, stringPattern_SK)
19+10,
+13,
+15,
+23,
+32,
+40
26"ParaMonte",
"XXXXXXXXX",
"is ",
"XXXXXXXXX",
"a ",
"XXXXXXXXX",
"Monte ",
"XXXXXXXXX",
"Carlo ",
"XXXXXXXXX",
"Library. ",
"XXXXXXXXX"
29Loc
= getLoc(array_SK, arrayPattern_SK)
31+2,
+4,
+6,
+8,
+10,
+12
41Loc
= getLoc(array_LK, arrayPattern_LK)
50+1,
+0,
+2,
+0,
+3,
+0,
+4
53Loc
= getLoc(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)
65Loc
= getLoc(array_CK, arrayPattern_CK)
74+1.0000000000000000,
+0.0000000000000000,
+2.0000000000000000,
+0.0000000000000000,
+3.0000000000000000,
+0.0000000000000000,
+4.0000000000000000
77Loc
= getLoc(array_RK, arrayPattern_RK)
98Loc
= getLoc(string_SK, stringPattern_SK, instance
= instance)
107"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A "
112Loc
= getLoc(array_SK, arrayPattern_SK, instance
= instance)
121"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A ",
"_ ",
"A "
126Loc
= getLoc(array_SK, arrayPattern_SK(
1), instance
= instance)
135F, T, F, T, T, F, T, T, F, F
140Loc
= getLoc(array_LK, arrayPattern_LK, instance
= instance)
149F, T, F, T, T, F, T, T, F, F
154Loc
= getLoc(array_LK, arrayPattern_LK(
1), instance
= instance)
163+0,
+1,
+0,
+2,
+3,
+0,
+4,
+5,
+0,
+0
168Loc
= getLoc(array_IK, arrayPattern_IK, instance
= instance)
177+0,
+1,
+0,
+2,
+3,
+0,
+4,
+5,
+0,
+0
182Loc
= getLoc(array_IK, arrayPattern_IK(
1), instance
= instance)
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)
196Loc
= getLoc(array_CK, arrayPattern_CK, instance
= instance)
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)
210Loc
= getLoc(array_CK, arrayPattern_CK(
1), instance
= instance)
219+0.0000000000000000,
+1.0000000000000000,
+0.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+0.0000000000000000,
+4.0000000000000000,
+5.0000000000000000,
+0.0000000000000000,
+0.0000000000000000
224Loc
= getLoc(array_RK, arrayPattern_RK, instance
= instance)
233+0.0000000000000000,
+1.0000000000000000,
+0.0000000000000000,
+2.0000000000000000,
+3.0000000000000000,
+0.0000000000000000,
+4.0000000000000000,
+5.0000000000000000,
+0.0000000000000000,
+0.0000000000000000
238Loc
= getLoc(array_RK, arrayPattern_RK(
1), instance
= instance)
252Loc
= getLoc(string_SK, stringPattern_SK, blindness
= 1_IK)
254+1,
+2,
+3,
+4,
+5,
+6
259Loc
= getLoc(string_SK, stringPattern_SK, blindness
= size(stringPattern_SK,
kind = IK))
266Loc
= getLoc(string_SK, stringPattern_SK, blindness
= 2_IK)
285Loc
= getLoc(string_SK, stringPattern_SK, iseq
= iseq_SK)
294+0.0000000000000000,
+1.0100000000000000,
+1.0400000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
296-1.0000000000000000,
+1.0000000000000000
299Loc
= getLoc(array_RK, arrayPattern_RK, iseq
= iseq_vec_RK, instance
= instance)
308+0.0000000000000000,
+1.0100000000000000,
+1.0400000000000000,
+0.97999999999999998,
+1.0000000000000000,
+1.0200000000000000
313Loc
= getLoc(array_RK, arrayPattern_RK(
1), iseq
= iseq_RK, instance
= instance)
- Test:
- test_pm_arrayFind
- Bug:
Status: Unresolved
Source: Intel Classic Fortran Compiler ifort
version 2021.2.0, GNU Fortran Compiler gfortran
version 10-12
Description: The Intel Fortran compiler Classic 2021.2.0 has a bug for the following interface definition
character(len(array),SK), allocatable :: loc(:)
leading to an internal compiler error.
For now, the remedy seems to be to redefine the interface as,
character(:, SK), allocatable :: loc(:)
and changing the allocation method accordingly in the implementation to,
allocate(character(len(array, kind = IK)) :: loc(lenLoc))
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(loc)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK) , allocatable :: loc(:)
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(loc, source = array)
end procedure
end submodule routines
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: loc(:)
loc = 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.
Remedy (as of ParaMonte Library version 2.0.0): 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 getLoc 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(loc)
character(*, SK), intent(in), contiguous :: array(:)
character(len(array),SK), allocatable :: loc(:)
end function
end interface
end module pm_explicitLenResult
submodule (pm_explicitLenResult) routines
implicit none
contains
module procedure bug
allocate(loc, source = array)
end procedure
end submodule routines
use pm_explicitLenResult, only: bug
character(2) :: array(3) = ["AA", "BB", "CC"]
character(2), allocatable :: loc(:)
loc = bug(array)
end program main
- Todo:
- Low Priority: This generic interface can be extended to higher-dimensional input arrays.
- Todo:
- Critical Priority: Currently, the value of
blindness
is checked for being non-zero in the implementation.
However, the documentation of blindness
requires it to be positive.
This conflict between the implementation and documentation must be resolved.
- Todo:
- Normal Priority: The functionality of this generic interface can be extended with an optional
border
argument as in getCountLoc.
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 3939 of file pm_arrayFind.F90.