Added example_sprinkler.py, a python port of examples/example_sprinkler.cpp and added...
[libdai.git] / python / dai.i
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
6 *
7 * Copyright (C) 2009 Patrick Pletscher [pletscher at inf dot ethz dot ch]
8 */
9
10
11 %module dai
12
13 struct Neighbor {
14 size_t iter;
15 size_t node;
16 size_t dual;
17
18 Neighbor() {}
19 Neighbor( size_t iter, size_t node, size_t dual ) : iter(iter), node(node), dual(dual) {}
20
21 operator size_t () const { return node; }
22 };
23
24 %{
25 #include "../include/dai/var.h"
26 #include "../include/dai/smallset.h"
27 #include "../include/dai/varset.h"
28 #include "../include/dai/prob.h"
29 #include "../include/dai/factor.h"
30 #include "../include/dai/bipgraph.h"
31 #include "../include/dai/factorgraph.h"
32 #include "../include/dai/util.h"
33 %}
34
35 %ignore dai::TProb::operator[];
36 %ignore dai::TFactor::operator[];
37
38 %include "../include/dai/util.h"
39 %include "../include/dai/var.h"
40 %include "../include/dai/smallset.h"
41 %template(SmallSetVar) dai::SmallSet< dai::Var >;
42 %include "../include/dai/varset.h"
43 %extend dai::VarSet {
44 inline void append(const dai::Var &v) { (*self) |= v; }
45 };
46
47 %include "../include/dai/prob.h"
48 %template(Prob) dai::TProb<Real>;
49 %extend dai::TProb<Real> {
50 inline Real __getitem__(int i) const {return (*self)[i];}
51 inline void __setitem__(int i,Real d) {(*self)[i] = d;}
52 %template(TProbRealConstructor) TProb<double *>;
53 %template(TProbIntConstructor) TProb<size_t *>;
54 };
55 %include "../include/dai/factor.h"
56 %extend dai::TFactor<Real> {
57 inline Real __getitem__(int i) const {return (*self)[i];}
58 inline void __setitem__(int i,Real d) {(*self)[i] = d;}
59 };
60
61 %template(Factor) dai::TFactor<Real>;
62 %include "../include/dai/bipgraph.h"
63 %include "../include/dai/factorgraph.h"
64 %include "std_vector.i"
65 // TODO: typemaps for the vectors (input/output python arrays)
66 %inline{
67 typedef std::vector<dai::Factor> VecFactor;
68 typedef std::vector< VecFactor > VecVecFactor;
69 }
70 %template(VecFactor) std::vector< dai::Factor >;
71 %template(VecVecFactor) std::vector< VecFactor >;
72
73 %{
74 typedef dai::BipartiteGraph::Neighbor Neighbor;
75 %}
76
77 %include "../include/dai/index.h"
78 %extend dai::MultiFor {
79 inline size_t __getitem__(int i) const {
80 return (*self)[i];
81 }
82 inline void next() {
83 return (*self)++;
84 }
85 };