# 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

    return A

##############################################################################
# Adapting Matlab code provided by Matt Harrison (matt_harrison@brown.edu).
##############################################################################

def clear_cache():
    _dict_canonical_scalings = {}
    _dict_conjugate = {}

_dict_canonical_scalings = {}
def canonical_scalings(w, r, c):
    """From weights and margins, find scalings to balance a matrix.

TODO: describe "rc" method.
    """
    w_hash = digest(w)
    hash = (w_hash, tuple(r), tuple(c))
    if hash in _dict_canonical_scalings:
        return _dict_canonical_scalings[hash]

    max_iter = 1000
    tol = 1e-8

    m, n = w.shape
    r = r.reshape((m,1))
    c = c.reshape((1,n))
    
    def sw_sums(a, b):

# 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


    return A

##############################################################################
# Adapting Matlab code provided by Matt Harrison (matt_harrison@brown.edu).
##############################################################################

def clear_cache():
    _dict_canonical_scalings = {}
    _dict_conjugate = {}

_dict_canonical_scalings = {}
def canonical_scalings(w, r, c):
    """From weights and margins, find scalings to balance a matrix.

TODO: describe "rc" method.
    """
    w_hash = digest(w)
    hash = (w_hash, tuple(r), tuple(c))
    if hash in _dict_canonical_scalings:
        return _dict_canonical_scalings[hash]

    max_iter = 1000
    tol = 1e-8

    m, n = w.shape
    r = r.reshape((m,1))
    c = c.reshape((1,n))
    
    def sw_sums(a, b):

        abw = apply_scale(w, a, b)