summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/Internal.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-06-08 09:45:14 +0000
committerAlberto Ruiz <aruiz@um.es>2009-06-08 09:45:14 +0000
commitd9efdd9334da1a63f739d6e2e68c4ff78f52e505 (patch)
tree4c4c4c798fd1e67ec4565a441e1357d5b75f37da /lib/Numeric/GSL/Internal.hs
parent34de6154086224a0e9f774bd8a2ab804d78e8a10 (diff)
auxiliary functions moved to Numeric.GSL.Internal
Diffstat (limited to 'lib/Numeric/GSL/Internal.hs')
-rw-r--r--lib/Numeric/GSL/Internal.hs64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/Internal.hs b/lib/Numeric/GSL/Internal.hs
new file mode 100644
index 0000000..834dfc2
--- /dev/null
+++ b/lib/Numeric/GSL/Internal.hs
@@ -0,0 +1,64 @@
1-- Module : Numeric.GSL.Internal
2-- Copyright : (c) Alberto Ruiz 2009
3-- License : GPL
4--
5-- Maintainer : Alberto Ruiz (aruiz at um dot es)
6-- Stability : provisional
7-- Portability : uses ffi
8--
9-- Auxiliary functions.
10--
11-- #hide
12
13module Numeric.GSL.Internal where
14
15import Data.Packed.Internal
16import Foreign
17import Foreign.C.Types(CInt)
18
19iv :: (Vector Double -> Double) -> (CInt -> Ptr Double -> Double)
20iv f n p = f (createV (fromIntegral n) copy "iv") where
21 copy n' q = do
22 copyArray q p (fromIntegral n')
23 return 0
24
25-- | conversion of Haskell functions into function pointers that can be used in the C side
26foreign import ccall "wrapper"
27 mkVecfun :: (CInt -> Ptr Double -> Double)
28 -> IO( FunPtr (CInt -> Ptr Double -> Double))
29
30foreign import ccall "wrapper"
31 mkVecVecfun :: TVV -> IO (FunPtr TVV)
32
33aux_vTov :: (Vector Double -> Vector Double) -> TVV
34aux_vTov f n p nr r = g where
35 V {fptr = pr} = f x
36 x = createV (fromIntegral n) copy "aux_vTov"
37 copy n' q = do
38 copyArray q p (fromIntegral n')
39 return 0
40 g = do withForeignPtr pr $ \p' -> copyArray r p' (fromIntegral nr)
41 return 0
42
43foreign import ccall "wrapper"
44 mkVecMatfun :: TVM -> IO (FunPtr TVM)
45
46aux_vTom :: (Vector Double -> Matrix Double) -> TVM
47aux_vTom f n p rr cr r = g where
48 V {fptr = pr} = flatten $ f x
49 x = createV (fromIntegral n) copy "aux_vTov"
50 copy n' q = do
51 copyArray q p (fromIntegral n')
52 return 0
53 g = do withForeignPtr pr $ \p' -> copyArray r p' (fromIntegral $ rr*cr)
54 return 0
55
56createV n fun msg = unsafePerformIO $ do
57 r <- createVector n
58 app1 fun vec r msg
59 return r
60
61createMIO r c fun msg = do
62 res <- createMatrix RowMajor r c
63 app1 fun mat res msg
64 return res