diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-08 08:48:12 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-08 08:48:12 +0200 |
commit | 1925c123d7d8184a1d2ddc0a413e0fd2776e1083 (patch) | |
tree | fad79f909d9c3be53d68e6ebd67202650536d387 /examples/devel/ej1/wrappers.hs | |
parent | eb3f702d065a4a967bb754977233e6eec408fd1f (diff) |
empty hmatrix-base
Diffstat (limited to 'examples/devel/ej1/wrappers.hs')
-rw-r--r-- | examples/devel/ej1/wrappers.hs | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/examples/devel/ej1/wrappers.hs b/examples/devel/ej1/wrappers.hs deleted file mode 100644 index a88f74b..0000000 --- a/examples/devel/ej1/wrappers.hs +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | {-# LANGUAGE ForeignFunctionInterface #-} | ||
2 | |||
3 | -- $ ghc -O2 --make wrappers.hs functions.c | ||
4 | |||
5 | import Numeric.LinearAlgebra | ||
6 | import Data.Packed.Development | ||
7 | import Foreign(Ptr,unsafePerformIO) | ||
8 | import Foreign.C.Types(CInt) | ||
9 | |||
10 | ----------------------------------------------------- | ||
11 | |||
12 | main = do | ||
13 | print $ myScale 3.0 (fromList [1..10]) | ||
14 | print $ myDiag $ (3><5) [1..] | ||
15 | |||
16 | ----------------------------------------------------- | ||
17 | |||
18 | foreign import ccall unsafe "c_scale_vector" | ||
19 | cScaleVector :: Double -- scale | ||
20 | -> CInt -> Ptr Double -- argument | ||
21 | -> CInt -> Ptr Double -- result | ||
22 | -> IO CInt -- exit code | ||
23 | |||
24 | myScale s x = unsafePerformIO $ do | ||
25 | y <- createVector (dim x) | ||
26 | app2 (cScaleVector s) vec x vec y "cScaleVector" | ||
27 | return y | ||
28 | |||
29 | ----------------------------------------------------- | ||
30 | -- forcing row order | ||
31 | |||
32 | foreign import ccall unsafe "c_diag" | ||
33 | cDiag :: CInt -> CInt -> Ptr Double -- argument | ||
34 | -> CInt -> Ptr Double -- result1 | ||
35 | -> CInt -> CInt -> Ptr Double -- result2 | ||
36 | -> IO CInt -- exit code | ||
37 | |||
38 | myDiag m = unsafePerformIO $ do | ||
39 | y <- createVector (min r c) | ||
40 | z <- createMatrix RowMajor r c | ||
41 | app3 cDiag mat (cmat m) vec y mat z "cDiag" | ||
42 | return (y,z) | ||
43 | where r = rows m | ||
44 | c = cols m | ||