Fixed benchmarks to work with Nonnegative-Floats.

This commit is contained in:
Vincent St-Amour 2010-06-30 19:25:18 -04:00
parent f478b74ed6
commit e4cd5329fb
11 changed files with 31 additions and 24 deletions

View File

@ -278,6 +278,7 @@
;
; The components tx, ty, and tz are the translation vector.
(: tfo-id (Vectorof Float))
(define tfo-id ; the identity transformation matrix
'#(1.0 0.0 0.0
0.0 1.0 0.0

View File

@ -12,7 +12,7 @@
(define N.0 (exact->inexact N))
(define 2/N (/ 2.0 N.0))
(define Crs
(let ([v (make-vector N 0.0)])
(let: ([v : (Vectorof Float) (make-vector N 0.0)])
(for ([x (in-range N)])
(vector-set! v x (- (/ (* 2 x) N.0) 1.5)))
v))

View File

@ -91,7 +91,7 @@
(define (no-islands? mask)
(let ([zeros (zero-count mask)])
(and (zeros . >= . 5)
(let loop ([mask mask] [zeros zeros])
(let: loop : Boolean ([mask : Integer mask] [zeros : Integer zeros])
(if (= mask #x3FFFFFFFFFFFF)
#t
(let* ([p (assert (find-free-cell mask))]

View File

@ -76,7 +76,8 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let loop-i ([i *system*] [px 0.0] [py 0.0] [pz 0.0])
(let: loop-i : Void ([i : (Listof body) *system*]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(if (null? i)
(begin
(set-body-vx! (car *system*) (/ (- px) +solar-mass+))
@ -91,7 +92,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let loop-o ([o *system*] [e 0.0])
(let: loop-o : Float ([o : (Listof body) *system*] [e : Float 0.0])
(if (null? o)
e
(let* ([o1 (car o)]

View File

@ -27,6 +27,7 @@ Correct output N = 1000 is
(define +dt+ 0.01)
(: make-body (Float * -> (Vectorof Float)))
(define make-body vector)
(define-syntax-rule (deffield n getter setter)
(begin (define-syntax-rule (getter b) (vector-ref b n))
@ -84,7 +85,8 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let loop-i ([i 0] [px 0.0] [py 0.0] [pz 0.0])
(let: loop-i : Void ([i : Natural 0]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(if (= i *system-size*)
(begin
(set-body-vx! (vector-ref *system* 0) (/ (- px) +solar-mass+))
@ -99,7 +101,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let loop-o ([o 0] [e 0.0])
(let: loop-o : Float ([o : Natural 0] [e : Float 0.0])
(if (= o *system-size*)
e
(let* ([o1 (vector-ref *system* o)]

View File

@ -90,7 +90,8 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let loop-i ([i 0] [px 0.0] [py 0.0] [pz 0.0])
(let: loop-i : Void ([i : Natural 0]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(if (unsafe-fx= i *system-size*)
(begin
(set-body-vx! (unsafe-vector-ref *system* 0) (fl/ (fl- 0.0 px) +solar-mass+))
@ -105,7 +106,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let loop-o ([o 0] [e 0.0])
(let: loop-o : Float ([o : Natural 0] [e : Float 0.0])
(if (unsafe-fx= o *system-size*)
e
(let* ([o1 (unsafe-vector-ref *system* o)]

View File

@ -85,7 +85,8 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let loop-i ([i 0] [px 0.0] [py 0.0] [pz 0.0])
(let: loop-i : Void ([i : Natural 0]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(if (= i *system-size*)
(begin
(set-body-vx! (vector-ref *system* 0) (fl/ (fl- 0.0 px) +solar-mass+))
@ -100,7 +101,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let loop-o ([o 0] [e 0.0])
(let: loop-o : Float ([o : Natural 0] [e : Float 0.0])
(if (= o *system-size*)
e
(let* ([o1 (vector-ref *system* o)]

View File

@ -77,7 +77,8 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let loop-i ([i *system*] [px 0.0] [py 0.0] [pz 0.0])
(let: loop-i : Void ([i : (Listof body) *system*]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(if (null? i)
(begin
(set-body-vx! (car *system*) (fl/ (fl- 0.0 px) +solar-mass+))
@ -92,7 +93,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let loop-o ([o *system*] [e 0.0])
(let: loop-o : Float ([o : (Listof body) *system*] [e : Float 0.0])
(if (null? o)
e
(let* ([o1 (car o)]

View File

@ -8,8 +8,8 @@
(: Approximate (Natural -> Float))
(define (Approximate n)
(let ([u (make-vector n 1.0)]
[v (make-vector n 0.0)])
(let: ([u : (Vectorof Float) (make-vector n 1.0)]
[v : (Vectorof Float) (make-vector n 0.0)])
;; 20 steps of the power method
(for: : Void ([i : Natural (in-range 10)])
(MultiplyAtAv n u v)
@ -51,7 +51,7 @@
;; multiply vector v by matrix A and then by matrix A transposed
(: MultiplyAtAv (Natural (Vectorof Float) (Vectorof Float) -> Void))
(define (MultiplyAtAv n v AtAv)
(let ([u (make-vector n 0.0)])
(let: ([u : (Vectorof Float) (make-vector n 0.0)])
(MultiplyAv n v u)
(MultiplyAtv n u AtAv)))

View File

@ -45,8 +45,8 @@
(define (MultiplyAv n v Av)
(for ([i (in-range n)])
(flvector-set! Av i
(for/fold ([r 0.0])
([j (in-range n)])
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(fl+ r (fl* (A i j) (flvector-ref v j)))))))
;; multiply vector v by matrix A transposed
@ -54,8 +54,8 @@
(define (MultiplyAtv n v Atv)
(for ([i (in-range n)])
(flvector-set! Atv i
(for/fold ([r 0.0])
([j (in-range n)])
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(fl+ r (fl* (A j i) (flvector-ref v j)))))))
;; multiply vector v by matrix A and then by matrix A transposed

View File

@ -18,7 +18,7 @@
;; B=AtA A multiplied by A transposed
;; v.Bv /(v.v) eigenvalue of v
(let loop ([i 0][vBv 0.0][vv 0.0])
(let: loop : Float ([i : Natural 0][vBv : Float 0.0][vv : Float 0.0])
(if (= i n)
(flsqrt (fl/ vBv vv))
(let ([vi (flvector-ref v i)])
@ -38,8 +38,8 @@
(define (MultiplyAv n v Av)
(for: : Void ([i : Natural (in-range n)])
(flvector-set! Av i
(for/fold ([r 0.0])
([j (in-range n)])
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(fl+ r (fl* (A i j) (flvector-ref v j)))))))
;; multiply vector v by matrix A transposed
@ -47,8 +47,8 @@
(define (MultiplyAtv n v Atv)
(for: : Void ([i : Natural (in-range n)])
(flvector-set! Atv i
(for/fold ([r 0.0])
([j (in-range n)])
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(fl+ r (fl* (A j i) (flvector-ref v j)))))))
;; multiply vector v by matrix A and then by matrix A transposed