Skip to content

Commit 19cbb74

Browse files
committed
take the branch on the right when splitting rnd-lazy, etc.
1 parent bf51d25 commit 19cbb74

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

src/provisdom/math/random.clj

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,14 @@
374374

375375
(defn rnd-lazy
376376
"Creates a lazy sequence of random doubles from independent RNGs.
377-
377+
378378
Parameters:
379379
`rng` - Initial random number generator
380-
380+
381381
Returns a lazy sequence of doubles in [0, 1)."
382382
[rng]
383-
(map rand-double (rng-lazy rng)))
383+
(let [[_ rng-branch] (split rng)]
384+
(map rand-double (rng-lazy rng-branch))))
384385

385386
(s/fdef rnd-lazy
386387
:args (s/cat :rng ::rng)
@@ -394,7 +395,8 @@
394395
395396
Returns a lazy sequence of random longs."
396397
[rng]
397-
(map rand-long (rng-lazy rng)))
398+
(let [[_ rng-branch] (split rng)]
399+
(map rand-long (rng-lazy rng-branch))))
398400

399401
(s/fdef rnd-long-lazy
400402
:args (s/cat :rng ::rng)
@@ -674,7 +676,8 @@
674676
675677
Returns a vector of doubles in `[0, 1)`."
676678
[rng n]
677-
(mapv rand-double (take n (rng-lazy rng))))
679+
(let [[_ rng-branch] (split rng)]
680+
(mapv rand-double (take n (rng-lazy rng-branch)))))
678681

679682
(s/fdef rnd-doubles
680683
:args (s/cat :rng ::rng :n ::n)
@@ -703,7 +706,8 @@
703706
704707
Returns a vector of random longs."
705708
[rng n]
706-
(mapv rand-long (take n (rng-lazy rng))))
709+
(let [[_ rng-branch] (split rng)]
710+
(mapv rand-long (take n (rng-lazy rng-branch)))))
707711

708712
(s/fdef rnd-longs
709713
:args (s/cat :rng ::rng :n ::n)
@@ -732,7 +736,8 @@
732736
733737
Returns a vector of standard normal values (`mean=0`, `std=1`)."
734738
[rng n]
735-
(mapv (comp random-normal rand-double) (take n (rng-lazy rng))))
739+
(let [[_ rng-branch] (split rng)]
740+
(mapv (comp random-normal rand-double) (take n (rng-lazy rng-branch)))))
736741

737742
(s/fdef rnd-normals
738743
:args (s/cat :rng ::rng :n ::n)

test/provisdom/math/matrix_test.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@
368368
(random/bind-seed 0
369369
(t/is= [[]] (mx/rnd-matrix! 0 0)))
370370
(random/bind-seed 0
371-
(t/is= [[0.2961287401299688 0.8622994122994543]
372-
[0.07868284113948965 0.548683671433349]]
371+
(t/is= [[0.0023434341918648904 0.355610453579705]
372+
[0.8462878193318439 0.6940010275147983]]
373373
(mx/rnd-matrix! 2 2)))
374374
(random/bind-seed 0
375-
(t/is= [[0.2961287401299688 0.8622994122994543 0.07868284113948965]
376-
[0.548683671433349 0.11620266042486127 0.5772125043785624]]
375+
(t/is= [[0.0023434341918648904 0.355610453579705 0.8462878193318439]
376+
[0.6940010275147983 0.8119067024046234 0.14220466649514807]]
377377
(mx/rnd-matrix! 2 3)))))
378378

379379
(t/deftest rnd-reflection-matrix!-test
@@ -385,8 +385,8 @@
385385
(random/bind-seed 0
386386
(t/is= [[-1.0]] (mx/rnd-reflection-matrix! 1)))
387387
(random/bind-seed 0
388-
(t/is= [[0.7890118105552666 -0.6143780292330612]
389-
[-0.6143780292330612 -0.7890118105552668]]
388+
(t/is= [[0.9999131504400358 -0.013179210032561553]
389+
[-0.013179210032561553 -0.9999131504400356]]
390390
(mx/rnd-reflection-matrix! 2)))))
391391

392392
(t/deftest rnd-spectral-matrix!-test
@@ -398,8 +398,8 @@
398398
(random/bind-seed 0
399399
(t/is= [[2.0]] (mx/rnd-spectral-matrix! [2.0])))
400400
(random/bind-seed 0
401-
(t/is= [[2.9987560086952176 0.04986416644446639]
402-
[0.04986416644446639 1.0012439913047837]]
401+
(t/is= [[1.3315052401244662 -0.7437168520471685]
402+
[-0.7437168520471685 2.668494759875535]]
403403
(mx/rnd-spectral-matrix! [1.0 3.0])))))
404404

405405
(t/deftest sparse->matrix-test

test/provisdom/math/random_test.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@
102102
(t/with-instrument `random/rnd-lazy
103103
(t/is-spec-check random/rnd-lazy))
104104
(t/with-instrument :all
105-
(t/is= '(0.17343824438608113 0.5672348695804793 0.4407296095269242)
105+
(t/is= '(0.6647522234423441 0.9435968775103368 0.11310782708569878)
106106
(take 3 (random/rnd-lazy (random/rng 3))))))
107107

108108
(t/deftest rnd-long-lazy-test
109109
(t/with-instrument `random/rnd-long-lazy
110110
(t/is-spec-check random/rnd-long-lazy))
111111
(t/with-instrument :all
112-
(t/is= '(3199370906783531226 -7983107604874433585 8130026312649114387)
112+
(t/is= '(-6184229935439241264 -1040453965524906477 2086471138983279185)
113113
(take 3 (random/rnd-long-lazy (random/rng 3))))))
114114

115115
;;;BOUND RNG
@@ -167,14 +167,14 @@
167167
(t/with-instrument `random/rnd-lazy!
168168
(t/is-spec-check random/rnd-lazy!))
169169
(t/with-instrument :all
170-
(t/is= '(0.17343824438608113 0.5672348695804793 0.4407296095269242)
170+
(t/is= '(0.6647522234423441 0.9435968775103368 0.11310782708569878)
171171
(take 3 (random/bind-seed 3 (random/rnd-lazy!))))))
172172

173173
(t/deftest rnd-long-lazy!-test
174174
(t/with-instrument `random/rnd-long-lazy!
175175
(t/is-spec-check random/rnd-long-lazy!))
176176
(t/with-instrument :all
177-
(t/is= '(3199370906783531226 -7983107604874433585 8130026312649114387)
177+
(t/is= '(-6184229935439241264 -1040453965524906477 2086471138983279185)
178178
(take 3 (random/bind-seed 3 (random/rnd-long-lazy!))))))
179179

180180
;;;USE CLOCK
@@ -219,43 +219,43 @@
219219
(t/with-instrument `random/rnd-doubles
220220
(t/is-spec-check random/rnd-doubles))
221221
(t/with-instrument :all
222-
(t/is= [0.17343824438608113 0.5672348695804793 0.4407296095269242]
222+
(t/is= [0.6647522234423441 0.9435968775103368 0.11310782708569878]
223223
(random/rnd-doubles (random/rng 3) 3))
224224
(t/is= [] (random/rnd-doubles (random/rng 3) 0))))
225225

226226
(t/deftest rnd-doubles!-test
227227
(t/with-instrument `random/rnd-doubles!
228228
(t/is-spec-check random/rnd-doubles!))
229229
(t/with-instrument :all
230-
(t/is= [0.17343824438608113 0.5672348695804793 0.4407296095269242]
230+
(t/is= [0.6647522234423441 0.9435968775103368 0.11310782708569878]
231231
(random/bind-seed 3 (random/rnd-doubles! 3)))))
232232

233233
(t/deftest rnd-longs-test
234234
(t/with-instrument `random/rnd-longs
235235
(t/is-spec-check random/rnd-longs))
236236
(t/with-instrument :all
237-
(t/is= [3199370906783531226 -7983107604874433585 8130026312649114387]
237+
(t/is= [-6184229935439241264 -1040453965524906477 2086471138983279185]
238238
(random/rnd-longs (random/rng 3) 3))))
239239

240240
(t/deftest rnd-longs!-test
241241
(t/with-instrument `random/rnd-longs!
242242
(t/is-spec-check random/rnd-longs!))
243243
(t/with-instrument :all
244-
(t/is= [3199370906783531226 -7983107604874433585 8130026312649114387]
244+
(t/is= [-6184229935439241264 -1040453965524906477 2086471138983279185]
245245
(random/bind-seed 3 (random/rnd-longs! 3)))))
246246

247247
(t/deftest rnd-normals-test
248248
(t/with-instrument `random/rnd-normals
249249
(t/is-spec-check random/rnd-normals))
250250
(t/with-instrument :all
251-
(t/is= [-0.9406651398679139 0.16933867009164844 -0.14911965219889575]
251+
(t/is= [0.4254679878903436 1.58570499753794 -1.2101648206296136]
252252
(random/rnd-normals (random/rng 3) 3))))
253253

254254
(t/deftest rnd-normals!-test
255255
(t/with-instrument `random/rnd-normals!
256256
(t/is-spec-check random/rnd-normals!))
257257
(t/with-instrument :all
258-
(t/is= [-0.9406651398679139 0.16933867009164844 -0.14911965219889575]
258+
(t/is= [0.4254679878903436 1.58570499753794 -1.2101648206296136]
259259
(random/bind-seed 3 (random/rnd-normals! 3)))))
260260

261261
;;;CONVENIENCE FUNCTIONS

test/provisdom/math/tensor_test.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@
9090
(t/is-spec-check tensor/rnd-tensor! {:num-tests 20}))
9191
(t/with-instrument :all
9292
(random/bind-seed 0
93-
(t/is= 0.2961287401299688 (tensor/rnd-tensor! [])))
93+
(t/is= 0.0023434341918648904 (tensor/rnd-tensor! [])))
9494
(random/bind-seed 0
9595
(t/is= [] (tensor/rnd-tensor! [0])))
9696
(random/bind-seed 0
9797
(t/is= [[]] (tensor/rnd-tensor! [1 0])))
9898
(random/bind-seed 0
99-
(t/is= [[0.2961287401299688 0.8622994122994543 0.07868284113948965]
100-
[0.548683671433349 0.11620266042486127 0.5772125043785624]]
99+
(t/is= [[0.0023434341918648904 0.355610453579705 0.8462878193318439]
100+
[0.6940010275147983 0.8119067024046234 0.14220466649514807]]
101101
(tensor/rnd-tensor! [2 3])))))
102102

103103
;;INFO
@@ -143,7 +143,7 @@
143143
(boolean (and (seq indices)
144144
(> (first indices) v))))
145145
[1.0 0.5]))
146-
(t/is (tensor/every-kv? (fn [indices v]
146+
(t/is (tensor/every-kv? (fn [indices _v]
147147
(boolean (and (seq indices)
148148
(> (first indices) -1))))
149149
[1.0 0.5]))

test/provisdom/math/vector_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@
127127
(random/bind-seed 0
128128
(t/is= [] (vector/rnd-vector! 0)))
129129
(random/bind-seed 0
130-
(t/is= [0.2961287401299688] (vector/rnd-vector! 1)))
130+
(t/is= [0.0023434341918648904] (vector/rnd-vector! 1)))
131131
(random/bind-seed 0
132-
(t/is= [0.2961287401299688 0.8622994122994543] (vector/rnd-vector! 2)))))
132+
(t/is= [0.0023434341918648904 0.355610453579705] (vector/rnd-vector! 2)))))
133133

134134
(t/deftest sparse->vector-test
135135
(t/with-instrument `vector/sparse->vector

0 commit comments

Comments
 (0)