Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pyc
*.so
*.*~
factor_graph.cpp
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
branches:
only:
- master

language: python
notifications:
email: false
python:
- "2.7"
- "2.6"
before_install :
- sudo apt-get install -qq
language: python
notifications:
email: false
python:
- "2.7"
- "2.6"
before_install :
- sudo apt-get install -qq libboost-dev
install:
- pip install -r --use-mirrors requirements.txt
- python setup.py install
script: true
Empty file removed python/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions python/ad3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from factor_graph import PBinaryVariable, PFactorGraph, PMultiVariable
from simple_inference import simple_grid, general_graph
6 changes: 3 additions & 3 deletions python/simple_inference.py → python/ad3/simple_inference.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import itertools
import numpy as np
#from numpy.testing.utils import assert_array_almost_equal
from . import ad3
import factor_graph as fg


def simple_grid(unaries, pairwise, verbose=1):
height, width, n_states = unaries.shape

factor_graph = ad3.PFactorGraph()
factor_graph = fg.PFactorGraph()

multi_variables = []
for i in xrange(height):
Expand Down Expand Up @@ -52,7 +52,7 @@ def general_graph(unaries, edges, edge_weights, verbose=1, n_iterations=1000,
raise ValueError("Number of edge weights different from number of"
"edges")

factor_graph = ad3.PFactorGraph()
factor_graph = fg.PFactorGraph()
n_states = unaries.shape[-1]

multi_variables = []
Expand Down
6 changes: 3 additions & 3 deletions python/factor_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from libcpp cimport bool

# get the classes from the c++ headers

cdef extern from "ad3/Factor.h" namespace "AD3":
cdef extern from "../ad3/Factor.h" namespace "AD3":
cdef cppclass BinaryVariable:
BinaryVariable()
double GetLogPotential()
Expand All @@ -12,14 +12,14 @@ cdef extern from "ad3/Factor.h" namespace "AD3":
cdef cppclass Factor:
Factor()

cdef extern from "ad3/MultiVariable.h" namespace "AD3":
cdef extern from "../ad3/MultiVariable.h" namespace "AD3":
cdef cppclass MultiVariable:
int GetNumStates()
double GetLogPotential(int i)
void SetLogPotential(int i, double log_potential)


cdef extern from "ad3/FactorGraph.h" namespace "AD3":
cdef extern from "../ad3/FactorGraph.h" namespace "AD3":
cdef cppclass FactorGraph:
FactorGraph()
void SetVerbosity(int verbosity)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cython
73 changes: 73 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension
from distutils.command.build_clib import build_clib
from distutils.errors import DistutilsSetupError
from distutils import log


class build_libad3(build_clib):
def build_libraries(self, libraries):
for (lib_name, build_info) in libraries:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError(
"in 'libraries' option (library '%s'), " +
"'sources' must be present and must be " +
"a list of source filenames" % lib_name)
sources = list(sources)

log.info("building '%s' library", lib_name)

# First, compile the source code to object files in the library
# directory. (This should probably change to putting object
# files in a temporary build directory.)
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
extra_compile_args = build_info.get('extra_compile_args')
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=include_dirs,
extra_preargs=extra_compile_args,
debug=self.debug,
)

# Now "link" the object files together into a static library.
# (On Unix at least, this isn't really linking -- it just
# builds an archive. Whatever.)
self.compiler.create_static_lib(objects, lib_name,
output_dir=self.build_clib,
debug=self.debug)
libad3 = ('ad3', {
'sources': ['ad3/FactorGraph.cpp',
'ad3/GenericFactor.cpp',
'ad3/Factor.cpp',
'ad3/Utils.cpp'],
'include_dirs': ['.',
'./ad3',
'./Eigen'
],
'extra_compile_args': [
'-Wno-sign-compare',
'-Wall',
'-fPIC',
'-O3',
'-c',
'-fmessage-length=0'
],
})


setup(name='ad3',
package_dir = {'ad3': 'python/ad3'},
packages = ['ad3'],
libraries=[libad3],
cmdclass={'build_clib': build_libad3, 'build_ext' : build_ext},
ext_modules=[Extension("ad3.factor_graph",
["python/factor_graph.pyx"],
include_dirs = ["ad3"],
language="c++",
)])