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 /packages/hmatrix/examples/devel/ej2/wrappers.hs | |
parent | eb3f702d065a4a967bb754977233e6eec408fd1f (diff) |
empty hmatrix-base
Diffstat (limited to 'packages/hmatrix/examples/devel/ej2/wrappers.hs')
-rw-r--r-- | packages/hmatrix/examples/devel/ej2/wrappers.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/hmatrix/examples/devel/ej2/wrappers.hs b/packages/hmatrix/examples/devel/ej2/wrappers.hs new file mode 100644 index 0000000..1c02a24 --- /dev/null +++ b/packages/hmatrix/examples/devel/ej2/wrappers.hs | |||
@@ -0,0 +1,32 @@ | |||
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 $ myDiag $ (3><5) [1..] | ||
14 | |||
15 | ----------------------------------------------------- | ||
16 | -- arbitrary data order | ||
17 | |||
18 | foreign import ccall unsafe "c_diag" | ||
19 | cDiag :: CInt -- matrix order | ||
20 | -> CInt -> CInt -> Ptr Double -- argument | ||
21 | -> CInt -> Ptr Double -- result1 | ||
22 | -> CInt -> CInt -> Ptr Double -- result2 | ||
23 | -> IO CInt -- exit code | ||
24 | |||
25 | myDiag m = unsafePerformIO $ do | ||
26 | y <- createVector (min r c) | ||
27 | z <- createMatrix (orderOf m) r c | ||
28 | app3 (cDiag o) mat m vec y mat z "cDiag" | ||
29 | return (y,z) | ||
30 | where r = rows m | ||
31 | c = cols m | ||
32 | o = if orderOf m == RowMajor then 1 else 0 | ||