ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation. |
Replace the requested instances of the input pattern
with the input replacement
in the allocatable input/output array
.
More...
Replace the requested instances of the input pattern
with the input replacement
in the allocatable input/output array
.
If an input vector of instance
is specified, representing the specific instances of pattern to change, then only those specific instances will be changed.
[in,out] | array | : The input/output allocatable array of rank 1 of either
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.On output, the array will be possibly (if needed) reallocated to its new value with the requested instances of pattern replaced with replacement. |
[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... Definition: pm_kind.F90:268 integer, parameter LK The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(.... Definition: pm_kind.F90:541 integer, parameter IK The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper... Definition: pm_kind.F90:540 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... Definition: pm_kind.F90:543 integer, parameter CK The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I... Definition: pm_kind.F90:542 integer, parameter SK The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero... Definition: pm_kind.F90:539 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
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
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.) |
Possible calling interfaces ⛓
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.pure
in release
build and impure
in debug
and testing
builds.impure
when the user-specified external
procedure iseq
is specified as input argument."Fortran" == "Fortran "
yields .true.
.array
an allocatable
with intent(inout)
is to make the procedures potentially more efficient with a well-defined behavior.intent(out), allocatable :: arrayNew(:)
argument along with an intent(in), contiguous :: array(:)
.array
to arrayNew
when no replacement practically has occurred.arrayNew
must be set a priori by the user which is only determined within the algorithm.array
in-place.allocatable, intent(inout) :: array
argument is guaranteed to have the same lower bound as before, although its upper bound is potentially different.
Example usage ⛓
ifort
compiler ⛓ ifort
compiler ⛓ gfortran
compiler ⛓ intent(inout), allocatable :: array
argument as opposed to returning the result in a new array is that the size of the output array is not known a priori, but is determined within the algorithm.allocatable
dummy arguments is to be truly avoided, a new interface can be added where the output is returned in a contiguous
ArrayReplaced
while the input array remains intact.pattern
and replacement
arguments.pattern
and replacement
are arrays of length 1
. See pm_arraySplit for an example relevant benchmark about this matter.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.
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.
Definition at line 8076 of file pm_arrayReplace.F90.