Added BETHE method for GBP/HAK cluster choice
[libdai.git] / swig / 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 * 2009 Joris Mooij [joris dot mooij at libdai dot org]
9 */
10
11
12 %module dai
13
14 struct Neighbor {
15 size_t iter;
16 size_t node;
17 size_t dual;
18
19 Neighbor() {}
20 Neighbor( size_t iter, size_t node, size_t dual ) : iter(iter), node(node), dual(dual) {}
21
22 operator size_t () const { return node; }
23 };
24
25 %{
26 #include "../include/dai/var.h"
27 #include "../include/dai/smallset.h"
28 #include "../include/dai/varset.h"
29 #include "../include/dai/prob.h"
30 #include "../include/dai/factor.h"
31 #include "../include/dai/bipgraph.h"
32 #include "../include/dai/factorgraph.h"
33 #include "../include/dai/util.h"
34 %}
35
36 %ignore dai::TProb::operator[];
37 %ignore dai::TFactor::operator[];
38
39 %ignore dai::Var::label() const;
40 %ignore dai::Var::states() const;
41
42 %include "../include/dai/util.h"
43 %include "../include/dai/var.h"
44 %include "../include/dai/smallset.h"
45 %template(SmallSetVar) dai::SmallSet< dai::Var >;
46 %include "../include/dai/varset.h"
47 %extend dai::VarSet {
48 inline void append(const dai::Var &v) { (*self) |= v; } /* for python, octave */
49 };
50
51 %include "../include/dai/prob.h"
52 %template(Prob) dai::TProb<dai::Real>;
53 %extend dai::TProb<dai::Real> {
54 inline dai::Real __getitem__(int i) const {return (*self)[i];} /* for python */
55 inline void __setitem__(int i,dai::Real d) {(*self)[i] = d;} /* for python */
56 inline dai::Real __paren(int i) const {return (*self)[i];} /* for octave */
57 inline void __paren_asgn(int i,dai::Real d) {(*self)[i] = d;} /* for octave */
58 };
59 %include "../include/dai/factor.h"
60 %extend dai::TFactor<dai::Real> {
61 inline dai::Real __getitem__(int i) const {return (*self)[i];} /* for python */
62 inline void __setitem__(int i,dai::Real d) {(*self)[i] = d;} /* for python */
63 inline dai::Real __paren__(int i) const {return (*self)[i];} /* for octave */
64 inline void __paren_asgn__(int i,dai::Real d) {(*self)[i] = d;} /* for octave */
65 };
66
67 %template(Factor) dai::TFactor<dai::Real>;
68 %include "../include/dai/bipgraph.h"
69 %include "../include/dai/factorgraph.h"
70 %include "std_vector.i"
71 // TODO: typemaps for the vectors (input/output python arrays)
72 %inline{
73 typedef std::vector<dai::Factor> VecFactor;
74 typedef std::vector< VecFactor > VecVecFactor;
75 }
76 %template(VecFactor) std::vector< dai::Factor >;
77 %template(VecVecFactor) std::vector< VecFactor >;
78
79 %{
80 typedef dai::BipartiteGraph::Neighbor Neighbor;
81 %}
82
83 %include "../include/dai/index.h"
84 %extend dai::multifor {
85 inline size_t __getitem__(int i) const {
86 return (*self)[i];
87 }
88 inline void next() {
89 return (*self)++;
90 }
91 };