# Path: cubical/kernels/generics.py
# def compute_2x2_inverse(x, xinv, flags, eps, flagbit):
# def compute_diag_inverse(x, xinv, flags, eps, flagbit):
# def compute_chisq(r, chisq):
# def compute_chisq_diag(r, chisq):
# def compute_chisq_offdiag(r, chisq):
# 
# Path: cubical/kernels/full_complex.py
# def allocate_vis_array(shape, dtype, zeros=False):
# def allocate_gain_array(shape, dtype, zeros=False):
# def allocate_flag_array(shape, dtype, zeros=False):
# def compute_residual(m, g, gh, r, t_int, f_int):
# def compute_jh(m, g, jh, t_int, f_int):
# def compute_jhr(jh, r, jhr, t_int, f_int):
# def compute_jhj(jh, jhj, t_int, f_int):
# def compute_update(jhr, jhjinv, upd):
# def compute_corrected(o, g, gh, corr, t_int, f_int):
# def apply_gains(m, g, gh, t_int, f_int):
# def right_multiply_gains(g, g_next, t_int, f_int):


from builtins import range
from numba import jit, prange
from cubical.kernels import generics
from cubical.kernels import full_complex
import numpy as np
import cubical.kernels

    n_dir = g.shape[0]
    n_tim = g.shape[1]
    n_fre = g.shape[2]
    n_ant = g.shape[3]

    g_dir = g_next.shape[0]

    broadcast_times = np.array([t//t_int for t in range(n_tim)])
    broadcast_freqs = np.array([f//f_int for f in range(n_fre)])
    broadcast_dirs = np.array([d%g_dir for d in range(n_dir)])

    for aa in prange(n_ant):
        for t in range(n_tim):
            bt = broadcast_times[t]
            for f in range(n_fre):
                bf = broadcast_freqs[f]
                for d in range(n_dir):
                    bd = broadcast_dirs[d]

                    g[d,t,f,aa,0,0] *= g_next[bd,bt,bf,aa,0,0]
                    g[d,t,f,aa,0,1] = 0
                    g[d,t,f,aa,1,0] = 0
                    g[d,t,f,aa,1,1] *= g_next[bd,bt,bf,aa,1,1]


# Map the J^H.J inversion method to a generic diagonal inversion.
compute_jhjinv = generics.compute_diag_inverse

# Map inversion to generic diagonal inverse.

# Path: cubical/kernels/generics.py
# def compute_2x2_inverse(x, xinv, flags, eps, flagbit):
# def compute_diag_inverse(x, xinv, flags, eps, flagbit):
# def compute_chisq(r, chisq):
# def compute_chisq_diag(r, chisq):
# def compute_chisq_offdiag(r, chisq):
# 
# Path: cubical/kernels/full_complex.py
# def allocate_vis_array(shape, dtype, zeros=False):
# def allocate_gain_array(shape, dtype, zeros=False):
# def allocate_flag_array(shape, dtype, zeros=False):
# def compute_residual(m, g, gh, r, t_int, f_int):
# def compute_jh(m, g, jh, t_int, f_int):
# def compute_jhr(jh, r, jhr, t_int, f_int):
# def compute_jhj(jh, jhj, t_int, f_int):
# def compute_update(jhr, jhjinv, upd):
# def compute_corrected(o, g, gh, corr, t_int, f_int):
# def apply_gains(m, g, gh, t_int, f_int):
# def right_multiply_gains(g, g_next, t_int, f_int):


# Path: cubical/kernels/diagdiag_complex.py
from builtins import range
from numba import jit, prange
from cubical.kernels import generics
from cubical.kernels import full_complex
import numpy as np
import cubical.kernels


    n_dir = g.shape[0]
    n_tim = g.shape[1]
    n_fre = g.shape[2]
    n_ant = g.shape[3]

    g_dir = g_next.shape[0]

    broadcast_times = np.array([t//t_int for t in range(n_tim)])
    broadcast_freqs = np.array([f//f_int for f in range(n_fre)])
    broadcast_dirs = np.array([d%g_dir for d in range(n_dir)])

    for aa in prange(n_ant):
        for t in range(n_tim):
            bt = broadcast_times[t]
            for f in range(n_fre):
                bf = broadcast_freqs[f]
                for d in range(n_dir):
                    bd = broadcast_dirs[d]

                    g[d,t,f,aa,0,0] *= g_next[bd,bt,bf,aa,0,0]
                    g[d,t,f,aa,0,1] = 0
                    g[d,t,f,aa,1,0] = 0
                    g[d,t,f,aa,1,1] *= g_next[bd,bt,bf,aa,1,1]


# Map the J^H.J inversion method to a generic diagonal inversion.
compute_jhjinv = generics.compute_diag_inverse

# Map inversion to generic diagonal inverse.

invert_gains = generics.compute_diag_inverse