Exemplo n.º 1
0
def convolve_third(S2, E3=(1,)):
    dL = len(E3) - 1
    L3, L2, L1 = S2.shape
    S3 = np.zeros((L3 + dL, L2, L1), dtype=S2.dtype)
    A = convolution_operator(E3, L3, False, False)
    for sum23 in xrange(L2):
        for T1 in xrange(L1):
            S3[:, sum23, T1] = A.dot(S2[:, sum23, T1])
    return S3
Exemplo n.º 2
0
def convolve_first(R, E1=(1,)):
    dL = len(E1) - 1
    L3, L2, L1 = R.shape
    S1 = np.zeros((L3, L2, L1 + L2 + L3 + dL), dtype=R.dtype)
    A = convolution_operator(E1, L1, False, False)
    for t3 in xrange(L3):
        for t2 in xrange(L2):
            S1[t3, t2, (t3 + t2):(t3 + t2 + L1 + dL)] = A.dot(R[t3, t2, :])
    return S1
Exemplo n.º 3
0
def convolve_second(S1, E2=(1,)):
    dL = len(E2) - 1
    L3, L2, L1 = S1.shape
    S2 = np.zeros((L3, L2 + L3 + dL, L1), dtype=S1.dtype)
    A = convolution_operator(E2, L2, False, False)
    for t3 in xrange(L3):
        for sum12 in xrange(L1):
            S2[t3, t3:(t3 + L2 + dL), sum12] = A.dot(S1[t3, :, sum12])
    return S2
Exemplo n.º 4
0
def convolve_third(S2, E3=(1, )):
    dL = len(E3) - 1
    L3, L2, L1 = S2.shape
    S3 = np.zeros((L3 + dL, L2, L1), dtype=S2.dtype)
    A = convolution_operator(E3, L3, False, False)
    for sum23 in xrange(L2):
        for T1 in xrange(L1):
            S3[:, sum23, T1] = A.dot(S2[:, sum23, T1])
    return S3
Exemplo n.º 5
0
def convolve_second(S1, E2=(1, )):
    dL = len(E2) - 1
    L3, L2, L1 = S1.shape
    S2 = np.zeros((L3, L2 + L3 + dL, L1), dtype=S1.dtype)
    A = convolution_operator(E2, L2, False, False)
    for t3 in xrange(L3):
        for sum12 in xrange(L1):
            S2[t3, t3:(t3 + L2 + dL), sum12] = A.dot(S1[t3, :, sum12])
    return S2
Exemplo n.º 6
0
def convolve_first(R, E1=(1, )):
    dL = len(E1) - 1
    L3, L2, L1 = R.shape
    S1 = np.zeros((L3, L2, L1 + L2 + L3 + dL), dtype=R.dtype)
    A = convolution_operator(E1, L1, False, False)
    for t3 in xrange(L3):
        for t2 in xrange(L2):
            S1[t3, t2, (t3 + t2):(t3 + t2 + L1 + dL)] = A.dot(R[t3, t2, :])
    return S1
Exemplo n.º 7
0
def R3_to_P3_alt(R, E_all=((1,), (1,), (1,)), trim=True, include_margin=True):
    conv_mat, shapes, slice_maps = convolution_parameters(R.shape, E_all)
    P3 = shift_time_indices(
        reduce(loop_matvec, zip(conv_mat, shapes[1:], slice_maps), R),
        E_all, trim, include_margin)

    try:
        return MetaArray(P3, ticks=expand_ticks(R, E_all), rw_freq=R.rw_freq)
    except AttributeError:
        return P3


def convolution_parameters((L3, L2, L1), E_all=((1,), (1,), (1,))):
    E3, E2, E1 = E_all
    conv_matrices = [convolution_operator(E1, L1, False, False),
                     convolution_operator(E2, L2, False, False),
                     convolution_operator(E3, L3, False, False)]
    d1, d2, d3 = (len(conv_matrices[i]) for i in xrange(3))
    M1 = L3 + L2 + d1
    M2 = L3 + d2
    M3 = d3
    shapes = [(L3, L2, L1), (L3, L2, M1), (L3, M2, M1), (M3, M2, M1)]
    slice_maps = [[((t3, t2, slice(t3 + t2, t3 + t2 + d1)), (t3, t2))
                   for t3 in xrange(L3) for t2 in xrange(L2)],
                  [((t3, slice(t3, t3 + d2), sum12), (t3, slice(None), sum12))
                   for t3 in xrange(L3) for sum12 in xrange(M1)],
                  [((slice(None), sum23, T1), (slice(None), sum23, T1))
                   for sum23 in xrange(M2) for T1 in xrange(M1)]]
    return conv_matrices, shapes, slice_maps
Exemplo n.º 8
0
                 include_margin=True):
    conv_mat, shapes, slice_maps = convolution_parameters(R.shape, E_all)
    P3 = shift_time_indices(
        reduce(loop_matvec, zip(conv_mat, shapes[1:], slice_maps), R), E_all,
        trim, include_margin)

    try:
        return MetaArray(P3, ticks=expand_ticks(R, E_all), rw_freq=R.rw_freq)
    except AttributeError:
        return P3


def convolution_parameters((L3, L2, L1), E_all=((1, ), (1, ), (1, ))):
    E3, E2, E1 = E_all
    conv_matrices = [
        convolution_operator(E1, L1, False, False),
        convolution_operator(E2, L2, False, False),
        convolution_operator(E3, L3, False, False)
    ]
    d1, d2, d3 = (len(conv_matrices[i]) for i in xrange(3))
    M1 = L3 + L2 + d1
    M2 = L3 + d2
    M3 = d3
    shapes = [(L3, L2, L1), (L3, L2, M1), (L3, M2, M1), (M3, M2, M1)]
    slice_maps = [[((t3, t2, slice(t3 + t2, t3 + t2 + d1)), (t3, t2))
                   for t3 in xrange(L3) for t2 in xrange(L2)],
                  [((t3, slice(t3, t3 + d2), sum12), (t3, slice(None), sum12))
                   for t3 in xrange(L3) for sum12 in xrange(M1)],
                  [((slice(None), sum23, T1), (slice(None), sum23, T1))
                   for sum23 in xrange(M2) for T1 in xrange(M1)]]
    return conv_matrices, shapes, slice_maps