Changeset 932
- Timestamp:
- 07/02/19 15:05:16 (5 years ago)
- Location:
- codes/icosagcm/devel/Python/dynamico/dev
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/dynamico/dev/meshes.py
r931 r932 9 9 10 10 class MeshData(numba.NumbaData): 11 signature=(int64, 'primal_num dual_num edge_num',12 int32[:], 'primal_deg left right',13 int32[:,:], 'primal_edge primal_ne',14 float64[:], 'le_de le de lon_e lat_e lon_v lat_v Ai Av')15 11 def to_dynamico(self): 16 12 max_primal_deg, max_dual_deg, max_trisk_deg = [x.shape[1] for x in self.primal_edge, self.dual_edge, self.trisk] -
codes/icosagcm/devel/Python/dynamico/dev/numba.py
r931 r932 10 10 def data(self): 11 11 """Returns a jitclass instance containing attributes copied from self, using self.signature which is of the form type,names,type,names ... where names is a string 'attr1 attr2 attr3' containing space-separated names of attributes of self. Those attributes are declared to numba with the type preceding them. The result of data() can be used as argument to a @jit function.""" 12 cls = self.__class__.__name__ 12 13 spec = [] 13 for item in self.signature: 14 if isinstance(item,str): 15 spec = spec + [(name,thetype) for name in item.split(' ')] 16 else: 17 thetype=item 14 for name in dir(self): 15 attr = getattr(self,name) 16 if not name.startswith('__') and not callable(attr): 17 tp = None 18 if isinstance(attr, int): tp=int64 19 if isinstance(attr, float): tp=float64 20 if isinstance(attr, np.ndarray): 21 dtype=attr.dtype 22 if dtype == np.int32 : dtype=int32 23 elif dtype == np.float64 : dtype=float64 24 else: dtype=None 25 if dtype is None: print('Unknown dtype ', attr.dtype) 26 27 if len(attr.shape)==1 : tp = dtype[:] 28 elif len(attr.shape)==2 : tp = dtype[:,:] 29 elif len(attr.shape)==3 : tp = dtype[:,:,:] 30 else: print('%s.%s is a numpy array with unsupported rank >3'%(cls,name)) 31 32 if tp is None: 33 print('Type of attribute %s.%s is not recognized'%(cls,name), type(attr)) 34 else: 35 spec.append( (name, tp) ) 36 18 37 @numba.jitclass(spec) 19 38 class JitClass(object): 20 39 def __init__(self): pass 40 21 41 data=JitClass() 22 42 for name,thetype in spec: 23 print( ' Copying to %s.%s : '%(self.__class__.__name__, name), type(getattr(self,name)))43 print( 'Making %s.%s available @jit functions : '%(self.__class__.__name__, name), type(getattr(self,name))) 24 44 setattr(data, name, getattr(self,name)) 25 45 return data
Note: See TracChangeset
for help on using the changeset viewer.