Skip to content

Commit

Permalink
Update fft, paraffins (thanks to Brad/gambiteer).
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Jul 3, 2024
1 parent 45ff859 commit 57e4ce3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 41 deletions.
28 changes: 2 additions & 26 deletions src/fft.scm
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
;;; FFT - Fast Fourier Transform, translated from "Numerical Recipes in C"
(import (scheme base) (scheme inexact) (scheme read) (scheme write) (scheme time))

;;; We need R6RS div for this benchmark.

(define (div x y)
(cond ((and (exact-integer? x)
(exact-integer? y)
(>= x 0))
(quotient x y))
((< y 0)
;; x < 0, y < 0
(let* ((q (quotient x y))
(r (- x (* q y))))
(if (= r 0)
q
(+ q 1))))
(else
;; x < 0, y > 0
(let* ((q (quotient x y))
(r (- x (* q y))))
(if (= r 0)
q
(- q 1))))))

;;(define sin sin)

(define (four1 data)
(let ((n (vector-length data))
(pi*2 6.28318530717959)) ; to compute the inverse, negate this value
Expand All @@ -40,9 +16,9 @@
(let ((temp (vector-ref data (+ i 1))))
(vector-set! data (+ i 1) (vector-ref data (+ j 1)))
(vector-set! data (+ j 1) temp)))
(let loop2 ((m (div n 2)) (j j))
(let loop2 ((m (quotient n 2)) (j j))
(if (and (>= m 2) (>= j m))
(loop2 (div m 2) (- j m))
(loop2 (quotient m 2) (- j m))
(loop1 (+ i 2) (+ j m))))))

;; Danielson-Lanczos section
Expand Down
23 changes: 8 additions & 15 deletions src/paraffins.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

(import (scheme base) (scheme read) (scheme write) (scheme time))

;;; This benchmark uses the following R6RS procedures.

(define (div x y)
(quotient x y))

;;; End of (faked) R6RS procedures.

(define (gen n)
(let* ((n/2 (div n 2))
(let* ((n/2 (quotient n 2))
(radicals (make-vector (+ n/2 1) '(H))))

(define (rads-of-size n)
Expand Down Expand Up @@ -60,7 +53,7 @@
(if (odd? j)
'()
(let loop1 ((rads1
(vector-ref radicals (div j 2)))
(vector-ref radicals (quotient j 2)))
(lst
'()))
(if (null? rads1)
Expand Down Expand Up @@ -142,11 +135,11 @@

(define (three-partitions m)
(let loop1 ((lst '())
(nc1 (div m 3)))
(nc1 (quotient m 3)))
(if (< nc1 0)
lst
(let loop2 ((lst lst)
(nc2 (div (- m nc1) 2)))
(nc2 (quotient (- m nc1) 2)))
(if (< nc2 nc1)
(loop1 lst
(- nc1 1))
Expand All @@ -155,17 +148,17 @@

(define (four-partitions m)
(let loop1 ((lst '())
(nc1 (div m 4)))
(nc1 (quotient m 4)))
(if (< nc1 0)
lst
(let loop2 ((lst lst)
(nc2 (div (- m nc1) 3)))
(nc2 (quotient (- m nc1) 3)))
(if (< nc2 nc1)
(loop1 lst
(- nc1 1))
(let ((start (max nc2 (- (div (+ m 1) 2) (+ nc1 nc2)))))
(let ((start (max nc2 (- (quotient (+ m 1) 2) (+ nc1 nc2)))))
(let loop3 ((lst lst)
(nc3 (div (- m (+ nc1 nc2)) 2)))
(nc3 (quotient (- m (+ nc1 nc2)) 2)))
(if (< nc3 start)
(loop2 lst (- nc2 1))
(loop3 (cons (vector nc1 nc2 nc3 (- m (+ nc1 (+ nc2 nc3)))) lst)
Expand Down

0 comments on commit 57e4ce3

Please sign in to comment.