Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/ein16/synth/d2/obj_ex.py
ViewVC logotype

Diff of /branches/ein16/synth/d2/obj_ex.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4242, Thu Jul 21 14:43:40 2016 UTC revision 4243, Thu Jul 21 17:54:34 2016 UTC
# Line 123  Line 123 
123  #-------------- binary operators  ----------------------  #-------------- binary operators  ----------------------
124  def writeex(e):  def writeex(e):
125      #print (e)      #print (e)
     # if it works continue  
126      f = open("rst/results_ex_1.txt", 'a+')      f = open("rst/results_ex_1.txt", 'a+')
127      f.write(e)      f.write(e)
128      f.close()      f.close()
# Line 136  Line 135 
135      writeex(pre)      writeex(pre)
136      x="\n\n operator: "+op1.name+ "("+str(op1.id) +")\n"      x="\n\n operator: "+op1.name+ "("+str(op1.id) +")\n"
137      for j in f:      for j in f:
138          [a,b]=j          x+= "\n cmd 1 2 : "+str(op1.id)+" "+str(i)+ " ("
139          x+= "\n cmd 1 2 : "+str(op1.id)+" "+str(i)+ " ("+ a.name+ ","+ b.name+")"          for k in j:
140                x+= k.name+ ","
141            x+=")"
142          i+=1          i+=1
143      writeex(x)      writeex(x)
144    
# Line 150  Line 151 
151  ps_unu_s_notd1 =    get_unu(scalarFldsnotd1) # all scalar fields  ps_unu_s_notd1 =    get_unu(scalarFldsnotd1) # all scalar fields
152  ps_unu_vec =        get_unu(vectorFlds) # all vector fields  ps_unu_vec =        get_unu(vectorFlds) # all vector fields
153  ps_unu_mat =        get_unu(matrixFlds) # all matrix fields  ps_unu_mat =        get_unu(matrixFlds) # all matrix fields
154    ps_unu_ten3 =       get_unu(ten3Flds)
155    # binary args
156    nonscalarsflds = vectorFlds+matrixFlds
157    # makes sure one arg is a field and the other has the same shape
158    ps_bin_add = get_modulate(l_all_F)
159    ps_bin_nonsca = get_modulate(nonscalarsflds)
160    #binary ops between a vector field and higher-order tensors with specific shape
161    # cross product
162    ps_bin_vec_cross =  get_vF_n(vectorFlds, 1,1)
163    # outer product
164    ps_bin_vec_outer =  get_outer_n(nonscalarsflds,1,3)
165    # inner product
166    ps_bin_vec_inner =  get_inner_n(nonscalarsflds,1,3)
167    ps_bin_sca_all =    get_mul()                  # one arg is a scalar
168    ps_bin_sca_second = get_division()          # second arg is a scalar
169    
170    def getEx_binsamenons(op1):
171        args = ps_bin_nonsca
172        itertys(op1, op1.name, args)
173        return  example(op1, args)
174    
175  def getEx_all(op1):  def getEx_all(op1):
176      return  example(op1, ps_unu_all)      args = ps_unu_all
177        itertys(op1, op1.name, args)
178        return  example(op1, args)
179  def getEx_vec(op1):  def getEx_vec(op1):
180      return  example(op1,  ps_unu_vec)      args = ps_unu_vec
181        itertys(op1, op1.name, args)
182        return  example(op1,  args)
183  def getEx_mat(op1):  def getEx_mat(op1):
184      return  example(op1, ps_unu_mat)      args = ps_unu_mat
185        itertys(op1, op1.name, args)
186        return  example(op1, args)
187    def getEx_ten3(op1):
188        args = ps_unu_ten3
189        itertys(op1, op1.name, args)
190        return example(op1, args)
191    def getEx_binall(op1):
192        # binary operator types are the same shape
193        args =  ps_bin_add
194        itertys(op1, op1.name, args)
195        return example(op1,  args)
196    def getEx_bincross(op1):
197        args = ps_bin_vec_cross
198        itertys(op1, op1.name, args)
199        return example(op1, args)
200    def getEx_binouter(op1):
201        args =  ps_bin_vec_outer
202        itertys(op1, op1.name, args)
203        return example(op1, args)
204    def getEx_bininner(op1):
205        args = ps_bin_vec_inner
206        itertys(op1, op1.name, args)
207        return example(op1, args)
208    def getEx_binscale(op1):
209        args = ps_bin_sca_all
210        itertys(op1, op1.name, args)
211        return example(op1, args)
212    def getEx_bindiv(op1):
213        args= ps_bin_sca_second
214        itertys(op1, op1.name, args)
215        return example(op1, args)
216    
217  # unary operators oragnzied by type of argument it accepts  #-------------- examples with operators and types  ----------------------
218    #### unary operators oragnzied by type of argument it accepts
219  #accepts scalars only  #accepts scalars only
220  ex_gradient = example(op_gradient, ps_unu_s)  # gradient  ex_gradient = example(op_gradient, ps_unu_s)  # gradient
221  # accepts vectors only  # accepts vectors only
# Line 174  Line 230 
230  ex_det = getEx_mat(op_det)                # det  ex_det = getEx_mat(op_det)                # det
231  ex_slicem0 = getEx_mat(op_slicem0)        # slice matrix  ex_slicem0 = getEx_mat(op_slicem0)        # slice matrix
232  ex_slicem1 = getEx_mat(op_slicem1)        # slice matrix  ex_slicem1 = getEx_mat(op_slicem1)        # slice matrix
233    # accepts only third order tensors
234    ex_slicet0 = getEx_ten3(op_slicet0)       # slice third order tensor
235    ex_slicet1 = getEx_ten3(op_slicet1)       # slice third order tensor
236  # accepts any types  # accepts any types
237  ex_probe = getEx_all(op_probe)            # probe  ex_probe = getEx_all(op_probe)            # probe
238  ex_neg = getEx_all(op_negation)           # negation  ex_neg = getEx_all(op_negation)           # negation
239  ex_norm = getEx_all(op_norm)              # norm  ex_norm = getEx_all(op_norm)              # norm
240  ex_normalize = getEx_all(op_normalize)    # normalize  ex_normalize = getEx_all(op_normalize)    # normalize
241    #### binary operators
242    ex_add = getEx_binall(op_add)             # addition
243    ex_subtract = getEx_binall(op_subtract)   # subtraction
244    ex_cross = getEx_bincross(op_cross)       # cross product
245    ex_outer = getEx_binouter(op_outer)       # outer product
246    ex_inner = getEx_bininner(op_inner)       # inner product
247    ex_scale = getEx_binscale (op_scale)      # scaling
248    ex_division = getEx_bindiv (op_division)  # division
249    ex_modulate = getEx_binsamenons(op_modulate)   # modulate
250    
251    # order of examples
   
   
252  exs_reg = [ex_probe, ex_neg, ex_norm, ex_normalize, ex_trace, ex_transpose, ex_det]  exs_reg = [ex_probe, ex_neg, ex_norm, ex_normalize, ex_trace, ex_transpose, ex_det]
253  exs_slice =[ex_slicem0,ex_slicem1, ex_slicev0, ex_slicev1]  exs_slice =[ex_slicem0,ex_slicem1, ex_slicev0, ex_slicev1,ex_slicet0, ex_slicet1]
254  exs_diff = [ex_gradient, ex_divergence, ex_curl, ex_jacobian]  exs_diff = [ex_gradient, ex_divergence, ex_curl, ex_jacobian]
255  exs_unary = exs_reg + exs_slice+exs_diff  exs_unary = exs_reg + exs_slice+exs_diff
256  #-------------- binary operators  ----------------------  exs_binary = [ex_add, ex_subtract, ex_cross, ex_outer, ex_inner, ex_scale, ex_division, ex_modulate]
 # binary args  
 # makes sure one arg is a field and the other has the same shape  
 ps_bin_add = get_add()  
 #binary ops between a vector field and higher-order tensors with specific shape  
 ps_bin_vec_cross =  get_vF_n(vectorFlds, 1,1)           # cross product  
 ps_bin_vec_outer =  get_outer_n(vectorFlds+matrixFlds,1,3)           # outer product  
 ps_bin_vec_inner =  get_inner_n(vectorFlds+matrixFlds,1,3)           # inner product  
 ps_bin_sca_all =    get_mul()                  # one arg is a scalar  
 ps_bin_sca_second = get_division()          # second arg is a scalar  
 #printing it out  
 itertys(op_outer, "ps_bin_vec_outer", ps_bin_vec_outer)  
 itertys(op_inner, "ps_bin_vec_innerr",ps_bin_vec_inner)  
 itertys(op_scale, "op_scale", ps_bin_sca_all)  
 itertys(op_division, "op_division", ps_bin_sca_second)  
 #binary opertaors  
 ex_add = example(op_add, ps_bin_add) #     addition  
 ex_subtract = example(op_subtract, ps_bin_add) # subtraction  
 ex_cross = example(op_cross, ps_bin_vec_cross) # cross product  
 ex_outer = example(op_outer, ps_bin_vec_outer) # outer product  
 ex_inner = example(op_inner, ps_bin_vec_inner) # inner product  
 ex_scale = example (op_scale, ps_bin_sca_all)   # scaling  
 ex_division= example (op_division, ps_bin_sca_second)   # 11 division  
   
 # order of examples  
 exs_binary = [ex_add, ex_subtract, ex_cross, ex_outer, ex_inner, ex_scale, ex_division]  
257  exs = exs_unary+exs_binary  exs = exs_unary+exs_binary
258    
259    i=0
260    for e in exs:
261        # if (not (i= e.opr.id)):
262        print "ex: "+str(i),e.opr.name, e.opr.id
263        i+=1
264    
265  def get_exname(opr_num):  def get_exname(opr_num):
266      n =len(exs)      n =len(exs)

Legend:
Removed from v.4242  
changed lines
  Added in v.4243

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0