C_centroidCloud(file ='%s' % l_cloudFile[cloud], stdWidth = G_f_stdWidth, rotations = G_numRotations) ) print("\tappending cloud matrix and norm vectors...") lM_cloudOrig.append(lC_cloud[cloud].cloud()) lM_cloud.append(lC_cloud[cloud].cloud()) lv_normOrig.append(cloud_normalize(lM_cloud[cloud])) lv_norm.append(lv_normOrig[cloud]) print("\tcreating boundary list holder...") ll_polygonPoints.append([]) print("\nPreprocessing complete.\n") # Now process the clouds, with possible iterative rotations if Gb_rotateClouds: l_rotaryPoints = misc.neighbours_findFast(2, G_depth, includeOrigin=True) else: l_rotaryPoints = [ np.array((0,0)) ] v_nonBaseOffset = np.array( (G_f_nonBaseOffsetX, G_f_nonBaseOffsetY)) l_rotaryPoints = l_rotaryPoints * v_reltranScale + v_nonBaseOffset v_indoffset = np.array( (G_depth, G_depth ) ) * 0.0; M_pvalInd = l_rotaryPoints.copy() + v_indoffset v_pval = np.zeros((len(M_pvalInd),1)) M_pvalflt = np.column_stack( (M_pvalInd, v_pval) ) M_pval = np.zeros((2*G_depth+1, 2*G_depth+1)) M_pvalmNorm = np.zeros((2*G_depth+1, 2*G_depth+1)) M_pvalvNorm = np.zeros((2*G_depth+1, 2*G_depth+1)) indexTotal = 0
def state_transition( self ): """ The state transition machine for the CAE; determines the "next" state from the "current". PRECONDITIONS: o The "current" == "next" state TRANSITION: o The "next" state is changed according to "current" state in a decoupled element-by-element fashion. POSTCONDITIONS: o Once each element in the "current" state has been processed, the "next" state is copied into the "current" state. o A state transition is now complete. o Returns the number of elements processed. Primitive support for multithreaded/parallelization is planned... """ # Process the current grid, and determine all the changes required to # transition to the next state. elementProcessedCount = 0 misc.tic() for row in np.arange( 0, self.m_rows ): for col in np.arange( 0, self.m_cols ): dict_nextStateNeighbourSpectra = {} A_neighbours = None key = str( row ) + ':' + str( col ) if self.__neighbors.has_key( key ): # we already have the neighbors A_neighbours = self.__neighbors[key] else: # we don't have the neighbors, so let's calculate them A_neighbours = \ misc.neighbours_findFast( 2, 1, np.array( ( row, col ) ), gridSize=np.array( ( self.m_rows, self.m_cols ) ), wrapGridEdges=False, returnUnion=True, includeOrigin=False ) self.__neighbors[key] = A_neighbours dict_nextStateNeighbourSpectra = \ self.dict_createFromGridLocations( A_neighbours ) deltaSelf, deltaNeighbour = \ self.mgg_current.spectrum_get( row, col ).nextStateDelta_determine( dict_nextStateNeighbourSpectra ) if deltaNeighbour: for update in deltaNeighbour.keys(): elementProcessedCount += 1 updateRule = deltaNeighbour[update] dict_nextStateNeighbourSpectra[update].nextState_process( updateRule ) print "Update loop time: %f seconds (%d elements processed)." % \ ( misc.toc(), elementProcessedCount ) # Now update the current state with the next state misc.tic() b_setFromArray = False if self.mb_syncGridSpectralArray: self.mgg_next.internals_sync( b_setFromArray ) print misc.toc( sysprint="Synchronization: %f seconds." ) misc.tic() # self.mgg_current = copy.deepcopy(self.mgg_next) # use cPickle instead of deepcopy self.mgg_current = cPickle.loads( cPickle.dumps( self.mgg_next, -1 ) ) print misc.toc( sysprint="next->current deepcopy: %f seconds.\n" ) return elementProcessedCount
#!/usr/bin/env python from _common import systemMisc as misc import numpy as np col2sort = lambda A: np.sort(A.view('i8,i8'), order=['f0','f1'], axis=0).view(np.int) misc.tic() A1 = misc.neighbours_find(2,2, np.array((4,4)), gridSize = np.array((5,5)), wrapGridEdges = True, returnUnion = True) misc.toc() print col2sort(A1.astype(int)) misc.tic() A2 = misc.neighbours_findFast(2,2, np.array((4,4)), gridSize = np.array((5,5)), wrapGridEdges = True, returnUnion = True, includeOrigin = True) misc.toc() print col2sort(A2)
#!/usr/bin/env python from _common import systemMisc as misc import numpy as np col2sort = lambda A: np.sort(A.view('i8,i8'), order=['f0', 'f1'], axis=0).view( np.int) misc.tic() A1 = misc.neighbours_find(2, 2, np.array((4, 4)), gridSize=np.array((5, 5)), wrapGridEdges=True, returnUnion=True) misc.toc() print col2sort(A1.astype(int)) misc.tic() A2 = misc.neighbours_findFast(2, 2, np.array((4, 4)), gridSize=np.array((5, 5)), wrapGridEdges=True, returnUnion=True, includeOrigin=True) misc.toc() print col2sort(A2)