Giter Club home page Giter Club logo

cl-cffi-fftw3's Introduction

cl-cffi-fftw3

description

cl-cffi-fftw3 is a foreign function binding to call fftw3 from common lisp using cffi. i want it to run in sbcl and clozure common lisp. my application are in particular multi-dimensional complex transforms with arbitrary array sizes.

usage:

prepare-threads [n]

Initialize fftw3_threads to use n threads. On Linux the optional parameter n defaults to the number of processors. This function doesn't have to be called, if only one thread should be used for calculations.

ft in [out]

Plan and execute an out-of-place Fourier transform of the array 'in'. The input array 'in' must be a displaced one-dimensional array. The transform is calculated out-of-place if no output array 'out' is given.

In Clozure Common Lisp the fastest speed can be obtained when preallocated arrays (using the function make-foreign-complex-array-as-double

make-foreign-complex-array-as-double dimension

This function only makes sense for Clozure Common Lisp. It allocates an array on the foreign stack and registers a finalizer to free the memory when the reference is no longer used. dimension is a list of positive integers, e.g. '(17 23). Note that Clozure Common Lisp doesn't support (complex double-float) element types as heap-ivector. Until I find a better solution make-foreign-complex-array-as-double returns a double-float array with dimensions (17 23 2), i.e. the last dimension indexes real (0) and imaginary parts (1).

example:

(let* ((w 37)
       (h 12)
       ;; allocate a 1d array
       (a1 (make-array (* w h) :element-type '(complex double-float)))
       ;; create a 2d array for access
       (a (make-array (list h w) :element-type '(complex double-float)
		      :displaced-to a1)))
  
  ;; fill the 2d array with a sinosoidal grating    		    
  (dotimes (i w)
    (dotimes (j h)
      (setf (aref a j i) (complex (sin (* 8 pi (+ (/ i w) (/ j h))))))))

  ;; call fftw
  (defparameter *bla* (fftw:ft a))

  ;; print out each element of the array. scale data to lie within 0..9
  (progn
    (terpri)
    (destructuring-bind (h w) (array-dimensions *bla*)
      (dotimes (j h)
	(dotimes (i w)
	  (format t "~1,'0d" (floor (abs (aref *bla* j i)) (/ (* h w) 9))))
	(terpri)))))

output:

0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000400000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000004000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000

supported implementations:

  • SBCL .. currently doesn't work (linux64)
  • CCL .. works (linux64, win32 8.1)

todo

  • for best performance fftw3 wants its arrays to be allocated with a particular alignment. i haven't checked if this is the case

cl-cffi-fftw3's People

Contributors

plops avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.