# Path: killMS/Array/NpShared.py
# def zeros(*args,**kwargs):
# def ToShared(Name,A):
# def DelArray(Name):
# def ListNames():
# def DelAll(key=None):
# def GiveArray(Name):
# def DicoToShared(Prefix,Dico,DelInput=False):
# def SharedToDico(Prefix):
#     def __init__(self,prefixName,Dico):
# def SharedObjectToDico(SObject):
# def PackListArray(Name,LArray):
# def UnPackListArray(Name):
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     S=SharedArray.create(Name,(1+NArray+NDimTot+TotSize,),dtype=dS)
#     S[0]=NArray
#         A=LArray[i]
#         A=LArray[i]
#     S=GiveArray(Name)
#         A=S[idx:idx+size].reshape(shape)
# class SharedDicoDescriptor():


import numpy as np
from killMS.Array import NpShared
        # gg=g.ravel()
        # #gg+=(np.random.randn(*gg.shape)+1j*np.random.randn(*gg.shape))*np.sqrt(np.diag(Ptot))/np.sqrt(2.)

        # # print Pa.shape,Q.shape
        # # print np.diag(Pa)
        # # print np.diag(Q)
        # # print np.diag(Ptot)
        # # print

        # return Ptot
        ##############

        # return Pa+Q
        if indDone.size<2: return Pa+Q
        
        # #########################
        # take scans where no solve has been done into account
        G=NpShared.GiveArray("%sSolsArray_G"%self.IdSharedMem)[indDone][:,self.iChanSol,self.iAnt,:,0,0]
        Gm=np.mean(G,axis=-1)
        dG=Gm[:-1]-Gm[1:]
        done0=NpShared.GiveArray("%sSolsArray_done"%self.IdSharedMem)
        done1=np.zeros((done0.size,),int)
        done1[1:1+dG.size]=(dG!=0)
        done1[0]=1
        done=(done0&done1)
        indDone=np.where(done==1)[0]
        if indDone.size<2: return Pa+Q
        # #########################
        
        t0=NpShared.GiveArray("%sSolsArray_t0"%self.IdSharedMem)[indDone]

# Path: killMS/Array/NpShared.py
# def zeros(*args,**kwargs):
# def ToShared(Name,A):
# def DelArray(Name):
# def ListNames():
# def DelAll(key=None):
# def GiveArray(Name):
# def DicoToShared(Prefix,Dico,DelInput=False):
# def SharedToDico(Prefix):
#     def __init__(self,prefixName,Dico):
# def SharedObjectToDico(SObject):
# def PackListArray(Name,LArray):
# def UnPackListArray(Name):
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     T=ClassTimeIt.ClassTimeIt("   SharedToDico")
#     S=SharedArray.create(Name,(1+NArray+NDimTot+TotSize,),dtype=dS)
#     S[0]=NArray
#         A=LArray[i]
#         A=LArray[i]
#     S=GiveArray(Name)
#         A=S[idx:idx+size].reshape(shape)
# class SharedDicoDescriptor():


# Path: killMS/Wirtinger/ClassEvolve.py
import numpy as np
from killMS.Array import NpShared

        # gg=g.ravel()
        # #gg+=(np.random.randn(*gg.shape)+1j*np.random.randn(*gg.shape))*np.sqrt(np.diag(Ptot))/np.sqrt(2.)

        # # print Pa.shape,Q.shape
        # # print np.diag(Pa)
        # # print np.diag(Q)
        # # print np.diag(Ptot)
        # # print

        # return Ptot
        ##############

        # return Pa+Q
        if indDone.size<2: return Pa+Q
        
        # #########################
        # take scans where no solve has been done into account
        G=NpShared.GiveArray("%sSolsArray_G"%self.IdSharedMem)[indDone][:,self.iChanSol,self.iAnt,:,0,0]
        Gm=np.mean(G,axis=-1)
        dG=Gm[:-1]-Gm[1:]
        done0=NpShared.GiveArray("%sSolsArray_done"%self.IdSharedMem)
        done1=np.zeros((done0.size,),int)
        done1[1:1+dG.size]=(dG!=0)
        done1[0]=1
        done=(done0&done1)
        indDone=np.where(done==1)[0]
        if indDone.size<2: return Pa+Q
        # #########################
        
        t0=NpShared.GiveArray("%sSolsArray_t0"%self.IdSharedMem)[indDone]

        t1=NpShared.GiveArray("%sSolsArray_t1"%self.IdSharedMem)[indDone]