def findResolution(caponProcessor, srcFrames, resLimit, p_depth, fps=25.0, highres=True): capon = caponProcessor frames = srcFrames for frame in frames: capon.image_idx.updateValue(frame) capon.processData() capon.interpolateData() p1 = 0.5 + (1+1.5)*frame/fps p2 = -0.5 + (1-1.5)*frame/fps pc = (p1 + p2) / 2 p = [np.array([p1, p_depth]), np.array([p2, p_depth]), np.array([pc, p_depth])] amp_p = [] for i in range(len(p)): p_dist = np.linalg.norm(p[i]) p_angle = np.arctan(p[i][0]/p[i][1]) idx_range = np.argmin(abs(1000*capon.ranges_intrp-p_dist)) idx_angle = np.argmin(abs(capon.angles_intrp-p_angle)) if highres: amp_p.append(capon.img_cap_detected[idx_range][idx_angle]) else: amp_p.append(capon.img_das_detected[idx_range][idx_angle]) res = (amp_p[0] + amp_p[1])/2 - amp_p[2] if (res > resLimit): print 'Resolution measured to ', p1-p2, ' from', amp_p, ' in frame ', frame return p1 - p2
def testCholesky(self): # cho_solve(cho_factor(R), a) self.R = np.array([[3, 2], [2, 3]], dtype=complex) self.a = np.array([7, 7], dtype=complex) self.n = 2 Ria = np.linalg.solve(self.R, self.a) U = md.cholesky(self.R, self.n) UT = U.conjugate().transpose() y = ls.forwardSolve(UT, self.a, self.n) x = ls.backtrackSolve(U, y, self.n) self.almostEqual(Ria, x)
def processData(self): if VERBOSE: print 'Start processing image...' if self.multiFile: self.s = System(self.dataTag + ' %d' % (self.image_idx.value + 1)) self.Xd_i = self.s.data.Xd else: self.Xd_i = self.Xd[self.image_idx.value, :, :, :].copy() self.Xd_i = self.Xd_i[self.sliceAngleStart.value:self.sliceAngleEnd. value:self.sliceAngleStep.value, self.sliceRangeStart.value:self.sliceRangeEnd. value:self.sliceRangeStep.value, self.sliceElementStart.value:self.sliceElementEnd .value:self.sliceElementStep.value] self.Nx = self.Xd_i.shape[0] # No. beams self.Ny = self.Xd_i.shape[1] # No. range samples self.Nm = self.Xd_i.shape[2] # No. channels self.angles = self.s.data.angles.squeeze() self.angles = self.angles[self.sliceAngleStart.value:self.sliceAngleEnd .value:self.sliceAngleStep.value] self.ranges = self.s.data.ranges.squeeze() self.ranges = self.ranges[self.sliceRangeStart.value:self.sliceRangeEnd .value:self.sliceRangeStep.value] # Make delay and sum image if self.apod.value is 1: self.das_w = np.hamming(self.Nm) self.das_w_sub = np.hamming(self.L.value) else: self.das_w = np.ones(self.Nm) self.das_w_sub = np.ones(self.L.value) self.img_das = np.dot(self.Xd_i, self.das_w) / self.Nm if self.K.value > 0: self.img_das = self.img_das[:, self.K.value:-self.K. value] # truncate to get equal dim on das and capon image # init sub/beam-space matrix if self.Nb.value > 0: self.B = np.ones((self.Nb.value, self.L.value)) else: self.B = np.array([0]) # Make capon image res_gpu = getCaponCUDA.getCaponCUDAPy(self.Xd_i, 10.0**self.d.value, self.L.value, self.K.value, self.B, False, False) self.img_capon = res_gpu[0] self.capon_weights = res_gpu[2] #self.img_capon = self.img_das if VERBOSE: print 'getCaponCUDA return code: ', res_gpu[3] print 'done.'
def testCholesky(self): # cho_solve(cho_factor(R), a) self.R = np.array([[3,2],[2,3]],dtype=complex) self.a = np.array([7,7],dtype=complex) self.n = 2 Ria = np.linalg.solve(self.R, self.a) U = md.cholesky(self.R, self.n) UT = U.conjugate().transpose() y = ls.forwardSolve(UT, self.a, self.n) x = ls.backtrackSolve(U, y, self.n) self.almostEqual(Ria, x)
def findResolution(caponProcessor, srcFrames, resLimit, p_depth, fps=25.0, highres=True): capon = caponProcessor frames = srcFrames for frame in frames: capon.image_idx.updateValue(frame) capon.processData() capon.interpolateData() p1 = 0.5 + (1 + 1.5) * frame / fps p2 = -0.5 + (1 - 1.5) * frame / fps pc = (p1 + p2) / 2 p = [ np.array([p1, p_depth]), np.array([p2, p_depth]), np.array([pc, p_depth]) ] amp_p = [] for i in range(len(p)): p_dist = np.linalg.norm(p[i]) p_angle = np.arctan(p[i][0] / p[i][1]) idx_range = np.argmin(abs(1000 * capon.ranges_intrp - p_dist)) idx_angle = np.argmin(abs(capon.angles_intrp - p_angle)) if highres: amp_p.append(capon.img_cap_detected[idx_range][idx_angle]) else: amp_p.append(capon.img_das_detected[idx_range][idx_angle]) res = (amp_p[0] + amp_p[1]) / 2 - amp_p[2] if (res > resLimit): print 'Resolution measured to ', p1 - p2, ' from', amp_p, ' in frame ', frame return p1 - p2
def iterativeBuildUpRinv(Ainv, X, M, L): ''' Update Ainv with the data in X, using sub-arrays of length L. Remember to normalize X before calling this function. ''' newAinv = mynp.array(Ainv) K = M - L + 1; for l in range(K): newAinv = shermanMorrisonUp(X[l:l+L], newAinv, L) return newAinv
def iterativeBuildUpRinv(Ainv, X, M, L): ''' Update Ainv with the data in X, using sub-arrays of length L. Remember to normalize X before calling this function. ''' newAinv = mynp.array(Ainv) K = M - L + 1 for l in range(K): newAinv = shermanMorrisonUp(X[l:l + L], newAinv, L) return newAinv
def processData(self): if VERBOSE: print 'Start processing image...' if self.multiFile: self.s = System(self.dataTag + ' %d'%(self.image_idx.value+1)) self.Xd_i = self.s.data.Xd else: self.Xd_i = self.Xd[self.image_idx.value, :, :, :].copy() self.Xd_i = self.Xd_i[self.sliceAngleStart.value:self.sliceAngleEnd.value:self.sliceAngleStep.value, self.sliceRangeStart.value:self.sliceRangeEnd.value:self.sliceRangeStep.value, self.sliceElementStart.value:self.sliceElementEnd.value:self.sliceElementStep.value]; self.Nx = self.Xd_i.shape[0] # No. beams self.Ny = self.Xd_i.shape[1] # No. range samples self.Nm = self.Xd_i.shape[2] # No. channels self.angles = self.s.data.angles.squeeze() self.angles = self.angles[self.sliceAngleStart.value:self.sliceAngleEnd.value:self.sliceAngleStep.value] self.ranges = self.s.data.ranges.squeeze() self.ranges = self.ranges[self.sliceRangeStart.value:self.sliceRangeEnd.value:self.sliceRangeStep.value] # Make delay and sum image if self.apod.value is 1: self.das_w = np.hamming(self.Nm) self.das_w_sub = np.hamming(self.L.value) else: self.das_w = np.ones(self.Nm) self.das_w_sub = np.ones(self.L.value) self.img_das = np.dot(self.Xd_i, self.das_w) / self.Nm if self.K.value > 0: self.img_das = self.img_das[:,self.K.value:-self.K.value]# truncate to get equal dim on das and capon image # init sub/beam-space matrix if self.Nb.value > 0: self.B = np.ones((self.Nb.value, self.L.value)) else: self.B = np.array([0]) # Make capon image res_gpu = getCaponCUDA.getCaponCUDAPy(self.Xd_i, 10.0**self.d.value, self.L.value, self.K.value, self.B, False, False) self.img_capon = res_gpu[0] self.capon_weights = res_gpu[2] #self.img_capon = self.img_das if VERBOSE: print 'getCaponCUDA return code: ', res_gpu[3] print 'done.'
def start(s): PROFILE = False Xd_i = Xd[0, :, :, :] res = getCaponC.getCapon(Xd_i, regCoef, L, nTimeAverage, V, doForwardBackwardAveraging, verbose) img_capon_ampl = res[0] # Steering angles: M = s['M'][0] d = s['d'][0] c = s['c'][0] fc = s['fc'][0] D = M * d lmda = float(c) / fc # Get the relevant parameters. Todo: Make system.open() for this Xd = s.data.Xd Ni = Xd.shape[0] # No. realisations N = Xd.shape[1] # No. time samples (y-coordinates) Ny = N # No. y-coordinates in image Nx = Xd.shape[2] # No. x-coordinates in image Nm = Xd.shape[3] # No. channels # Capon parameters regCoef = 1.0 / 100 # Diagonal loading L = 16 # Subarray size <= N/2 (e.g. 16) nTimeAverage = 1 # Capon range-average window (+- this value) V = np.array([]) # Subspace matrix doForwardBackwardAveraging = False verbose = False Xd_i = Xd[0, :, :, :] res = getCaponC.getCapon(Xd_i, regCoef, L, nTimeAverage, V, doForwardBackwardAveraging, verbose) img_capon_ampl = res[0]
def testMVDRKernelPerformance(M=32,L=16,K=0): # c = 12345*6789 # print 'The result of 12345 x 6789 :', c # return c import framework.beamformer.capon.getCaponCUDA as getCaponCUDA # import scipy.interpolate as interpolate s = System('Holmengraa') r = [3000,9000] #Ny, Nx, M = s.data.Xd.shape Xd = s.data.Xd[r[0]:r[1],:,0:M] Nt = s.data.Nt[r[0]:r[1]] ext=(0,62.76,Nt.max(),Nt.min()) fs = s.data.fs Ny, Nx, M = Xd.shape das = Xd.sum(2) d = 0.01 # L = 16 # K = 0 V = np.array([]) # from time import sleep # sleep(7) Xd = Xd[:500,:100].copy() print " Running getCaponCUDA.getCaponCUDAPy(Xd[100x10xM=%d], d, L=%d, K, V, False, False)"%(M,L) mvdr1 = getCaponCUDA.getCaponCUDAPy(Xd, d, L, K, V, False, False)
def __init__(self, dataTag, multiFile=False): if multiFile: self.s = System(dataTag + ' %d' % 1) self.Xd = self.s.data.Xd self.Ni = self.s.data.NFrames # No. frames self.Nx = self.Xd.shape[0] # No. beams self.Ny = self.Xd.shape[1] # No. range samples self.Nm = self.Xd.shape[2] # No. channels else: self.s = System(dataTag) self.Xd = self.s.data.Xd self.Ni = self.Xd.shape[0] # No. frames self.Ny = self.Xd.shape[1] # No. range samples self.Nx = self.Xd.shape[2] # No. beams self.Nm = self.Xd.shape[3] # No. channels self.multiFile = multiFile self.dataTag = dataTag noReprocessing = False # self.sliceRangeStart = Parameter('Range slice start', 0, 1, self.Ny) # self.sliceAngleStart = Parameter('Angle slice start', 0, 1, self.Nx) # self.sliceElementStart = Parameter('Element slice start', 0, 1, self.Nm) # self.sliceRangeEnd = Parameter('Range slice end', self.Ny, 1, self.Ny) # self.sliceAngleEnd = Parameter('Angle slice end', self.Nx, 1, self.Nx) # self.sliceElementEnd = Parameter('Element slice end', self.Nm, 1, self.Nm) # self.sliceRangeStep = Parameter('Range slice step', 1, 1, self.Ny/2) # self.sliceAngleStep = Parameter('Angle slice step', 1, 1, self.Nx/2) # self.sliceElementStep = Parameter('Element slice step', 1, 1, self.Nm/2) self.sliceRangeStart = Parameter('Range slice start', self.Ny / 4, 1, self.Ny) self.sliceAngleStart = Parameter('Angle slice start', self.Nx / 5, 1, self.Nx) self.sliceElementStart = Parameter('Element slice start', 0, 1, self.Nm) self.sliceRangeEnd = Parameter('Range slice end', self.Ny * 3 / 4, 1, self.Ny) self.sliceAngleEnd = Parameter('Angle slice end', self.Nx * 4 / 5, 1, self.Nx) self.sliceElementEnd = Parameter('Element slice end', self.Nm, 1, self.Nm) self.sliceRangeStep = Parameter('Range slice step', 1, 1, self.Ny / 2) self.sliceAngleStep = Parameter('Angle slice step', 1, 1, self.Nx / 2) self.sliceElementStep = Parameter('Element slice step', 1, 1, self.Nm / 2) self.Ky = Parameter('Radial upsampling', 4, 1, 8, 1, noReprocessing) # Up-sampling factors self.Kx = Parameter('Lateral upsampling', 2, 1, 8, 1, noReprocessing) self.interp_method = 0 # 0 imag and real interp, 1 angle and radian interp, 2 fft2 interp self.Nb = Parameter('Beamspace dimension', 0, 0, self.Nm) # Dim. beamspace # Inital Capon parameters self.d = Parameter('Diagonal loading (power of 10)', -1, -5, 5) # Diagonal loading in percent self.L = Parameter('Subarray size', int(self.Nm / 2), 1, self.Nm) # Subarray size <= Nm/2 (e.g. 16) self.K = Parameter('Time averaging', 2, 0, (self.Ny - 1) / 2) # Capon range-average window (+- this value) self.B = np.array([0]) # Subspace matrix self.image_idx = Parameter('Frame no.', 0, 0, self.Ni - 1) self.minDynRange = Parameter('Min dynamic range', -20, -60, 60, 1, noReprocessing) self.maxDynRange = Parameter('Max dynamic range', 20, -60, 60, 1, noReprocessing) self.minDynRangeCapon = Parameter('Min dynamic range Capon', -20, -60, 60, 1, noReprocessing) self.maxDynRangeCapon = Parameter('Max dynamic range Capon', 20, -60, 60, 1, noReprocessing) self.fps = Parameter('Video fps', 10, 1, 50, 1, noReprocessing) # TODO: Move to gui # self.profile_on_off = Parameter('Profile plots on (1) off (0)', 1, 0, 1, 1, noReprocessing) self.save_single_plots = Parameter('Save single plots: on=1, off=0', 0, 0, 1, 1, noReprocessing) # TODO: Move to gui self.show_legends = Parameter('Show legends: on=1, off=0', 0, 0, 1, 1, noReprocessing) self.apod = Parameter('Apodization: 0=uniform, 1=hamming', 0, 0, 1) #self.compress = Parameter('Number of logs: 1=log(), 2=log(log())', 1, 1, 2, 1, noReprocessing) # profile position (Lateral and axial pattern is plotted, crossing at this position) self.profilePos = [10.0, 80.0, 0.0]
def __init__(self, dataTag, multiFile=False): if multiFile: self.s = System(dataTag + ' %d'%1) self.Xd = self.s.data.Xd self.Ni = self.s.data.NFrames # No. frames self.Nx = self.Xd.shape[0] # No. beams self.Ny = self.Xd.shape[1] # No. range samples self.Nm = self.Xd.shape[2] # No. channels else: self.s = System(dataTag) self.Xd = self.s.data.Xd self.Ni = self.Xd.shape[0] # No. frames self.Ny = self.Xd.shape[1] # No. range samples self.Nx = self.Xd.shape[2] # No. beams self.Nm = self.Xd.shape[3] # No. channels self.multiFile = multiFile self.dataTag = dataTag noReprocessing = False # self.sliceRangeStart = Parameter('Range slice start', 0, 1, self.Ny) # self.sliceAngleStart = Parameter('Angle slice start', 0, 1, self.Nx) # self.sliceElementStart = Parameter('Element slice start', 0, 1, self.Nm) # self.sliceRangeEnd = Parameter('Range slice end', self.Ny, 1, self.Ny) # self.sliceAngleEnd = Parameter('Angle slice end', self.Nx, 1, self.Nx) # self.sliceElementEnd = Parameter('Element slice end', self.Nm, 1, self.Nm) # self.sliceRangeStep = Parameter('Range slice step', 1, 1, self.Ny/2) # self.sliceAngleStep = Parameter('Angle slice step', 1, 1, self.Nx/2) # self.sliceElementStep = Parameter('Element slice step', 1, 1, self.Nm/2) self.sliceRangeStart = Parameter('Range slice start', self.Ny/4, 1, self.Ny) self.sliceAngleStart = Parameter('Angle slice start', self.Nx/5, 1, self.Nx) self.sliceElementStart = Parameter('Element slice start', 0, 1, self.Nm) self.sliceRangeEnd = Parameter('Range slice end', self.Ny*3/4, 1, self.Ny) self.sliceAngleEnd = Parameter('Angle slice end', self.Nx*4/5, 1, self.Nx) self.sliceElementEnd = Parameter('Element slice end', self.Nm, 1, self.Nm) self.sliceRangeStep = Parameter('Range slice step', 1, 1, self.Ny/2) self.sliceAngleStep = Parameter('Angle slice step', 1, 1, self.Nx/2) self.sliceElementStep = Parameter('Element slice step', 1, 1, self.Nm/2) self.Ky = Parameter('Radial upsampling', 4, 1, 8, 1, noReprocessing) # Up-sampling factors self.Kx = Parameter('Lateral upsampling', 2, 1, 8, 1, noReprocessing) self.interp_method = 0 # 0 imag and real interp, 1 angle and radian interp, 2 fft2 interp self.Nb = Parameter('Beamspace dimension', 0, 0, self.Nm) # Dim. beamspace # Inital Capon parameters self.d = Parameter('Diagonal loading (power of 10)', -1, -5, 5) # Diagonal loading in percent self.L = Parameter('Subarray size', int(self.Nm/2), 1, self.Nm) # Subarray size <= Nm/2 (e.g. 16) self.K = Parameter('Time averaging', 2, 0, (self.Ny-1)/2) # Capon range-average window (+- this value) self.B = np.array([0]) # Subspace matrix self.image_idx = Parameter('Frame no.', 0, 0, self.Ni-1) self.minDynRange = Parameter('Min dynamic range', -20, -60, 60, 1, noReprocessing) self.maxDynRange = Parameter('Max dynamic range', 20, -60, 60, 1, noReprocessing) self.minDynRangeCapon = Parameter('Min dynamic range Capon', -20, -60, 60, 1, noReprocessing) self.maxDynRangeCapon = Parameter('Max dynamic range Capon', 20, -60, 60, 1, noReprocessing) self.fps = Parameter('Video fps', 10, 1, 50, 1, noReprocessing) # TODO: Move to gui # self.profile_on_off = Parameter('Profile plots on (1) off (0)', 1, 0, 1, 1, noReprocessing) self.save_single_plots = Parameter('Save single plots: on=1, off=0', 0, 0, 1, 1, noReprocessing) # TODO: Move to gui self.show_legends = Parameter('Show legends: on=1, off=0', 0, 0, 1, 1, noReprocessing) self.apod = Parameter('Apodization: 0=uniform, 1=hamming', 0, 0, 1) #self.compress = Parameter('Number of logs: 1=log(), 2=log(log())', 1, 1, 2, 1, noReprocessing) # profile position (Lateral and axial pattern is plotted, crossing at this position) self.profilePos = [10.0, 80.0, 0.0]
def solveBiCG(A, b, x0, tol, itr): ''' Solves the complex linear system Ax = b using the complex-biconjugate-gradient method Arguments: A -- Coefficient matrix b -- Right-side vector x0 -- Initial solution (default: 0-vector) tol -- Stop solver when error is less than tol (default: 0) itr -- Stop solver after itr iterations -- default ''' # Check arguments m, n = len(A), len(A[0]) if m != n: raise Exception('Coefficient matrix is not square') if len(b) != n: raise Exception('Dimension mismatch between A and b') x = x0 # make origin as starting point if no x is passed # Calculate initial residual r = b - Ax0 and search direction p r0 = b - np.dot(A, x) r = r0 normr0 = np.euclidnorm(r0) if (np.euclidnorm(r) / normr0) <= tol: # break if error is less-than tolerance. # TODO: Should also test bir return x p = np.array(r) # init biresidual and bidirection bir = r.conjugate() bip = p.conjugate() numerator, denominator = 0, 0 alpha, betha = 0, 0 AH = np.conjugatetranspose( A ) # Simplification: since A is Hermitian and semi-positive definite in our case, we can avoid this step... if itr <= 0 or itr > m: itr = m for i in range(itr): # Calculate common matrix-vector products Ap = np.dot(A, p) AHbip = np.dot(AH, bip) # Calculate step-length parameter numerator = np.vdot(bir, r) denominator = np.vdot(bip, Ap) alpha = numerator / denominator # Obtain new solution x = x + (alpha * p) # Calculate new residual and biresidual # r = r - (alpha * Ap) for i in range(m): r[i] = r[i] - alpha * Ap[ i] # Calculate new residual and biresidual if np.euclidnorm(r) / normr0 <= tol: # TODO: Should also test bir return x bir = bir - (alpha.conjugate() * AHbip) # Calculate the biconjugacy coefficient numerator = np.vdot(AHbip, r) denominator = np.vdot(bip, Ap) betha = -1.0 * (numerator / denominator) # Obtain new search and bi-search-direction p = r + (betha * p) bip = bir + (betha.conjugate() * bip) return x
def solveBiCG(A, b, x0, tol, itr): ''' Solves the complex linear system Ax = b using the complex-biconjugate-gradient method Arguments: A -- Coefficient matrix b -- Right-side vector x0 -- Initial solution (default: 0-vector) tol -- Stop solver when error is less than tol (default: 0) itr -- Stop solver after itr iterations -- default ''' # Check arguments m,n = len(A),len(A[0]) if m != n: raise Exception('Coefficient matrix is not square') if len(b) != n: raise Exception('Dimension mismatch between A and b') x = x0 # make origin as starting point if no x is passed # Calculate initial residual r = b - Ax0 and search direction p r0 = b - np.dot(A, x) r = r0 normr0 = np.euclidnorm(r0) if (np.euclidnorm(r) / normr0) <= tol: # break if error is less-than tolerance. # TODO: Should also test bir return x p = np.array(r) # init biresidual and bidirection bir = r.conjugate() bip = p.conjugate() numerator,denominator = 0,0 alpha,betha = 0,0 AH = np.conjugatetranspose(A) # Simplification: since A is Hermitian and semi-positive definite in our case, we can avoid this step... if itr <= 0 or itr > m: itr = m for i in range(itr): # Calculate common matrix-vector products Ap = np.dot(A, p) AHbip = np.dot(AH, bip) # Calculate step-length parameter numerator = np.vdot(bir, r) denominator = np.vdot(bip, Ap) alpha = numerator / denominator # Obtain new solution x = x + (alpha * p) # Calculate new residual and biresidual # r = r - (alpha * Ap) for i in range(m): r[i] = r[i] - alpha * Ap[i] # Calculate new residual and biresidual if np.euclidnorm(r) / normr0 <= tol: # TODO: Should also test bir return x bir = bir - (alpha.conjugate() * AHbip) # Calculate the biconjugacy coefficient numerator = np.vdot(AHbip, r) denominator = np.vdot(bip, Ap) betha = -1.0 * (numerator / denominator) # Obtain new search and bi-search-direction p = r + (betha * p) bip = bir + (betha.conjugate() * bip) return x
def setUp(self): self.n = 3 self.A = np.array([[2.0, -1.0, 0.0], [-1.0, 2.0, -1.0], [0.0, -1.0, 2.0]],dtype=complex) self.A2 = np.array([[4.0, -2.0, 0.0], [-2.0, 4.0, -2.0], [0.0, -2.0, 4.0]],dtype=complex) self.R = np.array([[1.414213562373095, -0.707106781186547, 0.0], [0.0, 1.224744871391589, -0.816496580927726], [0.0, 0.0, 1.154700538379252]],dtype=complex) self.AA = np.array([[5, -4, 1], [-4, 6, -4], [1, -4, 5]],dtype=complex) self.B = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]],dtype=complex) self.BT = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]],dtype=complex) self.b1 = np.array([1.0, 1.0, 1.0],dtype=complex) self.x1 = np.array([3.0/2, 2.0, 3.0/2],dtype=complex) self.b2 = np.array([1, 2, 3],dtype=complex) self.x2 = np.array([5.0/2, 4, 7.0/2],dtype=complex) self.C = np.array([[1, 2, 3], [0, 1, 1], [0, 0, 1]],dtype=complex) self.b1c = np.array([1, 1, 1],dtype=complex) self.x1c = np.array([-2, 0, 1],dtype=complex) self.x1cT = np.array([1, -1, -1],dtype=complex) self.x0_zero = np.zeros((3,), dtype=complex) self.Ab2 = np.array([0, 0, 4],dtype=complex) self.Ab1 = np.array([1, 0, 1],dtype=complex) self.Ab1b1T = np.array([[3, 1, 3], [1, 6, 5], [3, 5, 11]],dtype=complex) self.invA = np.array([[0.750, 0.50, 0.250], [0.50, 1.0, 0.50], [0.250, 0.50, 0.750]],dtype=complex) self.invAb1b1T = np.array([[0.465909090909091, 0.045454545454545, -0.147727272727273], [0.045454545454545, 0.272727272727273, -0.136363636363636], [-0.147727272727273, -0.136363636363636, 0.193181818181818]],dtype=complex) self.complexA = np.array([[2.0, 3.0 + 1.0j, 2.0 - 2.0j], [3.0 - 1.0j, 9.0, -2.0j], [2.0 + 2.0j, 2.0j, 14.0]], dtype=complex) self.complexR = np.array([[1.414213562373095, 2.121320343559642 + 0.707106781186547j, 1.414213562373095 - 1.414213562373095j], [0.0, 2.0, -1.0 + 1.0j], [0.0, 0.0, 2.828427124746190]], dtype=complex) self.complexb = np.array([1.0, 1.0 + 1.0j, 1.0 - 2.0j], dtype=complex) self.complexy = np.array([0.707106781186547 - 0.0j, -0.250 + 0.750j, -0.353553390593273 - 0.883883476483184j], dtype=complex) self.complexx = np.array([1.593749999999999 - 0.06250j, -0.343750 + 0.281250j, -0.1250 - 0.31250j], dtype=complex) self.complexAb = np.array([2.0 - 2.0j, 8.0 + 6.0j, 14.0 - 24.0j], dtype=complex) self.but4 = np.array([[0.5]*4, [0.5, -0.5j, -0.5, 0.5j], [0.5, -0.5]*2, [0.5, 0.5j, -0.5, -0.5j]], dtype=complex) self.but3 = np.array([[0.577350269189626, 0.577350269189626, 0.577350269189626], [0.577350269189626, -0.288675134594813 - 0.50j, -0.288675134594813 + 0.50j], [0.577350269189626, -0.288675134594813 + 0.50j, -0.288675134594813 - 0.50j]], dtype=complex) self.bsComplexb = np.array([1.732050807568878 - 0.577350269189626j, 1.50 + 0.288675134594813j], dtype=complex) self.diag = 0.2 self.x = np.array([1.0, 1.0 + 1.0j, 1.0 - 2.0j, 2.0 + 1.0j], dtype=complex) self.complexAbbH = np.array([[10.0, 11.0 + 1.0j, 10.0 - 2.0j], [11.0 - 1.0j, 17.0, 8.0 - 2.0j], [10.0 + 2.0j, 8.0 + 2.0j, 22.0]], dtype=complex) self.complexInvAbbH = np.array([[1.067010309278351, -0.407216494845361 - 0.015463917525773j, -0.190721649484536 + 0.020618556701031j], [-0.407216494845361 + 0.015463917525773j, 0.247422680412371, 0.077319587628866 - 0.015463917525773j], [-0.190721649484536 - 0.020618556701031j, 0.077319587628866 + 0.015463917525773j, 0.087628865979381]], dtype=complex) self.complexInvA = np.array([[1.906250, -0.593750 - 0.156250j, -0.250 + 0.18750j], [-0.593750 + 0.156250j, 0.31250, 0.06250 - 0.06250j], [-0.250 - 0.18750j, 0.06250 + 0.06250j, 0.1250]], dtype=complex) self.complexA4x4 = np.array([[22.0, 8.0, 11.0 - 11.0j, 22.0 - 7.0j], [8.0, 22.0, 17.0 - 2.0j, 11.0 - 7.0j], [11.0 + 11.0j, 17.0 + 2.0j, 45.0, 23.0 - 5.0j], [22.0 + 7.0j, 11.0 + 7.0j, 23.0 + 5.0j, 37.0]], dtype=complex) self.U4x4 = np.array([[1.0000, 0.3636, 0.50 - 0.50j, 1.0 - 0.3182j], [0.0, 1.0, 0.6810 + 0.1048j, 0.1571 - 0.2333j], [0.0, 0.0, 1.0, 0.2776 - 0.3670j], [0.0, 0.0, 0.0, 1.0]], dtype=complex) self.D4x4 = np.array([22.0, 19.0909, 24.9381, 5.9806]) self.sonardata_R = np.array(np.load('./data/data_R.npy')) # created without diagonal loading self.sonardata_a = np.array(np.load('./data/data_a.npy')) self.sonardata_Ria = np.array(np.load('./data/data_Ria.npy')) self.sonardata_ar = np.array(np.load('./data/data_ar.npy')) self.sonardata_n = 32 # random data for testing self.L = L = 24 self.d = d = 100 U = np.triu(np.random.randn(L,L) + np.random.randn(L,L)*1j) + np.eye(L)*d self.randA = np.dot(U.conjugate().T, U) self.randb = np.random.randn(L) + np.random.randn(L)*1j
def collectResults(M=32,L=16): if QUIET: print "Collecting results for M=%d, L=%d"%(M,L) if not QUIET: print "############" print "## DEFAULT #" print "############" print "" functions=['gauss_solve','buildR_kernel','amplitude_capon'] timings_default = getTimings(functions=functions,M=M,L=L) memops_default = getMemoryOps(functions=functions,M=M,L=L) instructions_default = getInstructions(functions=functions,M=M,L=L) if not QUIET: print 'Runtimes: %d %d %d'%tuple(timings_default) print '' print 'Memory instructions (gld_request gst_request shared_load shared_store):' for i,key in enumerate(functions): a = [functions[i]] a.extend(memops_default[i]) print '%s: %d %d %d %d'%tuple(a) print '' print 'Instructions %d %d %d'%tuple(instructions_default) #print "############" #print "## DEFAULT #" #print "############" #print "" #print "Runtimes: 40700 2510 742" #print "" #print "Memory instructions (gld_request gst_request shared_load shared_store):" #print "gauss_solve: 160000 10000 7380000 2860000" #print "buildR_kernel: 10000 85000 555000 95000" #print "amplitude_capon: 15000 10000 245000 20000" #print "" #print "Instructions 65520464 7268280 2220345" if not QUIET: print "" print "###########" print "## MEMORY #" print "###########" print "" timings_memory = getTimings(app_name='testEfficiency_memcheck', functions=functions,M=M,L=L) memops_memory = getMemoryOps(app_name='testEfficiency_memcheck', functions=functions,M=M,L=L) instructions_memory = getInstructions(app_name='testEfficiency_memcheck', functions=functions,M=M,L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d'%tuple(timings_memory) print '' print 'Memory instructions diff (should be all zeros):' for i,key in enumerate(functions): a = [functions[i]] a.extend(memops_memory[i]-memops_default[i]) print '%s: %d %d %d %d'%tuple(a) print '' print 'Instructions %d %d %d'%tuple(instructions_memory) if not QUIET: print "" print "################" print "## MATH GLOBAL #" print "################" print "" timings_math = getTimings(app_name='testEfficiency_mathcheck_global', functions=functions,M=M,L=L) memops_math = getMemoryOps(app_name='testEfficiency_mathcheck_global', functions=functions,M=M,L=L) instructions_math = getInstructions(app_name='testEfficiency_mathcheck_global', functions=functions,M=M,L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d'%tuple(timings_math) print '' print 'Memory instructions diff (should be all zeros):' for i,key in enumerate(functions): a = [functions[i]] a.extend(memops_math[i]-memops_default[i]) print '%s: %d %d %d %d'%tuple(a) print '' print 'Instructions %d %d %d'%tuple(instructions_math) print "" print "################" print "## MATH SHARED #" print "################" print "" timings_math = getTimings(app_name='testEfficiency_mathcheck_shared', functions=functions,M=M,L=L) memops_math = getMemoryOps(app_name='testEfficiency_mathcheck_shared', functions=functions,M=M,L=L) instructions_math = getInstructions(app_name='testEfficiency_mathcheck_shared', functions=functions,M=M,L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d'%tuple(timings_math) print '' print 'Memory instructions diff (should be all zeros):' for i,key in enumerate(functions): a = [functions[i]] a.extend(memops_math[i]-memops_default[i]) print '%s: %d %d %d %d'%tuple(a) print '' print 'Instructions %d %d %d'%tuple(instructions_math) if not QUIET: print "" print "#########" print "## MATH #" print "#########" print "" timings_math = getTimings(app_name='testEfficiency_mathcheck', functions=functions,M=M,L=L) memops_math = getMemoryOps(app_name='testEfficiency_mathcheck', functions=functions,M=M,L=L) instructions_math = getInstructions(app_name='testEfficiency_mathcheck', functions=functions,M=M,L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d'%tuple(timings_math) print '' print 'Memory instructions diff (should be all zeros):' for i,key in enumerate(functions): a = [functions[i]] a.extend(memops_math[i]-memops_default[i]) print '%s: %d %d %d %d'%tuple(a) print '' print 'Instructions %d %d %d'%tuple(instructions_math) if not QUIET: print "" print "#########" print "## TOTAL #" print "#########" print "" # time_total = timings_default[0] + timings_default[1] # time_math = timings_math[0] + timings_math[1] # time_memory = timings_memory[0] + timings_memory[1] return np.array([timings_default[0],timings_default[1], timings_math[0], timings_math[1], timings_memory[0], timings_memory[1]])
def collectResults(M=32, L=16): if QUIET: print "Collecting results for M=%d, L=%d" % (M, L) if not QUIET: print "############" print "## DEFAULT #" print "############" print "" functions = ['gauss_solve', 'buildR_kernel', 'amplitude_capon'] timings_default = getTimings(functions=functions, M=M, L=L) memops_default = getMemoryOps(functions=functions, M=M, L=L) instructions_default = getInstructions(functions=functions, M=M, L=L) if not QUIET: print 'Runtimes: %d %d %d' % tuple(timings_default) print '' print 'Memory instructions (gld_request gst_request shared_load shared_store):' for i, key in enumerate(functions): a = [functions[i]] a.extend(memops_default[i]) print '%s: %d %d %d %d' % tuple(a) print '' print 'Instructions %d %d %d' % tuple(instructions_default) #print "############" #print "## DEFAULT #" #print "############" #print "" #print "Runtimes: 40700 2510 742" #print "" #print "Memory instructions (gld_request gst_request shared_load shared_store):" #print "gauss_solve: 160000 10000 7380000 2860000" #print "buildR_kernel: 10000 85000 555000 95000" #print "amplitude_capon: 15000 10000 245000 20000" #print "" #print "Instructions 65520464 7268280 2220345" if not QUIET: print "" print "###########" print "## MEMORY #" print "###########" print "" timings_memory = getTimings(app_name='testEfficiency_memcheck', functions=functions, M=M, L=L) memops_memory = getMemoryOps(app_name='testEfficiency_memcheck', functions=functions, M=M, L=L) instructions_memory = getInstructions(app_name='testEfficiency_memcheck', functions=functions, M=M, L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d' % tuple(timings_memory) print '' print 'Memory instructions diff (should be all zeros):' for i, key in enumerate(functions): a = [functions[i]] a.extend(memops_memory[i] - memops_default[i]) print '%s: %d %d %d %d' % tuple(a) print '' print 'Instructions %d %d %d' % tuple(instructions_memory) if not QUIET: print "" print "################" print "## MATH GLOBAL #" print "################" print "" timings_math = getTimings(app_name='testEfficiency_mathcheck_global', functions=functions, M=M, L=L) memops_math = getMemoryOps(app_name='testEfficiency_mathcheck_global', functions=functions, M=M, L=L) instructions_math = getInstructions( app_name='testEfficiency_mathcheck_global', functions=functions, M=M, L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d' % tuple(timings_math) print '' print 'Memory instructions diff (should be all zeros):' for i, key in enumerate(functions): a = [functions[i]] a.extend(memops_math[i] - memops_default[i]) print '%s: %d %d %d %d' % tuple(a) print '' print 'Instructions %d %d %d' % tuple(instructions_math) print "" print "################" print "## MATH SHARED #" print "################" print "" timings_math = getTimings(app_name='testEfficiency_mathcheck_shared', functions=functions, M=M, L=L) memops_math = getMemoryOps(app_name='testEfficiency_mathcheck_shared', functions=functions, M=M, L=L) instructions_math = getInstructions( app_name='testEfficiency_mathcheck_shared', functions=functions, M=M, L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d' % tuple(timings_math) print '' print 'Memory instructions diff (should be all zeros):' for i, key in enumerate(functions): a = [functions[i]] a.extend(memops_math[i] - memops_default[i]) print '%s: %d %d %d %d' % tuple(a) print '' print 'Instructions %d %d %d' % tuple(instructions_math) if not QUIET: print "" print "#########" print "## MATH #" print "#########" print "" timings_math = getTimings(app_name='testEfficiency_mathcheck', functions=functions, M=M, L=L) memops_math = getMemoryOps(app_name='testEfficiency_mathcheck', functions=functions, M=M, L=L) instructions_math = getInstructions(app_name='testEfficiency_mathcheck', functions=functions, M=M, L=L) if not QUIET: print 'Runtimes [ms]: %d %d %d' % tuple(timings_math) print '' print 'Memory instructions diff (should be all zeros):' for i, key in enumerate(functions): a = [functions[i]] a.extend(memops_math[i] - memops_default[i]) print '%s: %d %d %d %d' % tuple(a) print '' print 'Instructions %d %d %d' % tuple(instructions_math) if not QUIET: print "" print "#########" print "## TOTAL #" print "#########" print "" # time_total = timings_default[0] + timings_default[1] # time_math = timings_math[0] + timings_math[1] # time_memory = timings_memory[0] + timings_memory[1] return np.array([ timings_default[0], timings_default[1], timings_math[0], timings_math[1], timings_memory[0], timings_memory[1] ])