Exemplo n.º 1
0
import ptychopy_1
from ptychopy_1 import make_sp_cof
import numpy as np
import p2p as p2p

B = np.reshape(np.asarray(range(24)) * 0.5, [6, 4])
A = make_sp_cof(2, 3, range(2), 0.5 * np.reshape(range(1, 7), [2, 3]), 2)
X = np.zeros([A.shape[1], 2 * B.shape[1]])
A_data = np.zeros((2 * len(A.data)))
A_data[0::2] = A.data

print("types A=", type(A), "types A.data=", type(A.data), "types A.indices=",
      type(A.indices), "types A.indptr=", type(A.indptr), "types B=", type(B))
print("types A.data[0]=", type(A.data[0]), "types A.indices[0]=",
      type(A.indices[0]), "types A.indptr[0]=", type(A.indptr[0]),
      "types B[0][0]=", type(B[0][0]))
p2p.py2petsc(A_data, A.indices, A.indptr, B, X)

print(A)
print("A.data=", A_data)
#print("A.indices=",A.indices)
#print("A.iptr=",A.indptr)
#print("B=",B)
#print("X=",X)

# print("printNPY")
# p2p.printNPY()
Exemplo n.º 2
0
def reconEBAS2d(y, f1, f2, gridx, gridy, mtype):
    symFilters = True
    if f2.shape[0] == 0:
        f2 = f1
    else:
        symFilters = False

    if gridy.shape[0] == 0:
        gridy = gridx
    else:
        symFilters = False
    [l1, d1] = f1.shape
    [l2, d2] = f2.shape
    if mtype == 'periodic':
        M = gridx.max() + 1
        N = gridy.max() + 1
    elif mtype == 'zeropadding':
        M = l1 - 1 + gridx.max()
        N = l2 - 1 + gridy.max()
    else:
        print('error')
    a = make_sp_cof(l1, d1, gridx, f1, M)
    y = np.reshape(y, (gridx.size * d1, gridy.size * d2), order='F')
    # replace the spsolve with p2p
    a_c = np.zeros((2 * len(a.data)))
    a_c[0::2] = np.real(a.data)
    a_c[1::2] = np.imag(a.data)
    p2p.py2petsc(a_c, a.indices, a.indptr, y)
    # replace the spsolve with p2p
    x = spsolve(a, y)
    if symFilters == False:
        a = make_sp_cof(l2, d2, gridy, f2, N)
    x = spsolve(a, np.transpose(x)) / 2
    x = np.reshape(x, (M, (2 * l1 - 1), N, (2 * l2 - 1)), order='F')
    x = x + np.conj(x[:, ::-1, :, ::-1])
    x_amp = np.sqrt(x[:, l1, :, l2])

    x[abs(x) == 0] = 1
    x = x / np.abs(x)
    indd0 = pDiag(np.array([M, M]), np.array(range(1 - l1, l1)))
    indd0 = np.unravel_index(indd0, np.array([M, M]))

    indd1 = pDiag(np.array([N, N]), np.array(range(1 - l2, l2)))
    indd1 = np.unravel_index(indd1, np.array([N, N]))

    indd1_0 = np.asarray(indd1[0])
    indd1_1 = np.asarray(indd1[1])
    indd1_0 = (indd1_0) * M
    indd1_1 = (indd1_1) * M

    i0 = np.reshape(indd0[0], (np.size(indd0[0]), 1), order='F') + np.reshape(
        indd1_0, (1, indd1_0.size), order='F')
    i1 = np.reshape(indd0[1], (np.size(indd0[1]), 1), order='F') + np.reshape(
        indd1_1, (1, indd1_1.size), order='F')

    x = csr_matrix((x.reshape((x.size), order='f'), (i0.reshape(
        (i0.size), order='f'), i1.reshape((i1.size), order='f'))),
                   shape=(M * N, M * N))
    u = np.asarray(eigs(x, 1)[1])
    u[u == 0] = 1
    u = u / np.abs(u)
    x = x_amp * np.reshape(u, (M, N), order='F')

    return x
Exemplo n.º 3
0
import ptychopy_1
from ptychopy_1 import make_sp_cof
import numpy as np
import p2p as p2p

B = np.reshape(np.asarray(range(16)) * 0.5, [4, 4])
A = make_sp_cof(2, 3, range(2), 0.5 * np.reshape(range(1, 7), [2, 3]), 2)
print("types A=", type(A), "types A.data=", type(A.data), "types A.indices=",
      type(A.indices), "types A.indptr=", type(A.indptr), "types B=", type(B))
print("types A.data[0]=", type(A.data[0]), "types A.indices[0]=",
      type(A.indices[0]), "types A.indptr[0]=", type(A.indptr[0]),
      "types B[0][0]=", type(B[0][0]))
p2p.py2petsc(A.data, A.indices, A.indptr, B)

# print(A)
print("A.data=", A.data)
print("A.indices=", A.indices)
print("A.iptr=", A.indptr)
print("B=", B)