# Path: src/utils/mpiutil.py
# def collect_int(i,comm = MPI.COMM_WORLD,root=0):
# def bcast_int(i,comm = MPI.COMM_WORLD,root=0):
# def bcast_string(s,comm = MPI.COMM_WORLD,root=0):
# def bcast_array_1d(array,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_arrays(data,nbr_col,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_data(data,nbr_col,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_data_1d(data,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_strings(s_list,comm = MPI.COMM_WORLD,root=0):
# def collect_array_(data_array,nbr_col,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# 
# Path: src/utils/jsonutil.py
# class ObjJsonEncoder(ArrayEncoder):
#     def default(self, o):
#         if hasattr(o, 'encode_json'):
#             return(o.encode_json())
#         return super(ObjJsonEncoder, self).default(o)
# 
# def class_decoder(obj, Cls, **kwargs):
#     '''
#         Cls can be a dictionary of classes or a single class.
#     '''
#     if not '__type__'in obj or obj['__type__'] == 'np.ndarray':
#         return array_decoder(obj)
#     #print "type = {}".format(obj['__type__'])
#     try:
#         objCls = Cls[obj['__type__']]
#     except TypeError:
#         objCls = Cls
#     del obj['__type__']
#     #print "obj.keys() = {}".format(obj.keys())
#     obj_decode = construct_from_dict(obj, objCls, **kwargs)
#     #print "{} constructed from dict".format(objCls)
#     for arg in obj:
#         setattr(obj_decode, arg, obj[arg])
#     return obj_decode


from mpi4py import MPI
from scipy import io, sparse
from .utils import mpiutil
from .utils.jsonutil import ObjJsonEncoder, class_decoder
import numpy as np
import collections
import warnings
import os
import pickle
import json
        self.ii += 1
        if self.ii == self.batch:
            self.add_classif_fr()
            for classif_ in self.classif:
                classif_[:] = -1
            self.ii = 0
        for j, GMM in enumerate(hGMM.GMMs):
            self.classif[j][:, self.ii] = GMM.x[:]

    def add_classif_fr(self):
        try:
            classif_freq_loc = self.classif_freq_loc
        except:
            classif_freq_loc = [np.zeros((cl.shape[0], self.K+self.noise_class), dtype='i') for cl in self.classif]
        for j, cl in enumerate(self.classif):
            for ii in range(cl.shape[0]):
                cnt = collections.Counter(cl[ii, :])
                del cnt[self.classif_dtype(-1)]
                classif_freq_loc[j][ii, cnt.keys()] += cnt.values()
        self.classif_freq_loc = classif_freq_loc

    def postproc(self, high_memory=False):
        '''
            Post-processing production iterations
        '''
        super(HMElog, self).postproc(high_memory)
        if not self.ii == self.batch:
            self.add_classif_fr()
        del self.classif
        if self.rank == 0 and high_memory:

# Path: src/utils/mpiutil.py
# def collect_int(i,comm = MPI.COMM_WORLD,root=0):
# def bcast_int(i,comm = MPI.COMM_WORLD,root=0):
# def bcast_string(s,comm = MPI.COMM_WORLD,root=0):
# def bcast_array_1d(array,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_arrays(data,nbr_col,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_data(data,nbr_col,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_data_1d(data,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# def collect_strings(s_list,comm = MPI.COMM_WORLD,root=0):
# def collect_array_(data_array,nbr_col,nptype,mpitype,comm = MPI.COMM_WORLD,root=0):
# 
# Path: src/utils/jsonutil.py
# class ObjJsonEncoder(ArrayEncoder):
#     def default(self, o):
#         if hasattr(o, 'encode_json'):
#             return(o.encode_json())
#         return super(ObjJsonEncoder, self).default(o)
# 
# def class_decoder(obj, Cls, **kwargs):
#     '''
#         Cls can be a dictionary of classes or a single class.
#     '''
#     if not '__type__'in obj or obj['__type__'] == 'np.ndarray':
#         return array_decoder(obj)
#     #print "type = {}".format(obj['__type__'])
#     try:
#         objCls = Cls[obj['__type__']]
#     except TypeError:
#         objCls = Cls
#     del obj['__type__']
#     #print "obj.keys() = {}".format(obj.keys())
#     obj_decode = construct_from_dict(obj, objCls, **kwargs)
#     #print "{} constructed from dict".format(objCls)
#     for arg in obj:
#         setattr(obj_decode, arg, obj[arg])
#     return obj_decode


# Path: src/HMlog.py
from mpi4py import MPI
from scipy import io, sparse
from .utils import mpiutil
from .utils.jsonutil import ObjJsonEncoder, class_decoder
import numpy as np
import collections
import warnings
import os
import pickle
import json

        self.ii += 1
        if self.ii == self.batch:
            self.add_classif_fr()
            for classif_ in self.classif:
                classif_[:] = -1
            self.ii = 0
        for j, GMM in enumerate(hGMM.GMMs):
            self.classif[j][:, self.ii] = GMM.x[:]

    def add_classif_fr(self):
        try:
            classif_freq_loc = self.classif_freq_loc
        except:
            classif_freq_loc = [np.zeros((cl.shape[0], self.K+self.noise_class), dtype='i') for cl in self.classif]
        for j, cl in enumerate(self.classif):
            for ii in range(cl.shape[0]):
                cnt = collections.Counter(cl[ii, :])
                del cnt[self.classif_dtype(-1)]
                classif_freq_loc[j][ii, cnt.keys()] += cnt.values()
        self.classif_freq_loc = classif_freq_loc

    def postproc(self, high_memory=False):
        '''
            Post-processing production iterations
        '''
        super(HMElog, self).postproc(high_memory)
        if not self.ii == self.batch:
            self.add_classif_fr()
        del self.classif
        if self.rank == 0 and high_memory:

            self.classif_freq = mpiutil.collect_arrays(self.classif_freq_loc)