9f3074f073fa7672108a7c8d4dcdc6a739ba0775
[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 #include "../include/dai/alldai.h"
18
19 using namespace dai;
20 %}
21
22 // ************************************************************************************************
23 %include "../include/dai/util.h"
24
25 // ************************************************************************************************
26 %ignore dai::Var::label() const;
27 %ignore dai::Var::states() const;
28 %ignore operator<<(std::ostream&, const Var&);
29 %include "../include/dai/var.h"
30 %extend dai::Var {
31 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
32 inline std::string __str() const { return (*self).toString(); } /* for octave */
33 };
34
35 // ************************************************************************************************
36 %ignore operator<<(std::ostream&, const SmallSet&);
37 %rename(__eq__) operator==(const SmallSet&, const SmallSet&); /* for python */
38 %rename(__ne__) operator!=(const SmallSet&, const SmallSet&); /* for python */
39 %rename(__lt__) operator<(const SmallSet&, const SmallSet&); /* for python */
40 %include "../include/dai/smallset.h"
41 %template(SmallSetVar) dai::SmallSet< dai::Var >;
42 %extend dai::SmallSet<dai::Var> {
43 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
44 inline std::string __str() const { return (*self).toString(); } /* for octave */
45 }
46
47 // ************************************************************************************************
48 %ignore operator<<(std::ostream&, const VarSet&);
49 %include "../include/dai/varset.h"
50 %extend dai::VarSet {
51 inline void append(const dai::Var &v) { (*self) |= v; } /* for python, octave */
52 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
53 inline std::string __str() const { return (*self).toString(); } /* for octave */
54 };
55
56 // ************************************************************************************************
57 %ignore dai::TProb::operator[];
58 %include "../include/dai/prob.h"
59 %template(Prob) dai::TProb<dai::Real>;
60 %extend dai::TProb<dai::Real> {
61 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
62 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
63 inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
64 inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for 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::TFactor::operator[];
71 %include "../include/dai/factor.h"
72 %extend dai::TFactor<dai::Real> {
73 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
74 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
75 inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
76 inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
77 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
78 inline std::string __str() const { return (*self).toString(); } /* for octave */
79 };
80 %template(Factor) dai::TFactor<dai::Real>;
81 %inline %{
82 typedef std::vector<dai::Factor> VecFactor;
83 typedef std::vector<VecFactor> VecVecFactor;
84 %}
85 %template(VecFactor) std::vector<dai::Factor>;
86 %template(VecVecFactor) std::vector<VecFactor>;
87
88 // ************************************************************************************************
89 %ignore operator<<(std::ostream&, const GraphAL&);
90 %rename(toInt) dai::Neighbor::operator size_t() const;
91 %include "../include/dai/graph.h"
92 %extend dai::GraphAL {
93 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
94 inline std::string __str() const { return (*self).toString(); } /* for octave */
95 }
96
97 // ************************************************************************************************
98 %ignore operator<<(std::ostream&, const BipartiteGraph&);
99 %include "../include/dai/bipgraph.h"
100 %extend dai::BipartiteGraph {
101 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
102 inline std::string __str() const { return (*self).toString(); } /* for octave */
103 }
104
105 // ************************************************************************************************
106 %ignore operator<<(std::ostream&, const FactorGraph&);
107 %ignore operator>>(std::istream&,FactorGraph&);
108 %include "../include/dai/factorgraph.h"
109 %extend dai::FactorGraph {
110 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
111 inline std::string __str() const { return (*self).toString(); } /* for octave */
112 }
113
114 // ************************************************************************************************
115 %ignore operator<<(std::ostream&, const RegionGraph&);
116 %include "../include/dai/regiongraph.h"
117 %extend dai::RegionGraph {
118 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
119 inline std::string __str() const { return (*self).toString(); } /* for octave */
120 }
121
122 // ************************************************************************************************
123 //%ignore operator<<(std::ostream&, const CobwebGraph&);
124 //%include "../include/dai/cobwebgraph.h"
125 //%extend dai::CobwebGraph {
126 // inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
127 // inline std::string __str() const { return (*self).toString(); } /* for octave */
128 //}
129 //TODO fix problems with CobwebGraph
130
131 // ************************************************************************************************
132 %ignore operator<<(std::ostream&, const PropertySet&);
133 %ignore operator>>(std::istream&,PropertySet&);
134 %include "../include/dai/properties.h"
135 %extend dai::PropertySet {
136 inline void __setitem__(char *name, char *val) {
137 self->set(std::string(name), std::string(val));
138 }
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
143 // ************************************************************************************************
144 %ignore dai::IndexFor::operator++;
145 %rename(toInt) dai::IndexFor::operator size_t() const;
146 %ignore dai::Permute::operator[];
147 %ignore dai::multifor::operator++;
148 %ignore dai::multifor::operator[];
149 %rename(toInt) dai::multifor::operator size_t() const;
150 %ignore dai::State::operator++;
151 %rename(toInt) dai::State::operator size_t() const;
152 %ignore dai::State::operator const std::map<Var,size_t>&;
153 %include "../include/dai/index.h"
154 %extend dai::IndexFor {
155 inline void next() { return (*self)++; }
156 };
157 %extend dai::Permute {
158 inline size_t __getitem__(int i) const {return (*self)[i];} /* for python */
159 inline size_t __paren__(int i) const {return (*self)[i];} /* for octave */
160 };
161 %extend dai::multifor {
162 inline void next() { return (*self)++; }
163 inline size_t __getitem__(int i) const {return (*self)[i];} /* for python */
164 inline size_t __paren__(int i) const {return (*self)[i];} /* for octave */
165 };
166 %extend dai::State {
167 inline void next() { return (*self)++; }
168 };
169
170 // ************************************************************************************************
171 %include "../include/dai/daialg.h"
172 //TODO: why do the following lines not work?
173 //%template(DAIAlgFG) dai::DAIAlg<dai::FactorGraph>;
174 //%template(DAIAlgRG) dai::DAIAlg<dai::RegionGraph>;
175 //%template(DAIAlgCG) dai::DAIAlg<dai::CobwebGraph>;
176
177 // ************************************************************************************************
178 %include "../include/dai/alldai.h"
179
180 // ************************************************************************************************
181 %ignore dai::BP::operator=;
182 %include "../include/dai/bp.h"
183
184 // ************************************************************************************************
185 %include "../include/dai/fbp.h"
186
187 // ************************************************************************************************
188 %include "../include/dai/trwbp.h"
189
190 // ************************************************************************************************
191 %include "../include/dai/mf.h"
192
193 // ************************************************************************************************
194 %include "../include/dai/hak.h"
195
196 // ************************************************************************************************
197 %include "../include/dai/lc.h"
198
199 // ************************************************************************************************
200 %include "../include/dai/jtree.h"
201
202 // ************************************************************************************************
203 %ignore dai::TreeEP::operator=;
204 %include "../include/dai/treeep.h"
205
206 // ************************************************************************************************
207 %include "../include/dai/mr.h"
208
209 // ************************************************************************************************
210 %include "../include/dai/gibbs.h"
211
212 // ************************************************************************************************
213 %include "../include/dai/cbp.h"
214
215 // ************************************************************************************************
216 %include "../include/dai/decmap.h"
217
218 // ************************************************************************************************
219 %include "../include/dai/glc.h"