Commit b6d847b1 authored by Liam Healy's avatar Liam Healy
Browse files

Define noise tests for all element types

The noise generator make-urand-vector and the noise test, now called
test-fft-noise, now work for all four element types, double-float,
single-float, (complex double-float), (complex single-float).  These
are meant to emulate the noise parts of GSL's test_complex_radix2,
test_real_radix2, test_complex_float_radix2, test_real_float_radix2,
test_complex_float_func, test_complex_func, test_real_float_func, and
test_real_func.  The real tests pass and the complex tests currently
fail.
parent d14dc372
;; Example FFT: transform a pulse (using the "clean" fft interface) ;; Example FFT: transform a pulse (using the "clean" fft interface)
;; Sumant Oemrawsingh, Sat Oct 31 2009 - 00:24 ;; Sumant Oemrawsingh, Sat Oct 31 2009 - 00:24
;; Time-stamp: <2009-11-09 22:29:03EST example.lisp> ;; Time-stamp: <2009-11-15 23:22:45EST example.lisp>
(in-package :gsl)
;;;;****************************************************************************
;;;; Pulse test
;;;;****************************************************************************
;;; Here is an example program modelled after the example given in Section ;;; Here is an example program modelled after the example given in Section
;;; 15.3 of the GSL Manual, which computes the FFT of a short pulse. To make ;;; 15.3 of the GSL Manual, which computes the FFT of a short pulse. To make
...@@ -16,8 +22,6 @@ ...@@ -16,8 +22,6 @@
;;; program in Section 15.4 of the GSL Manual: ;;; program in Section 15.4 of the GSL Manual:
;;; (fft-pulse-test '(complex double-float) 630) ;;; (fft-pulse-test '(complex double-float) 630)
(in-package :gsl)
(defun fft-pulse-test (element-type dimension) (defun fft-pulse-test (element-type dimension)
(assert (and (integerp dimension) (> dimension 20))) (assert (and (integerp dimension) (> dimension 20)))
(let ((pulse (make-marray element-type :dimensions dimension)) (let ((pulse (make-marray element-type :dimensions dimension))
...@@ -39,6 +43,10 @@ ...@@ -39,6 +43,10 @@
(fft-pulse-test 'double-float 128) (fft-pulse-test 'double-float 128)
(fft-pulse-test 'double-float 630)) (fft-pulse-test 'double-float 630))
;;;;****************************************************************************
;;;; Random vector transformations, from the GSL tests
;;;;****************************************************************************
;; From gsl-1.11/fft/urand.c ;; From gsl-1.11/fft/urand.c
(let ((urand-seed 1)) (let ((urand-seed 1))
(defun urand () (defun urand ()
...@@ -52,10 +60,14 @@ ...@@ -52,10 +60,14 @@
;; (make-urand-vector '(complex double-float) 5) ;; (make-urand-vector '(complex double-float) 5)
(defun make-urand-vector (element-type dimension &key (stride 1)) (defun make-urand-vector (element-type dimension &key (stride 1))
"Make a vector with random elements." "Make a vector with random elements."
(let ((vec (make-marray element-type :dimensions (list (* stride dimension))))) (let ((vec (make-marray `(complex ,(component-float-type element-type))
:dimensions (list (* stride dimension)))))
(loop for i from 0 below (* stride dimension) by stride (loop for i from 0 below (* stride dimension) by stride
do do
(setf (maref vec i) (complex (urand)))) (setf (maref vec i)
(if (subtypep element-type 'complex)
(coerce (complex (urand) (urand)) element-type)
(complex (coerce (urand) element-type)))))
vec)) vec))
(defun realpart-vector (complex-vector) (defun realpart-vector (complex-vector)
...@@ -69,14 +81,20 @@ ...@@ -69,14 +81,20 @@
(realpart (maref complex-vector i)))) (realpart (maref complex-vector i))))
real-vector)) real-vector))
(defun test-real-radix2 (element-type size &key (stride 1)) (defun test-fft-noise (element-type size &key (stride 1))
"Test for FFT; returns the DFT answer and the computed FFT answer. "Test for FFT with random data (noise); returns the DFT answer and the computed FFT answer.
See test_real_radix2 in fft/test.mc." See test_real_radix2 etc. in fft/test.mc."
(let ((random-vector (make-urand-vector (list 'complex element-type) size :stride stride))) (let* ((random-vector (make-urand-vector element-type size :stride stride))
(forward
(forward-fourier-transform
(if (subtypep element-type 'complex)
random-vector
(realpart-vector random-vector))
:stride stride)))
(values (values
(forward-discrete-fourier-transform random-vector :stride stride) (forward-discrete-fourier-transform random-vector :stride stride)
(unpack (if (subtypep element-type 'complex)
(forward-fourier-transform (realpart-vector random-vector) :stride stride) forward
:unpack-type 'complex :stride stride)))) (unpack forward :unpack-type 'complex :stride stride)))))
;;(test-real-radix2 'double-float 10 :stride 5) ;;(test-fft-noise 'double-float 10 :stride 5)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment