test-sphere is failing on Gambit
Bradley Lucier 02 Feb 2024 21:33 UTC
I made minimum modifications to get the SRFI and the test program to
work on Gambit (git diff results below).
Two tests are failing:
(reset-source!*)
(test-sphere (make-sphere-generator 1) (vector 1.0 1.0) 200
#t) ;; <<<<<<<<<<<<<<
(test-sphere (make-sphere-generator 2) (vector 1.0 1.0 1.0)
200 #t)
(test-sphere (make-sphere-generator 3) (vector 1.0 1.0 1.0
1.0) 200 #t)
(reset-source!*)
(test-sphere (make-ellipsoid-generator (vector 1.0 1.0))
(vector 1.0 1.0) 200 #t) ;; <<<<<<<<<<<
(test-sphere (make-ellipsoid-generator (vector 1.0 1.0
1.0)) (vector 1.0 1.0 1.0) 200 #t)
(test-sphere (make-ellipsoid-generator (vector 1.0 1.0 1.0
1.0)) (vector 1.0 1.0 1.0 1.0) 200 #t)
Now reset-source!* is defined as
(define (reset-source!*)
(random-source-pseudo-randomize! (current-random-source) 0 0))
i.e., it resets the current-random-source to the initial state of the
random number generator (in Gambit's case the SRFI 27 generator).
So, since (make-ellipsoid-generator (vector 1.0 1.0)) is exactly
(make-sphere-generator 1), these two sets of tests are identical, so if
one fails, the other one does, too.
The failure is:
"sphere-test.scm"@78.5-78.27: FAILED (test-assert (< zz 1)) GOT #f
*** 1 test failed after 688 tests
and the value of zz is 1.070418545004296.
The test passes if I take 400 samples instead of 200 samples.
I don't understand the reasoning behind this test, which checks that the
norm of the sum of the samples is < (\pi/2) * sqrt(number-of-samples).
Can someone give an explanation or a pointer?
Brad
heine:/tmp/srfi-194> gsi . srfi-194-test.scm
testing srfi-194
| testing Test clamp real number
| testing Test with-random-source basic syntax
| testing Test make-random-source-generator
| testing Test random int
| testing Test random real
| testing Test complex rectangular
| testing Test complex polar
| testing Test random bool
| testing Test random char
| testing Test random string
| testing Test Bernoulli
| testing Test categorical
| testing Test poisson
| testing Test normal
| testing Test exponential
| testing Test geometric
| testing Test uniform sampling
| testing Test Zipf sampling
| testing Test sphere
1.070418545004296
"sphere-test.scm"@78.5-78.27: FAILED (test-assert (< zz 1)) GOT #f
*** 1 test failed after 688 tests
heine:/tmp/srfi-194> git diff
diff --git a/sphere-test.scm b/sphere-test.scm
index a394322..6831fc9 100644
--- a/sphere-test.scm
+++ b/sphere-test.scm
@@ -74,6 +74,7 @@
(define (check-zero samples)
(define zz (norm-should-be-zero samples))
+ (pp zz)
(test-assert (< zz 1)))
; maximum allowed tolerance for radius deviation
diff --git a/srfi-194-test.scm b/srfi-194-test.scm
index b066f91..06f45ed 100644
--- a/srfi-194-test.scm
+++ b/srfi-194-test.scm
@@ -13,7 +13,7 @@
(scheme write)
(srfi 1)
(srfi 27)
- (srfi 133)
+ #;(srfi 133)
(srfi 194))
(cond-expand
@@ -137,7 +137,9 @@
(lambda ()
(make-random-integer-generator 0 10)))
5))
'(4 9 7 9 0)))
- (apply test-multiple-sources multiple-sources-testcase))))
+ (apply test-multiple-sources multiple-sources-testcase)))
+ (else
+ #f))
(test-group "Test make-random-source-generator"
(reset-source!)
diff --git a/srfi/194.scm b/srfi/194.scm
index fa875d7..3721e8d 100644
--- a/srfi/194.scm
+++ b/srfi/194.scm
@@ -2,13 +2,14 @@
; SPDX-License-Identifier: MIT
(define-library (srfi 194)
- (import (scheme base)
+ (import (gambit) ;; (scheme base)
(scheme case-lambda)
(scheme inexact)
(scheme complex)
(scheme write)
(srfi 27)
- (srfi 133))
+ #;(srfi 133)
+ )
(cond-expand
((library (srfi 158)) (import (srfi 158)))
diff --git a/zipf-test.scm b/zipf-test.scm
index 47c8cfa..9a34bd4 100644
--- a/zipf-test.scm
+++ b/zipf-test.scm
@@ -64,7 +64,8 @@
; Sequence 1..NVOCAB
(define seq
- (vector-unfold (lambda (i x) (values x (+ x 1))) NVOCAB 1))
+ #;(vector-unfold (lambda (i x) (values x (+ x 1))) NVOCAB 1)
+ (list->vector (iota NVOCAB 1)))
; Sequence 1/(k+QUE)^ESS
(define inv-pow (vector-map