packages feed

fftwRaw (empty) → 0.1.0.0

raw patch · 4 files changed

+254/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Adam Walker++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Adam Walker nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Numeric/FFTW.hsc view
@@ -0,0 +1,186 @@+{-| Bindings to FFTW.++Example usage:++> import Foreign.Marshal.Array+> import Data.Complex+> import Foreign.Storable.Complex+> import FFTW+> +> main = do+>     inA  <- fftwAllocComplex 1024+>     outA <- fftwAllocComplex 1024+> +>     plan <- planDFT1d 1024 inA outA Forward fftwEstimate+> +>     pokeArray inA $ map (:+ 0) [0..1023]+>     execute plan+>     res <- peekArray 1024 outA+> +>     fftwFree inA+>     fftwFree outA+> +>     print res+-}++module Numeric.FFTW (+    -- * Memory allocation functions+    fftwMalloc,+    fftwFree,+    fftwFreePtr,+    fftwAllocReal,+    fftwAllocComplex,++    -- * FFT planning flags+    Direction(..),+    Flag(),+    -- ** Planning rigor flags+    fftwMeasure,+    fftwExhaustive,+    fftwPatient,+    fftwEstimate,+    fftwWisdomOnly,+    -- ** Algorithm restriction flags+    fftwDestroyInput,+    fftwUnaligned,+    fftwPreserveInput,++    -- * FFT planning+    FFTWPlan,+    planDFT1d,+    planDFTR2C1d,++    -- * FFT execution+    execute,+    executeDFT,+    executeDFTR2C+    ) where++import Foreign.C.Types+import Foreign.Ptr+import Data.Word+import Data.Complex+import Control.Monad+import Data.Bits+import Data.Monoid++#include <fftw3.h>++foreign import ccall unsafe "fftw_malloc" +    c_fftwMalloc :: CUInt -> IO (Ptr a)++-- | Like malloc, but ensures that the pointer obeys the alignment restrictions of FFTW (e.g. for SIMD acceleration). You probably want to use 'fftwAllocReal' or 'fftwAllocComplex' instead.+fftwMalloc :: Word32 -- ^ size+           -> IO (Ptr a)+fftwMalloc = c_fftwMalloc . fromIntegral ++-- | Free a pointer returned by 'fftwMalloc', 'fftwAllocReal', or 'fftwAllocComplex'+foreign import ccall unsafe "fftw_free"+    fftwFree :: Ptr a -- ^ the pointer to be freed+             -> IO ()++-- | A function pointer to @fftwFree@.+foreign import ccall unsafe "&fftw_free"+    fftwFreePtr :: FunPtr (Ptr a -> IO ())++foreign import ccall unsafe "fftw_alloc_real"+    c_fftwAllocReal :: CUInt -> IO (Ptr CDouble)++-- | Allocates an array of Doubles. It ensures that the pointer obeys the alignment restrictions of FFTW (e.g. for SIMD acceleration).+fftwAllocReal :: Word32 -- ^ size+              -> IO (Ptr CDouble)+fftwAllocReal = c_fftwAllocReal . fromIntegral++foreign import ccall unsafe "fftw_alloc_complex"+    c_fftwAllocComplex :: CUInt -> IO (Ptr (Complex CDouble))++-- | Allocates an array of complex Doubles (i.e. the c type "double complex"). It ensures that the pointer obeys the alignment restrictions of FFTW (e.g. for SIMD acceleration).+fftwAllocComplex :: Word32 -- ^ size+                 -> IO (Ptr (Complex CDouble))+fftwAllocComplex = c_fftwAllocComplex . fromIntegral++-- | The direction of the transform: Forward for a normal transform, Backward for an inverse transform+data Direction = Forward+               | Backward++dirToInt :: Direction -> CInt+dirToInt Forward  = #const FFTW_FORWARD+dirToInt Backward = #const FFTW_BACKWARD++-- | FFTW planner flags. These flags affect the planning process. They can be combined using the 'Monoid' instance. See the FFTW flag documentation: <http://www.fftw.org/doc/Planner-Flags.html>.+newtype Flag = Flag {unFlag :: CUInt}++instance Monoid Flag where+    mempty                    = Flag 0+    mappend (Flag x) (Flag y) = Flag (x .|. y)++fftwMeasure, fftwExhaustive, fftwPatient, fftwEstimate, fftwWisdomOnly :: Flag+fftwEstimate       = Flag #const FFTW_ESTIMATE+fftwMeasure        = Flag #const FFTW_MEASURE+fftwPatient        = Flag #const FFTW_PATIENT+fftwExhaustive     = Flag #const FFTW_EXHAUSTIVE+fftwWisdomOnly     = Flag #const FFTW_WISDOM_ONLY++fftwDestroyInput, fftwUnaligned, fftwPreserveInput :: Flag+fftwDestroyInput   = Flag #const FFTW_DESTROY_INPUT+fftwUnaligned      = Flag #const FFTW_UNALIGNED+fftwPreserveInput  = Flag #const FFTW_PRESERVE_INPUT++data CFFTWPlan++-- | A @FFTWPlan i o@ contains all of the information necessary to perform a transform from an input array of type @i@ to an output array of type @o@, including pointers to the input and output arrays.+newtype FFTWPlan i o = FFTWPlan (Ptr CFFTWPlan)++foreign import ccall unsafe "fftw_plan_dft_1d"+    c_planDFT1d :: CInt -> Ptr (Complex CDouble) -> Ptr (Complex CDouble) -> CInt -> CUInt -> IO (Ptr CFFTWPlan)++--This appears to be missing from the fft package on Hackage+-- | Create a plan for a 1 dimensional complex to complex DFT. The plan stores pointers to the input and output arrays, and these will be used if you 'execute' the plan in the future. They are required even if you intend to specify different input and output arrays in the future (i.e. using 'executeDFT')+planDFT1d :: Int                   -- ^ size+          -> Ptr (Complex CDouble) -- ^ input pointer+          -> Ptr (Complex CDouble) -- ^ output pointer+          -> Direction             -- ^ direction+          -> Flag                  -- ^ planner flags+          -> IO (FFTWPlan (Complex CDouble) (Complex CDouble))+planDFT1d n inp out sign flags = liftM FFTWPlan $ c_planDFT1d (fromIntegral n) inp out (dirToInt sign) (unFlag flags)++foreign import ccall unsafe "fftw_plan_dft_r2c_1d"+    c_planDFTR2C1d :: CInt -> Ptr CDouble -> Ptr (Complex CDouble) -> CUInt -> IO (Ptr CFFTWPlan)++--This appears to be missing from the fft package on Hackage+-- | Create a plan for a 1 dimensional real to complex DFT. The plan stores pointers to the input and output arrays, and these will be used if you 'execute' the plan in the future. They are required even if you intend to specify different input and output arrays in the future (i.e. using 'executeDFTR2C')+planDFTR2C1d :: Int                   -- ^ size+             -> Ptr CDouble           -- ^ input pointer+             -> Ptr (Complex CDouble) -- ^ output pointer+             -> Flag                  -- ^ planner flags+             -> IO (FFTWPlan CDouble (Complex CDouble))+planDFTR2C1d n inp out flags = liftM FFTWPlan $ c_planDFTR2C1d (fromIntegral n) inp out (unFlag flags)++foreign import ccall unsafe "fftw_execute"+    c_execute :: Ptr CFFTWPlan -> IO ()++-- | Execute a plan. Performs an FFT. The input and output arrays are stored within the plan so do not need to be given.+execute :: FFTWPlan i o -- ^ the plan to execute+        -> IO ()+execute (FFTWPlan p) = c_execute p++foreign import ccall unsafe "fftw_execute_dft"+    c_executeDFT :: Ptr CFFTWPlan -> Ptr (Complex CDouble) -> Ptr (Complex CDouble) -> IO ()++-- | Execute a complex to complex DFT but on different input and output arrays to those specified when the plan was created.+executeDFT :: FFTWPlan (Complex CDouble) (Complex CDouble) -- ^ the plan to execute+           -> Ptr (Complex CDouble)                        -- ^ input pointer+           -> Ptr (Complex CDouble)                        -- ^ output pointer+           -> IO ()+executeDFT (FFTWPlan p) inp out = c_executeDFT p inp out++foreign import ccall unsafe "fftw_execute_dft_r2c"+    c_executeDFTR2C :: Ptr CFFTWPlan -> Ptr CDouble -> Ptr (Complex CDouble) -> IO ()++-- | Execute a real to complex DFT but on different input and output arrays to those specified when the plan was created.+executeDFTR2C :: FFTWPlan CDouble (Complex CDouble) -- ^ the plan to execute+              -> Ptr CDouble                        -- ^ input pointer+              -> Ptr (Complex CDouble)              -- ^ output pointer+              -> IO ()+executeDFTR2C (FFTWPlan p) inp out = c_executeDFTR2C p inp out+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ fftwRaw.cabal view
@@ -0,0 +1,36 @@+name:                fftwRaw+version:             0.1.0.0+synopsis:            Low level bindings to FFTW.+description:         +    Yet another set of Haskell bindings to <http://www.fftw.org/ FFTW>, the Fastest Fourier Transform in the West.+    .+    These are low level bindings with some type safety for a small subset of FFTW's functionality. Raise an Issue on Github if you need something I haven't implemented.+    .+    Unlike the <https://hackage.haskell.org/package/fft fft> package, this package provides low level manipulation of FFTW plans (such as `fftw_plan_dft_1d`).+    .+    Unlike the <https://hackage.haskell.org/package/vector-fftw vector-fftw> package, this package is based on pointers instead of the Vector datatype and it avoids copying the input arrays by assuming that the pointers are aligned as FFTW expects.+license:             BSD3+license-file:        LICENSE+author:              Adam Walker+maintainer:          adamwalker10@gmail.com+copyright:           2015 Adam Walker+category:            Math+homepage:            https://github.com/adamwalker/haskell-fftw-simple+bug-reports:         https://github.com/adamwalker/haskell-fftw-simple/issues+build-type:          Simple+-- extra-source-files:  +cabal-version:       >=1.10++source-repository head+    type: git+    location: https://github.com/adamwalker/haskell-fftw-simple++library+  exposed-modules:     Numeric.FFTW+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >=4.6 && <4.9+  -- hs-source-dirs:      +  default-language:    Haskell2010+  extra-libraries:     fftw3+  build-tools:         hsc2hs