[Patrick Pletscher] Added experimental SWIG Python wrapper code
[libdai.git] / python / dai.i
1 %module dai
2
3 struct Neighbor {
4 size_t iter;
5 size_t node;
6 size_t dual;
7
8 Neighbor() {}
9 Neighbor( size_t iter, size_t node, size_t dual ) : iter(iter), node(node), dual(dual) {}
10
11 operator size_t () const { return node; }
12 };
13
14 %{
15 #include "../include/dai/var.h"
16 #include "../include/dai/smallset.h"
17 #include "../include/dai/varset.h"
18 #include "../include/dai/prob.h"
19 #include "../include/dai/factor.h"
20 #include "../include/dai/bipgraph.h"
21 #include "../include/dai/factorgraph.h"
22 #include "../include/dai/util.h"
23 %}
24
25 %ignore dai::TProb::operator[];
26 %ignore dai::TFactor::operator[];
27
28 %include "../include/dai/util.h"
29 %include "../include/dai/var.h"
30 %include "../include/dai/smallset.h"
31 %template(SmallSetVar) dai::SmallSet< dai::Var >;
32 %include "../include/dai/varset.h"
33 %include "../include/dai/prob.h"
34 %template(Prob) dai::TProb<Real>;
35 %extend dai::TProb<Real> {
36 inline Real __getitem__(int i) const {return (*self)[i];}
37 inline void __setitem__(int i,Real d) {(*self)[i] = d;}
38 %template(TProbRealConstructor) TProb<double *>;
39 %template(TProbIntConstructor) TProb<size_t *>;
40 };
41 %include "../include/dai/factor.h"
42 %extend dai::TFactor<Real> {
43 inline Real __getitem__(int i) const {return (*self)[i];}
44 inline void __setitem__(int i,Real d) {(*self)[i] = d;}
45 };
46
47 %template(Factor) dai::TFactor<Real>;
48 %include "../include/dai/bipgraph.h"
49 %include "../include/dai/factorgraph.h"
50 %include "std_vector.i"
51 // TODO: typemaps for the vectors (input/output python arrays)
52 %inline{
53 typedef std::vector<dai::Factor> VecFactor;
54 typedef std::vector< VecFactor > VecVecFactor;
55 }
56 %template(VecFactor) std::vector< dai::Factor >;
57 %template(VecVecFactor) std::vector< VecFactor >;
58
59 %{
60 typedef dai::BipartiteGraph::Neighbor Neighbor;
61 %}
62
63 %include "../include/dai/index.h"
64 %extend dai::MultiFor {
65 inline size_t __getitem__(int i) const {
66 return (*self)[i];
67 }
68 inline void next() {
69 return (*self)++;
70 }
71 };