d60c9f11d747c0f0030745d07a829d4bd4155048
[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 %{
12 #include "../include/dai/var.h"
13 #include "../include/dai/smallset.h"
14 #include "../include/dai/varset.h"
15 #include "../include/dai/prob.h"
16 #include "../include/dai/factor.h"
17 #include "../include/dai/graph.h"
18 #include "../include/dai/bipgraph.h"
19 #include "../include/dai/factorgraph.h"
20 #include "../include/dai/util.h"
21 %}
22
23 %ignore dai::TProb::operator[];
24 %ignore dai::TFactor::operator[];
25
26 %ignore dai::Var::label() const;
27 %ignore dai::Var::states() const;
28
29 %include "../include/dai/util.h"
30 %include "../include/dai/var.h"
31 %include "../include/dai/smallset.h"
32 %template(SmallSetVar) dai::SmallSet< dai::Var >;
33 %include "../include/dai/varset.h"
34 %extend dai::VarSet {
35 inline void append(const dai::Var &v) { (*self) |= v; } /* for python, octave */
36 };
37
38 %include "../include/dai/prob.h"
39 %template(Prob) dai::TProb<dai::Real>;
40 %extend dai::TProb<dai::Real> {
41 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
42 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
43 inline dai::Real __paren(int i) const {return (*self).get(i);} /* for octave */
44 inline void __paren_asgn(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
45 };
46 %include "../include/dai/factor.h"
47 %extend dai::TFactor<dai::Real> {
48 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
49 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
50 inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
51 inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
52 };
53
54 %template(Factor) dai::TFactor<dai::Real>;
55 %include "../include/dai/graph.h"
56 %include "../include/dai/bipgraph.h"
57 %include "../include/dai/factorgraph.h"
58 %include "std_vector.i"
59 // TODO: typemaps for the vectors (input/output python arrays)
60 %inline{
61 typedef std::vector<dai::Factor> VecFactor;
62 typedef std::vector< VecFactor > VecVecFactor;
63 }
64 %template(VecFactor) std::vector< dai::Factor >;
65 %template(VecVecFactor) std::vector< VecFactor >;
66
67 %include "../include/dai/index.h"
68 %extend dai::multifor {
69 inline size_t __getitem__(int i) const {
70 return (*self)[i];
71 }
72 inline void next() {
73 return (*self)++;
74 }
75 };