]> gitweb.factorcode.org Git - factor.git/commitdiff
fftw: adding some bindings to fftw3.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 4 Jun 2014 19:10:18 +0000 (12:10 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 4 Jun 2014 19:10:18 +0000 (12:10 -0700)
extra/fftw/authors.txt [new file with mode: 0644]
extra/fftw/ffi/ffi.factor [new file with mode: 0644]
extra/fftw/fftw.factor [new file with mode: 0644]
extra/fftw/summary.txt [new file with mode: 0644]

diff --git a/extra/fftw/authors.txt b/extra/fftw/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/fftw/ffi/ffi.factor b/extra/fftw/ffi/ffi.factor
new file mode 100644 (file)
index 0000000..711e856
--- /dev/null
@@ -0,0 +1,39 @@
+! Copyright (c) 2014 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license.
+
+USING: alien alien.c-types alien.destructors alien.libraries
+alien.libraries.finder alien.syntax kernel ;
+
+IN: fftw.ffi
+
+LIBRARY: fftw3
+
+<< "fftw3" dup find-library cdecl add-library >>
+
+TYPEDEF: double[2] fftw_complex
+
+TYPEDEF: void* fftw_plan
+
+CONSTANT: FFTW_FORWARD -1
+CONSTANT: FFTW_BACKWARD 1
+
+CONSTANT: FFTW_MEASURE 0
+CONSTANT: FFTW_DESTROY_INPUT 1
+CONSTANT: FFTW_UNALIGNED 2
+CONSTANT: FFTW_CONSERVE_MEMORY 4
+CONSTANT: FFTW_EXHAUSTIVE 8
+CONSTANT: FFTW_PRESERVE_INPUT 16
+CONSTANT: FFTW_PATIENT 32
+CONSTANT: FFTW_ESTIMATE 64
+
+FUNCTION: void* fftw_malloc ( size_t n ) ;
+
+FUNCTION: fftw_plan fftw_plan_dft_1d ( int n, void* in, void* out, int sign, int flags ) ;
+
+FUNCTION: void fftw_destroy_plan ( fftw_plan ) ;
+
+FUNCTION: void fftw_execute ( fftw_plan ) ;
+
+FUNCTION: void fftw_free ( void* ) ;
+
+DESTRUCTOR: fftw_free
diff --git a/extra/fftw/fftw.factor b/extra/fftw/fftw.factor
new file mode 100644 (file)
index 0000000..b1ac9ed
--- /dev/null
@@ -0,0 +1,45 @@
+! Copyright (c) 2014 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license.
+
+USING: alien.c-types destructors fftw.ffi fry kernel locals math
+math.functions math.vectors sequences sequences.private
+specialized-arrays ;
+SPECIALIZED-ARRAY: double
+SPECIALIZED-ARRAY: fftw_complex
+
+IN: fftw
+
+<PRIVATE
+
+: <fftw-array> ( length -- array )
+    [ fftw_complex heap-size * fftw_malloc &fftw_free ] keep
+    fftw_complex-array boa ;
+
+: >fftw-array ( seq -- array )
+    [ length <fftw-array> ] keep over '[
+        [ >rect 0 1 ] [ _ nth ] bi*
+        [ set-nth-unsafe ] curry bi-curry@ bi*
+    ] each-index ;
+
+: fftw-array> ( array -- seq )
+    [ first2 rect> ] { } map-as ;
+
+:: (fft1d) ( seq sign -- seq' )
+    seq length :> n
+    [
+        n
+        seq >fftw-array
+        n <fftw-array> [
+            sign FFTW_ESTIMATE fftw_plan_dft_1d
+            [ fftw_execute ] [ fftw_destroy_plan ] bi
+        ] keep fftw-array>
+    ] with-destructors ;
+
+PRIVATE>
+
+: fft1d ( seq -- seq' ) FFTW_FORWARD (fft1d) ;
+
+: ifft1d ( seq -- seq' ) FFTW_BACKWARD (fft1d) ;
+
+: correlate1d ( x y -- z )
+    [ fft1d ] [ reverse fft1d ] bi* v* ifft1d ;
diff --git a/extra/fftw/summary.txt b/extra/fftw/summary.txt
new file mode 100644 (file)
index 0000000..c075a01
--- /dev/null
@@ -0,0 +1 @@
+Bindings to FFTW3.