# Path: Echobase/Common/errors.py
# def check_dims(arr, nd):
# def check_type(obj, typ):
# def check_function(obj):
# def check_path(path):
# def make_path(path):
# def check_path_overwrite(path):
# def check_has_key(dictionary, key_ref):
# 
# Path: Echobase/Common/display.py
# def my_display(txt, verbose, str_path=None):
#     '''
#     Print string to the screen
# 
#     Parameters
#     ----------
#         txt: str
#             Text to be printed to the screen
# 
#         verbose: bool
#             Option to robustly automate whether
#             text gets printed to the screen
# 
#         str_path: str
#             Path to store stdout
#     '''
# 
#     if str_path is not None:
#         old_stdout = sys.stdout
#         sys.stdout = open(str_path, 'a+')
# 
#     if verbose:
#         sys.stdout.write(txt)
#         sys.stdout.flush()
# 
#     if str_path is not None:
#         sys.stdout = old_stdout


import sys
import time
import numpy as np
import scipy.sparse as sp
from ....Common import errors
from ....Common.display import my_display
                    dtot = dtot + dH[k] - dH[comm_id_i]
                    dstep = dstep + dH[k] - dH[comm_id_i]

                    # Update community lookup table with change
                    comm_lut = comm_lut.tocoo()
                    comm_lut.col[comm_lut.row == i] = u[k]
                    comm_lut = comm_lut.tocsc()

                    # Update Community ID
                    comm_id[i] = u[k]

            t_phaseEnd = time.time()
            i_phaseCount = len(np.unique(comm_id))
            my_display('   --- Found %4d communities in %.5f sec \r' %
                    (i_phaseCount, t_phaseEnd-t_phaseStart),
                    verbose)

        comm_id = _tidyconfig(comm_id)
        for i in xrange(n_comm_id):
            comm_vec[comm_vec == i] = comm_id[i]

        # When community assignment converges
        # compute quality function measurement
        # of the community assignments
        if np.array_equal(comm_vec_old, comm_vec):
            Q = np.sum(np.diag(ml_mod_matr_new))
            break

        ml_mod_matr_new = _metanetwork(ml_mod_matr, comm_vec)


# Path: Echobase/Common/errors.py
# def check_dims(arr, nd):
# def check_type(obj, typ):
# def check_function(obj):
# def check_path(path):
# def make_path(path):
# def check_path_overwrite(path):
# def check_has_key(dictionary, key_ref):
# 
# Path: Echobase/Common/display.py
# def my_display(txt, verbose, str_path=None):
#     '''
#     Print string to the screen
# 
#     Parameters
#     ----------
#         txt: str
#             Text to be printed to the screen
# 
#         verbose: bool
#             Option to robustly automate whether
#             text gets printed to the screen
# 
#         str_path: str
#             Path to store stdout
#     '''
# 
#     if str_path is not None:
#         old_stdout = sys.stdout
#         sys.stdout = open(str_path, 'a+')
# 
#     if verbose:
#         sys.stdout.write(txt)
#         sys.stdout.flush()
# 
#     if str_path is not None:
#         sys.stdout = old_stdout


# Path: Echobase/Network/Partitioning/Module/community.py
import sys
import time
import numpy as np
import scipy.sparse as sp
from ....Common import errors
from ....Common.display import my_display

                    dtot = dtot + dH[k] - dH[comm_id_i]
                    dstep = dstep + dH[k] - dH[comm_id_i]

                    # Update community lookup table with change
                    comm_lut = comm_lut.tocoo()
                    comm_lut.col[comm_lut.row == i] = u[k]
                    comm_lut = comm_lut.tocsc()

                    # Update Community ID
                    comm_id[i] = u[k]

            t_phaseEnd = time.time()
            i_phaseCount = len(np.unique(comm_id))
            my_display('   --- Found %4d communities in %.5f sec \r' %
                    (i_phaseCount, t_phaseEnd-t_phaseStart),
                    verbose)

        comm_id = _tidyconfig(comm_id)
        for i in xrange(n_comm_id):
            comm_vec[comm_vec == i] = comm_id[i]

        # When community assignment converges
        # compute quality function measurement
        # of the community assignments
        if np.array_equal(comm_vec_old, comm_vec):
            Q = np.sum(np.diag(ml_mod_matr_new))
            break

        ml_mod_matr_new = _metanetwork(ml_mod_matr, comm_vec)


    my_display('\n', verbose)