blob: 834dfc256c0db7601f83392760ca0da859c8b4c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
-- Module : Numeric.GSL.Internal
-- Copyright : (c) Alberto Ruiz 2009
-- License : GPL
--
-- Maintainer : Alberto Ruiz (aruiz at um dot es)
-- Stability : provisional
-- Portability : uses ffi
--
-- Auxiliary functions.
--
-- #hide
module Numeric.GSL.Internal where
import Data.Packed.Internal
import Foreign
import Foreign.C.Types(CInt)
iv :: (Vector Double -> Double) -> (CInt -> Ptr Double -> Double)
iv f n p = f (createV (fromIntegral n) copy "iv") where
copy n' q = do
copyArray q p (fromIntegral n')
return 0
-- | conversion of Haskell functions into function pointers that can be used in the C side
foreign import ccall "wrapper"
mkVecfun :: (CInt -> Ptr Double -> Double)
-> IO( FunPtr (CInt -> Ptr Double -> Double))
foreign import ccall "wrapper"
mkVecVecfun :: TVV -> IO (FunPtr TVV)
aux_vTov :: (Vector Double -> Vector Double) -> TVV
aux_vTov f n p nr r = g where
V {fptr = pr} = f x
x = createV (fromIntegral n) copy "aux_vTov"
copy n' q = do
copyArray q p (fromIntegral n')
return 0
g = do withForeignPtr pr $ \p' -> copyArray r p' (fromIntegral nr)
return 0
foreign import ccall "wrapper"
mkVecMatfun :: TVM -> IO (FunPtr TVM)
aux_vTom :: (Vector Double -> Matrix Double) -> TVM
aux_vTom f n p rr cr r = g where
V {fptr = pr} = flatten $ f x
x = createV (fromIntegral n) copy "aux_vTov"
copy n' q = do
copyArray q p (fromIntegral n')
return 0
g = do withForeignPtr pr $ \p' -> copyArray r p' (fromIntegral $ rr*cr)
return 0
createV n fun msg = unsafePerformIO $ do
r <- createVector n
app1 fun vec r msg
return r
createMIO r c fun msg = do
res <- createMatrix RowMajor r c
app1 fun mat res msg
return res
|