import numpy as np
import ctypes

libPCA = ctypes.CDLL('../libPCA.so')  # CDLL加载库
print('load libPCA')

npsf = 2
npix = 3

libPCA.psfPCA.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]

Nstar = npsf
Mp    = npix*npix
NM    = Nstar*Mp
NN    = Nstar*Nstar
arr   = (ctypes.c_float*NM)()
basef = (ctypes.c_double*NM)()
coeff = (ctypes.c_double*NN)()

#psf1 = np.random.random([npix, npix])
#psf2 = np.random.random([npix, npix])
psfT  = np.random.random(Nstar*Mp)
arr[:] = psfT
libPCA.psfPCA(arr, Nstar, Mp, basef, coeff)

print('haha')
print(arr[:])
