ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_swap::setSwapped Interface Reference

Return the two input scalar or array values a and b while their values are swapped.
More...

Detailed Description

Return the two input scalar or array values a and b while their values are swapped.

Parameters
[in,out]a: The input/output scalar, or array of the same rank, shape, and size other array-like arguments, of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type-parameter, or
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
  3. type logical of kind any supported by the processor (e.g., LK) or
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128).
On output, its value is swapped with the value of b.
[in,out]b: The input/output scalar, or array of the same rank, shape, and size other array-like arguments, of the same type and kind as the input a.
On output, its value is swapped with the value of a.
[in]inca: The input scalar integer of default kind IK, containing the stride of the input/output scalar character or vector argument a(:).
  1. A positive value implies the multiplication to be performed on the subset a(1 : 1 + (size(a) - 1) * inca : inca).
  2. A negative value implies the multiplication to be performed on the subset a(1 + (1 - size(a)) * inca : 1 : inca).
(optional, default = 1. It can be present only if a and b are of rank 1. It must be present if inca is present.)
[in]incb: The input scalar integer of default kind IK, containing the stride of the input/output scalar character or vector argument b(:).
  1. A positive value implies the multiplication to be performed on the subset b(1 : 1 + (size(b) - 1) * incb : incb).
  2. A negative value implies the multiplication to be performed on the subset b(1 + (1 - size(b)) * incb : 1 : incb).
(optional, default = 1. It can be present only if a and b are of rank 1. It must be present if inca is present.)


Possible calling interfaces

use pm_swap, only: setSwapped
call setSwapped(a, b) ! elemental
call setSwapped(a, b, inca, incb) ! `a` and `b` are scalars of type `character`.
call setSwapped(a(..), b(..)) ! elemental
call setSwapped(a(:), b(:), inca, incb)
Return the two input scalar or array values a and b while their values are swapped.
Definition: pm_swap.F90:139
This module contains procedures and generic interfaces for swapping values of intrinsic Fortran types...
Definition: pm_swap.F90:45
Warning
The condition len(a) == len(b) must hold for the corresponding input arguments.
The condition size(a(1::abs(inca))) == size(b(1::abs(incb))) must hold for the corresponding input arguments.
The rank and size of the two input array-like arguments must be the same.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
The procedures under discussion are elemental.
This generic interface implements a fast interface for vector input arguments.
However, the cases for input arguments of higher ranks are handled via the elemental property of the scalar interface.
BLAS/LAPACK equivalent:
The procedures under discussion combine, modernize, and extend the interface and functionalities of Version 3.11 of BLAS/LAPACK routine(s): SSWAP, DSWAP, CSWAP, ZSWAP.
In particular, swapping scalars or vectors or arrays of arbitrary intrinsic type (including character, integer, and logical), kind, and rank are possible.
See also
getMinMax
setMinMax


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, CK, RK ! all intrinsic types and kinds are supported.
4 use pm_io, only: display_type
5 use pm_swap, only: setSwapped
6
7 implicit none
8
9 type(display_type) :: disp
10
11 character(:, SK), allocatable :: a_SK, b_SK, Pair_SK(:)
12 integer(IK) :: a_IK, b_IK, Pair_IK(2)
13 logical(LK) :: a_LK, b_LK, Pair_LK(2)
14 complex(CK) :: a_CK, b_CK, Pair_CK(2)
15 real(RK) :: a_RK, b_RK, Pair_RK(2)
16
17 a_SK = "Hell" ; b_SK = "Heaven"
18 a_IK = 10_IK ; b_IK = 5_IK
19 a_LK = .true._LK ; b_LK = .false._LK
20 a_CK = (+10._CK, -5._CK); b_CK = (+5._CK, +15._CK)
21 a_RK = 10._RK ; b_RK = 5._RK
22
23 disp = display_type(file = "main.out.F90")
24
25 call disp%skip()
26 call disp%show("!%%%%%%%%%%%%%%")
27 call disp%show("! Swap scalars.")
28 call disp%show("!%%%%%%%%%%%%%%")
29 call disp%skip()
30
31 block
32 character(:), allocatable :: a, b
33 call disp%skip()
34 call disp%show("a = 'Heaven'")
35 a = 'Heaven'
36 call disp%show("b = 'Hell '")
37 b = 'Hell '
38 call disp%show("call setSwapped(a, b)")
39 call setSwapped(a, b)
40 call disp%show("a")
41 call disp%show( a , deliml = SK_"""" )
42 call disp%show("b")
43 call disp%show( b , deliml = SK_"""" )
44 call disp%skip()
45 end block
46
47 block
48 character(:), allocatable :: a, b
49 call disp%skip()
50 call disp%show("a = 'p r m n e'")
51 a = 'p r m n e'
52 call disp%show("b = ' a a o t '")
53 b = ' a a o t '
54 call disp%show("call setSwapped(a, b, inca = 2_IK, incb = 2_IK)")
55 call setSwapped(a, b, inca = 2_IK, incb = 2_IK)
56 call disp%show("a")
57 call disp%show( a , deliml = SK_"""" )
58 call disp%show("b")
59 call disp%show( b , deliml = SK_"""" )
60 call disp%skip()
61 end block
62
63 block
64 integer, allocatable :: a, b
65 call disp%skip()
66 call disp%show("a = 1")
67 a = 1
68 call disp%show("b = 2")
69 b = 2
70 call disp%show("call setSwapped(a, b)")
71 call setSwapped(a, b)
72 call disp%show("a")
73 call disp%show( a , deliml = SK_"""" )
74 call disp%show("b")
75 call disp%show( b , deliml = SK_"""" )
76 call disp%skip()
77 end block
78
79 block
80 logical, allocatable :: a, b
81 call disp%skip()
82 call disp%show("a = .false.")
83 a = .false.
84 call disp%show("b = .true.")
85 b = .true.
86 call disp%show("call setSwapped(a, b)")
87 call setSwapped(a, b)
88 call disp%show("a")
89 call disp%show( a , deliml = SK_"""" )
90 call disp%show("b")
91 call disp%show( b , deliml = SK_"""" )
92 call disp%skip()
93 end block
94
95 block
96 complex, allocatable :: a, b
97 call disp%skip()
98 call disp%show("a = 1")
99 a = 1
100 call disp%show("b = 2")
101 b = 2
102 call disp%show("call setSwapped(a, b)")
103 call setSwapped(a, b)
104 call disp%show("a")
105 call disp%show( a , deliml = SK_"""" )
106 call disp%show("b")
107 call disp%show( b , deliml = SK_"""" )
108 call disp%skip()
109 end block
110
111 block
112 real, allocatable :: a, b
113 call disp%skip()
114 call disp%show("a = 1")
115 a = 1
116 call disp%show("b = 2")
117 b = 2
118 call disp%show("call setSwapped(a, b)")
119 call setSwapped(a, b)
120 call disp%show("a")
121 call disp%show( a , deliml = SK_"""" )
122 call disp%show("b")
123 call disp%show( b , deliml = SK_"""" )
124 call disp%skip()
125 end block
126
127 call disp%skip()
128 call disp%show("!%%%%%%%%%%%%%%")
129 call disp%show("! Swap vectors.")
130 call disp%show("!%%%%%%%%%%%%%%")
131 call disp%skip()
132
133 block
134 character(6), allocatable :: a(:), b(:)
135 call disp%skip()
136 call disp%show("a = ['Heaven', 'Hell ']")
137 a = ['Heaven', 'Hell ']
138 call disp%show("b = ['Hell ', 'Heaven']")
139 b = ['Hell ', 'Heaven']
140 call disp%show("call setSwapped(a, b)")
141 call setSwapped(a, b)
142 call disp%show("a")
143 call disp%show( a , deliml = SK_"""" )
144 call disp%show("b")
145 call disp%show( b , deliml = SK_"""" )
146 call disp%skip()
147 end block
148
149 block
150 integer, allocatable :: a(:), b(:)
151 call disp%skip()
152 call disp%show("a = [1, 2]")
153 a = [1, 2]
154 call disp%show("b = [2, 1]")
155 b = [2, 1]
156 call disp%show("call setSwapped(a, b)")
157 call setSwapped(a, b)
158 call disp%show("a")
159 call disp%show( a , deliml = SK_"""" )
160 call disp%show("b")
161 call disp%show( b , deliml = SK_"""" )
162 call disp%skip()
163 end block
164
165 block
166 logical, allocatable :: a(:), b(:)
167 call disp%skip()
168 call disp%show("a = [.false., .true.]")
169 a = [.false., .true.]
170 call disp%show("b = [.true., .false.]")
171 b = [.true., .false.]
172 call disp%show("call setSwapped(a, b)")
173 call setSwapped(a, b)
174 call disp%show("a")
175 call disp%show( a , deliml = SK_"""" )
176 call disp%show("b")
177 call disp%show( b , deliml = SK_"""" )
178 call disp%skip()
179 end block
180
181 block
182 complex, allocatable :: a(:), b(:)
183 call disp%skip()
184 call disp%show("a = [1, 2]")
185 a = [1, 2]
186 call disp%show("b = [2, 1]")
187 b = [2, 1]
188 call disp%show("call setSwapped(a, b)")
189 call setSwapped(a, b)
190 call disp%show("a")
191 call disp%show( a , deliml = SK_"""" )
192 call disp%show("b")
193 call disp%show( b , deliml = SK_"""" )
194 call disp%skip()
195 end block
196
197 block
198 real, allocatable :: a(:), b(:)
199 call disp%skip()
200 call disp%show("a = [1, 2]")
201 a = [1, 2]
202 call disp%show("b = [2, 1]")
203 b = [2, 1]
204 call disp%show("call setSwapped(a, b)")
205 call setSwapped(a, b)
206 call disp%show("a")
207 call disp%show( a , deliml = SK_"""" )
208 call disp%show("b")
209 call disp%show( b , deliml = SK_"""" )
210 call disp%skip()
211 end block
212
213 call disp%skip()
214 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
215 call disp%show("! Swap strided vectors.")
216 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%")
217 call disp%skip()
218
219 block
220 integer(IK) , parameter :: DUM = huge(DUM)
221 integer, allocatable :: a(:), b(:)
222 call disp%skip()
223 call disp%show("a = [1, 2, 3, 4, 5]")
224 a = [1, 2, 3, 4, 5]
225 call disp%show("b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]")
226 b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
227 call disp%show("call setSwapped(a, b, inca = 1_IK, incb = 2_IK)")
228 call setSwapped(a, b, inca = 1_IK, incb = 2_IK)
229 call disp%show("a")
230 call disp%show( a , deliml = SK_"""" )
231 call disp%show("b")
232 call disp%show( b , deliml = SK_"""" )
233 call disp%skip()
234 end block
235
236 block
237 integer(IK) , parameter :: DUM = huge(DUM)
238 integer, allocatable :: a(:), b(:)
239 call disp%skip()
240 call disp%show("a = [1, 2, 3, 4, 5]")
241 a = [1, 2, 3, 4, 5]
242 call disp%show("b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]")
243 b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
244 call disp%show("call setSwapped(a, b, inca = 1_IK, incb = -2_IK)")
245 call setSwapped(a, b, inca = 1_IK, incb = -2_IK)
246 call disp%show("a")
247 call disp%show( a , deliml = SK_"""" )
248 call disp%show("b")
249 call disp%show( b , deliml = SK_"""" )
250 call disp%skip()
251 end block
252
253 block
254 integer(IK) , parameter :: DUM = huge(DUM)
255 integer, allocatable :: a(:), b(:)
256 call disp%skip()
257 call disp%show("a = [1, 2, 3, 4, 5]")
258 a = [1, 2, 3, 4, 5]
259 call disp%show("b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]")
260 b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
261 call disp%show("call setSwapped(a(1:1), b, inca = 0_IK, incb = 2_IK)")
262 call setSwapped(a(1:1), b, inca = 0_IK, incb = 2_IK)
263 call disp%show("a")
264 call disp%show( a , deliml = SK_"""" )
265 call disp%show("b")
266 call disp%show( b , deliml = SK_"""" )
267 call disp%skip()
268 end block
269
270 call disp%skip()
271 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
272 call disp%show("! Swap strided vectors (blass call).")
273 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
274 call disp%skip()
275
276 block
277 real(IK) , parameter :: DUM = huge(DUM)
278 real, allocatable :: a(:), b(:)
279 call disp%skip()
280 call disp%show("a = [real :: 1, 2, 3, 4, 5]")
281 a = [real :: 1, 2, 3, 4, 5]
282 call disp%show("b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]")
283 b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
284 call disp%show("call setSwapped(a, b, inca = 1_IK, incb = 2_IK)")
285 call setSwapped(a, b, inca = 1_IK, incb = 2_IK)
286 call disp%show("a")
287 call disp%show( a , deliml = SK_"""" )
288 call disp%show("b")
289 call disp%show( b , deliml = SK_"""" )
290 call disp%skip()
291 end block
292
293 block
294 integer(IK) , parameter :: DUM = huge(DUM)
295 real, allocatable :: a(:), b(:)
296 call disp%skip()
297 call disp%show("a = [real :: 1, 2, 3, 4, 5]")
298 a = [real :: 1, 2, 3, 4, 5]
299 call disp%show("b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]")
300 b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
301 call disp%show("call setSwapped(a, b, inca = 1_IK, incb = -2_IK)")
302 call setSwapped(a, b, inca = 1_IK, incb = -2_IK)
303 call disp%show("a")
304 call disp%show( a , deliml = SK_"""" )
305 call disp%show("b")
306 call disp%show( b , deliml = SK_"""" )
307 call disp%skip()
308 end block
309
310 block
311 real(IK) , parameter :: DUM = huge(DUM)
312 real, allocatable :: a(:), b(:)
313 call disp%skip()
314 call disp%show("a = [real :: 1, 2, 3, 4, 5]")
315 a = [real :: 1, 2, 3, 4, 5]
316 call disp%show("b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]")
317 b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
318 call disp%show("call setSwapped(a, b(1:1), inca = 1_IK, incb = 0_IK)")
319 call setSwapped(a, b(1:1), inca = 1_IK, incb = 0_IK)
320 call disp%show("a")
321 call disp%show( a , deliml = SK_"""" )
322 call disp%show("b")
323 call disp%show( b , deliml = SK_"""" )
324 call disp%skip()
325 end block
326
327 call disp%skip()
328 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
329 call disp%show("! Swap higher-rank arrays.")
330 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
331 call disp%skip()
332
333 block
334 integer(IK) , parameter :: DUM = huge(DUM)
335 integer, allocatable :: a(:,:), b(:,:)
336 call disp%skip()
337 call disp%show("a = reshape([1, 2, 3, 4, 5, 6], [2,3])")
338 a = reshape([1, 2, 3, 4, 5, 6], [2,3])
339 call disp%show("b = reshape([-1 , -2 , -3, DUM, DUM, DUM, -4, -5, -6], [3, 3], order = [2, 1])")
340 b = reshape([-1 , -2 , -3, DUM, DUM, DUM, -4, -5, -6], [3, 3], order = [2, 1])
341 call disp%show("a")
342 call disp%show( a , deliml = SK_"""" )
343 call disp%show("b")
344 call disp%show( b , deliml = SK_"""" )
345 call disp%show("call setSwapped(a, b(1::2, :))")
346 call setSwapped(a, b(1::2, :))
347 call disp%show("a")
348 call disp%show( a , deliml = SK_"""" )
349 call disp%show("b")
350 call disp%show( b , deliml = SK_"""" )
351 call disp%skip()
352 end block
353
354end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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 IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
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
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%
3! Swap scalars.
4!%%%%%%%%%%%%%%
5
6
7a = 'Heaven'
8b = 'Hell '
9call setSwapped(a, b)
10a
11"Hell "
12b
13"Heaven"
14
15
16a = 'p r m n e'
17b = ' a a o t '
18call setSwapped(a, b, inca = 2_IK, incb = 2_IK)
19a
20" "
21b
22"paramonte"
23
24
25a = 1
26b = 2
27call setSwapped(a, b)
28a
29"+2"
30b
31"+1"
32
33
34a = .false.
35b = .true.
36call setSwapped(a, b)
37a
38"T"
39b
40"F"
41
42
43a = 1
44b = 2
45call setSwapped(a, b)
46a
47"+2.00000000, +0.00000000"
48b
49"+1.00000000, +0.00000000"
50
51
52a = 1
53b = 2
54call setSwapped(a, b)
55a
56"+2.00000000"
57b
58"+1.00000000"
59
60
61!%%%%%%%%%%%%%%
62! Swap vectors.
63!%%%%%%%%%%%%%%
64
65
66a = ['Heaven', 'Hell ']
67b = ['Hell ', 'Heaven']
68call setSwapped(a, b)
69a
70"Hell ", "Heaven"
71b
72"Heaven", "Hell "
73
74
75a = [1, 2]
76b = [2, 1]
77call setSwapped(a, b)
78a
79"+2", "+1"
80b
81"+1", "+2"
82
83
84a = [.false., .true.]
85b = [.true., .false.]
86call setSwapped(a, b)
87a
88"T", "F"
89b
90"F", "T"
91
92
93a = [1, 2]
94b = [2, 1]
95call setSwapped(a, b)
96a
97"+2.00000000, +0.00000000", "+1.00000000, +0.00000000"
98b
99"+1.00000000, +0.00000000", "+2.00000000, +0.00000000"
100
101
102a = [1, 2]
103b = [2, 1]
104call setSwapped(a, b)
105a
106"+2.00000000", "+1.00000000"
107b
108"+1.00000000", "+2.00000000"
109
110
111!%%%%%%%%%%%%%%%%%%%%%%
112! Swap strided vectors.
113!%%%%%%%%%%%%%%%%%%%%%%
114
115
116a = [1, 2, 3, 4, 5]
117b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
118call setSwapped(a, b, inca = 1_IK, incb = 2_IK)
119a
120"-1", "-2", "-3", "-4", "-5"
121b
122"+1", "+2147483647", "+2", "+2147483647", "+3", "+2147483647", "+4", "+2147483647", "+5"
123
124
125a = [1, 2, 3, 4, 5]
126b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
127call setSwapped(a, b, inca = 1_IK, incb = -2_IK)
128a
129"-5", "-4", "-3", "-2", "-1"
130b
131"+5", "+2147483647", "+4", "+2147483647", "+3", "+2147483647", "+2", "+2147483647", "+1"
132
133
134a = [1, 2, 3, 4, 5]
135b = [-1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
136call setSwapped(a(1:1), b, inca = 0_IK, incb = 2_IK)
137a
138"-5", "+2", "+3", "+4", "+5"
139b
140"+1", "+2147483647", "-1", "+2147483647", "-2", "+2147483647", "-3", "+2147483647", "-4"
141
142
143!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144! Swap strided vectors (blass call).
145!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
147
148a = [real :: 1, 2, 3, 4, 5]
149b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
150call setSwapped(a, b, inca = 1_IK, incb = 2_IK)
151a
152"-1.00000000", "-2.00000000", "-3.00000000", "-4.00000000", "-5.00000000"
153b
154"+1.00000000", "+0.340282347E+39", "+2.00000000", "+0.340282347E+39", "+3.00000000", "+0.340282347E+39", "+4.00000000", "+0.340282347E+39", "+5.00000000"
155
156
157a = [real :: 1, 2, 3, 4, 5]
158b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
159call setSwapped(a, b, inca = 1_IK, incb = -2_IK)
160a
161"-5.00000000", "-4.00000000", "-3.00000000", "-2.00000000", "-1.00000000"
162b
163"+5.00000000", "+0.214748365E+10", "+4.00000000", "+0.214748365E+10", "+3.00000000", "+0.214748365E+10", "+2.00000000", "+0.214748365E+10", "+1.00000000"
164
165
166a = [real :: 1, 2, 3, 4, 5]
167b = [real :: -1, DUM , -2, DUM , -3, DUM , -4, DUM , -5]
168call setSwapped(a, b(1:1), inca = 1_IK, incb = 0_IK)
169a
170"-1.00000000", "+1.00000000", "+2.00000000", "+3.00000000", "+4.00000000"
171b
172"+5.00000000", "+0.340282347E+39", "-2.00000000", "+0.340282347E+39", "-3.00000000", "+0.340282347E+39", "-4.00000000", "+0.340282347E+39", "-5.00000000"
173
174
175!%%%%%%%%%%%%%%%%%%%%%%%%%
176! Swap higher-rank arrays.
177!%%%%%%%%%%%%%%%%%%%%%%%%%
178
179
180a = reshape([1, 2, 3, 4, 5, 6], [2,3])
181b = reshape([-1 , -2 , -3, DUM, DUM, DUM, -4, -5, -6], [3, 3], order = [2, 1])
182a
183"+1", "+3", "+5"
184"+2", "+4", "+6"
185b
186"-1", "-2", "-3"
187"+2147483647", "+2147483647", "+2147483647"
188"-4", "-5", "-6"
189call setSwapped(a, b(1::2, :))
190a
191"-1", "-2", "-3"
192"-4", "-5", "-6"
193b
194"+1", "+3", "+5"
195"+2147483647", "+2147483647", "+2147483647"
196"+2", "+4", "+6"
197
198
Test:
test_pm_swap
Todo:
This generic interface can be extended to take an optional mask input argument that leads to selective swapping of array elements:
  \param[in]      mask    :   The input scalar, or array of the same rank, shape, and size as other array-like arguments, of type `logical` of default kind \LK.<br>
                              If present, then swapping will be done only if the corresponding value in `mask` is `.true.`.<br>
                              (**optional**, default = `.true.`.)


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.

  1. 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.
  2. 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.

Author:
Amir Shahmoradi, Thursday 1:45 AM, August 22, 2019, Dallas, TX

Definition at line 139 of file pm_swap.F90.


The documentation for this interface was generated from the following file: