# Path: Utility.py
# def l2(x):
# def apply_scale(w, a, b):
# def logabsdiffexp(x, y):
#     def f(x, y):
# def logit_mean(x):
# def digest(x):
# def tree():
# def lift_tree(src, dst):
# def init_latex_rendering():
# def draw_confidence(a, m, S, levels = [0.95]):


import numpy as np
    import ctypes
            import sys; sys.exit()
from scipy import optimize as opt
from Utility import logsumexp, logabsdiffexp, digest, apply_scale
#!/usr/bin/env python

# Algorithms for working for random binary matrices with margin constraints
# Daniel Klein, 5/11/2012

from __future__ import division


# Get machine precision; used to prevent divide by zero
eps0 = np.spacing(0)

# See if C support code can be loaded
try:

    c_double_p = ctypes.POINTER(ctypes.c_double)
    c_int_p = ctypes.POINTER(ctypes.c_int)
    c_int = ctypes.c_int
    c_double = ctypes.c_double

    support_library = ctypes.cdll.LoadLibrary('./support.so')

    support_library.fill_G.argtypes = [c_int_p, c_int, c_int, c_int,
                                       c_double_p, c_double_p, c_double_p]
    support_library.fill_G.restype = ctypes.c_void_p
    def fill_G(r, r_max, m, n, wopt, logwopt, G):
        arr_r = np.ascontiguousarray(r, dtype='int32')
        arr_wopt = np.ascontiguousarray(wopt, dtype='float64')
        arr_logwopt = np.ascontiguousarray(logwopt, dtype='float64')
        arr_G = np.ascontiguousarray(G, dtype='float64')


# Path: Utility.py
# def l2(x):
# def apply_scale(w, a, b):
# def logabsdiffexp(x, y):
#     def f(x, y):
# def logit_mean(x):
# def digest(x):
# def tree():
# def lift_tree(src, dst):
# def init_latex_rendering():
# def draw_confidence(a, m, S, levels = [0.95]):


# Path: BinaryMatrix.py
import numpy as np
    import ctypes
            import sys; sys.exit()
from scipy import optimize as opt
from Utility import logsumexp, logabsdiffexp, digest, apply_scale

#!/usr/bin/env python

# Algorithms for working for random binary matrices with margin constraints
# Daniel Klein, 5/11/2012

from __future__ import division


# Get machine precision; used to prevent divide by zero
eps0 = np.spacing(0)

# See if C support code can be loaded
try:

    c_double_p = ctypes.POINTER(ctypes.c_double)
    c_int_p = ctypes.POINTER(ctypes.c_int)
    c_int = ctypes.c_int
    c_double = ctypes.c_double

    support_library = ctypes.cdll.LoadLibrary('./support.so')

    support_library.fill_G.argtypes = [c_int_p, c_int, c_int, c_int,
                                       c_double_p, c_double_p, c_double_p]
    support_library.fill_G.restype = ctypes.c_void_p
    def fill_G(r, r_max, m, n, wopt, logwopt, G):
        arr_r = np.ascontiguousarray(r, dtype='int32')
        arr_wopt = np.ascontiguousarray(wopt, dtype='float64')
        arr_logwopt = np.ascontiguousarray(logwopt, dtype='float64')
        arr_G = np.ascontiguousarray(G, dtype='float64')


        support_library.fill_G(arr_r.ctypes.data_as(c_int_p), r_max, m, n,