Skip to content

Commit 1c2f467

Browse files
committed
Document RNG parameters and add test of rvalue passing into algorithm
1 parent a52320a commit 1c2f467

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

include/flc_random.i

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class SWIG_MERSENNE_TWISTER
3636
typedef SWIG_MERSENNE_RESULT_TYPE result_type;
3737

3838
SWIG_MERSENNE_TWISTER();
39-
explicit SWIG_MERSENNE_TWISTER(result_type);
40-
void seed(result_type);
41-
void discard(unsigned long long);
39+
explicit SWIG_MERSENNE_TWISTER(result_type seed_value);
40+
void seed(result_type seed_value);
41+
void discard(unsigned long long count);
4242
};
4343
} // namespace std
4444

src/flc_random.f90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,40 +169,40 @@ function swigf_new_Engine__SWIG_0() &
169169
self%swigdata = fresult
170170
end function
171171

172-
function swigf_new_Engine__SWIG_1(arg0) &
172+
function swigf_new_Engine__SWIG_1(seed_value) &
173173
result(self)
174174
use, intrinsic :: ISO_C_BINDING
175175
type(Engine) :: self
176-
integer(C_INT64_T), intent(in) :: arg0
176+
integer(C_INT64_T), intent(in) :: seed_value
177177
type(SwigClassWrapper) :: fresult
178178
integer(C_INT64_T) :: farg1
179179

180-
farg1 = arg0
180+
farg1 = seed_value
181181
fresult = swigc_new_Engine__SWIG_1(farg1)
182182
self%swigdata = fresult
183183
end function
184184

185-
subroutine swigf_Engine_seed(self, arg1)
185+
subroutine swigf_Engine_seed(self, seed_value)
186186
use, intrinsic :: ISO_C_BINDING
187187
class(Engine), intent(in) :: self
188-
integer(C_INT64_T), intent(in) :: arg1
188+
integer(C_INT64_T), intent(in) :: seed_value
189189
type(SwigClassWrapper) :: farg1
190190
integer(C_INT64_T) :: farg2
191191

192192
farg1 = self%swigdata
193-
farg2 = arg1
193+
farg2 = seed_value
194194
call swigc_Engine_seed(farg1, farg2)
195195
end subroutine
196196

197-
subroutine swigf_Engine_discard(self, arg1)
197+
subroutine swigf_Engine_discard(self, count)
198198
use, intrinsic :: ISO_C_BINDING
199199
class(Engine), intent(in) :: self
200-
integer(C_LONG_LONG), intent(in) :: arg1
200+
integer(C_LONG_LONG), intent(in) :: count
201201
type(SwigClassWrapper) :: farg1
202202
integer(C_LONG_LONG) :: farg2
203203

204204
farg1 = self%swigdata
205-
farg2 = arg1
205+
farg2 = count
206206
call swigc_Engine_discard(farg1, farg2)
207207
end subroutine
208208

test/test_algorithm.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ subroutine test_argsort()
100100
subroutine test_shuffle()
101101
use flc_algorithm, only : shuffle
102102
use flc_random, only : Engine
103+
use, intrinsic :: ISO_C_BINDING
103104
implicit none
104105
integer :: i
105106
integer, dimension(8) :: iarr = (/ ((i), i = -4, 3) /)
@@ -110,6 +111,11 @@ subroutine test_shuffle()
110111
call shuffle(rng, iarr)
111112
write(*,"(A,(8I4))") "Shuffled:", iarr
112113
end do
114+
call rng%release()
115+
116+
! Shuffle using temporary RNG using seed 12345
117+
call shuffle(Engine(12345_c_int64_t), iarr)
118+
write(*,"(A,(8I4))") "Shuffled:", iarr
113119
end subroutine
114120

115121
!-----------------------------------------------------------------------------!

0 commit comments

Comments
 (0)