5faec4e385c5428a91efdb2bf169cc1aee41e447
[libdai.git] / swig / dai.i
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 *
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6 */
7
8
9 %module dai
10
11 %include "std_string.i"
12 %include "std_vector.i"
13 %template(IntVector) std::vector<size_t>;
14 //%include "std_set.i" /* for python */
15
16 %{
17 #define DAI_WITH_BP 1
18 #define DAI_WITH_FBP 1
19 #define DAI_WITH_TRWBP 1
20 #define DAI_WITH_MF 1
21 #define DAI_WITH_HAK 1
22 #define DAI_WITH_LC 1
23 #define DAI_WITH_TREEEP 1
24 #define DAI_WITH_JTREE 1
25 #define DAI_WITH_MR 1
26 #define DAI_WITH_GIBBS 1
27 #define DAI_WITH_CBP 1
28 #define DAI_WITH_DECMAP 1
29 #define DAI_WITH_GLC 1
30 #include "../include/dai/alldai.h"
31
32 using namespace dai;
33 %}
34
35 // ************************************************************************************************
36 %include "../include/dai/util.h"
37
38 // ************************************************************************************************
39 %ignore dai::Var::label() const;
40 %ignore dai::Var::states() const;
41 %ignore operator<<(std::ostream&, const Var&);
42 %include "../include/dai/var.h"
43 %extend dai::Var {
44 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
45 inline std::string __str() const { return (*self).toString(); } /* for octave */
46 };
47
48 // ************************************************************************************************
49 %ignore operator<<(std::ostream&, const SmallSet&);
50 %rename(__eq__) operator==(const SmallSet&, const SmallSet&); /* for python */
51 %rename(__ne__) operator!=(const SmallSet&, const SmallSet&); /* for python */
52 %rename(__lt__) operator<(const SmallSet&, const SmallSet&); /* for python */
53 %include "../include/dai/smallset.h"
54 %template(SmallSetVar) dai::SmallSet< dai::Var >;
55 %extend dai::SmallSet<dai::Var> {
56 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
57 inline std::string __str() const { return (*self).toString(); } /* for octave */
58 }
59
60 // ************************************************************************************************
61 %ignore operator<<(std::ostream&, const VarSet&);
62 %include "../include/dai/varset.h"
63 %extend dai::VarSet {
64 inline void append(const dai::Var &v) { (*self) |= v; } /* for python, octave */
65 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
66 inline std::string __str() const { return (*self).toString(); } /* for octave */
67 };
68
69 // ************************************************************************************************
70 %ignore dai::TProb::operator[];
71 %include "../include/dai/prob.h"
72 %template(Prob) dai::TProb<dai::Real>;
73 %extend dai::TProb<dai::Real> {
74 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
75 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
76 inline dai::Real __paren(int i) const {return (*self).get(i);} /* for octave */
77 inline void __paren_asgn(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
78 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
79 inline std::string __str() const { return (*self).toString(); } /* for octave */
80 };
81
82 // ************************************************************************************************
83 %ignore dai::TFactor::operator[];
84 %include "../include/dai/factor.h"
85 %extend dai::TFactor<dai::Real> {
86 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
87 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
88 inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
89 inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
90 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
91 inline std::string __str() const { return (*self).toString(); } /* for octave */
92 };
93 %template(Factor) dai::TFactor<dai::Real>;
94 %inline %{
95 typedef std::vector<dai::Factor> VecFactor;
96 typedef std::vector<VecFactor> VecVecFactor;
97 %}
98 %template(VecFactor) std::vector<dai::Factor>;
99 %template(VecVecFactor) std::vector<VecFactor>;
100
101 // ************************************************************************************************
102 %ignore operator<<(std::ostream&, const GraphAL&);
103 %rename(toInt) dai::Neighbor::operator size_t() const;
104 %include "../include/dai/graph.h"
105 %extend dai::GraphAL {
106 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
107 inline std::string __str() const { return (*self).toString(); } /* for octave */
108 }
109
110 // ************************************************************************************************
111 %ignore operator<<(std::ostream&, const BipartiteGraph&);
112 %include "../include/dai/bipgraph.h"
113 %extend dai::BipartiteGraph {
114 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
115 inline std::string __str() const { return (*self).toString(); } /* for octave */
116 }
117
118 // ************************************************************************************************
119 %ignore operator<<(std::ostream&, const FactorGraph&);
120 %ignore operator>>(std::istream&,FactorGraph&);
121 %include "../include/dai/factorgraph.h"
122 %extend dai::FactorGraph {
123 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
124 inline std::string __str() const { return (*self).toString(); } /* for octave */
125 }
126
127 // ************************************************************************************************
128 %ignore operator<<(std::ostream&, const RegionGraph&);
129 %include "../include/dai/regiongraph.h"
130 %extend dai::RegionGraph {
131 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
132 inline std::string __str() const { return (*self).toString(); } /* for octave */
133 }
134
135 // ************************************************************************************************
136 //%ignore operator<<(std::ostream&, const CobwebGraph&);
137 //%include "../include/dai/cobwebgraph.h"
138 //%extend dai::CobwebGraph {
139 // inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
140 // inline std::string __str() const { return (*self).toString(); } /* for octave */
141 //}
142 //TODO fix problems with CobwebGraph
143
144 // ************************************************************************************************
145 %ignore operator<<(std::ostream&, const PropertySet&);
146 %ignore operator>>(std::istream&,PropertySet&);
147 %include "../include/dai/properties.h"
148 %extend dai::PropertySet {
149 inline void __setitem__(char *name, char *val) {
150 self->set(std::string(name), std::string(val));
151 }
152 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
153 inline std::string __str() const { return (*self).toString(); } /* for octave */
154 }
155
156 // ************************************************************************************************
157 %ignore dai::IndexFor::operator++;
158 %rename(toInt) dai::IndexFor::operator size_t() const;
159 %ignore dai::Permute::operator[];
160 %ignore dai::multifor::operator++;
161 %ignore dai::multifor::operator[];
162 %rename(toInt) dai::multifor::operator size_t() const;
163 %ignore dai::State::operator++;
164 %rename(toInt) dai::State::operator size_t() const;
165 %ignore dai::State::operator const std::map<Var,size_t>&;
166 %include "../include/dai/index.h"
167 %extend dai::IndexFor {
168 inline void next() { return (*self)++; }
169 };
170 %extend dai::Permute {
171 inline size_t __getitem__(int i) const {return (*self)[i];} /* for python */
172 inline size_t __paren__(int i) const {return (*self)[i];} /* for octave */
173 };
174 %extend dai::multifor {
175 inline void next() { return (*self)++; }
176 inline size_t __getitem__(int i) const {return (*self)[i];} /* for python */
177 inline size_t __paren__(int i) const {return (*self)[i];} /* for octave */
178 };
179 %extend dai::State {
180 inline void next() { return (*self)++; }
181 };
182
183 // ************************************************************************************************
184 %include "../include/dai/daialg.h"
185 //TODO: why do the following lines not work?
186 //%template(DAIAlgFG) dai::DAIAlg<dai::FactorGraph>;
187 //%template(DAIAlgRG) dai::DAIAlg<dai::RegionGraph>;
188 //%template(DAIAlgCG) dai::DAIAlg<dai::CobwebGraph>;
189
190 // ************************************************************************************************
191 %include "../include/dai/alldai.h"
192
193 // ************************************************************************************************
194 %ignore dai::BP::operator=;
195 %include "../include/dai/bp.h"
196
197 // ************************************************************************************************
198 %include "../include/dai/fbp.h"
199
200 // ************************************************************************************************
201 %include "../include/dai/trwbp.h"
202
203 // ************************************************************************************************
204 %include "../include/dai/mf.h"
205
206 // ************************************************************************************************
207 %include "../include/dai/hak.h"
208
209 // ************************************************************************************************
210 %include "../include/dai/lc.h"
211
212 // ************************************************************************************************
213 %include "../include/dai/jtree.h"
214
215 // ************************************************************************************************
216 %ignore dai::TreeEP::operator=;
217 %include "../include/dai/treeep.h"
218
219 // ************************************************************************************************
220 %include "../include/dai/mr.h"
221
222 // ************************************************************************************************
223 %include "../include/dai/gibbs.h"
224
225 // ************************************************************************************************
226 %include "../include/dai/cbp.h"
227
228 // ************************************************************************************************
229 %include "../include/dai/decmap.h"
230
231 // ************************************************************************************************
232 %include "../include/dai/glc.h"