From 197e88c3b56d28840217010a2871c6ea3a4dd1a4 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 21 May 2014 10:30:55 +0200 Subject: update dependencies, move examples etc --- examples/devel/ej2/functions.c | 24 ++++++++++++++++++++++++ examples/devel/ej2/wrappers.hs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 examples/devel/ej2/functions.c create mode 100644 examples/devel/ej2/wrappers.hs (limited to 'examples/devel/ej2') diff --git a/examples/devel/ej2/functions.c b/examples/devel/ej2/functions.c new file mode 100644 index 0000000..4dcd377 --- /dev/null +++ b/examples/devel/ej2/functions.c @@ -0,0 +1,24 @@ +/* general element order */ + +typedef struct { double r, i; } doublecomplex; + +#define DVEC(A) int A##n, double*A##p +#define CVEC(A) int A##n, doublecomplex*A##p +#define DMAT(A) int A##r, int A##c, double*A##p +#define CMAT(A) int A##r, int A##c, doublecomplex*A##p + +#define AT(M,r,c) (M##p[(r)*sr+(c)*sc]) + +int c_diag(int ro, DMAT(m),DVEC(y),DMAT(z)) { + int i,j,sr,sc; + if (ro==1) { sr = mc; sc = 1;} else { sr = 1; sc = mr;} + for (j=0; j<5) [1..] + +----------------------------------------------------- +-- arbitrary data order + +foreign import ccall unsafe "c_diag" + cDiag :: CInt -- matrix order + -> CInt -> CInt -> Ptr Double -- argument + -> CInt -> Ptr Double -- result1 + -> CInt -> CInt -> Ptr Double -- result2 + -> IO CInt -- exit code + +myDiag m = unsafePerformIO $ do + y <- createVector (min r c) + z <- createMatrix (orderOf m) r c + app3 (cDiag o) mat m vec y mat z "cDiag" + return (y,z) + where r = rows m + c = cols m + o = if orderOf m == RowMajor then 1 else 0 -- cgit v1.2.3