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 4235, Tue Jul 19 22:26:44 2016 UTC revision 4236, Wed Jul 20 03:02:00 2016 UTC
# Line 44  Line 44 
44          #print ("["+f.name+","+g.name+"]")          #print ("["+f.name+","+g.name+"]")
45      return rtn      return rtn
46    
47  #binary operators between vector field  #is type represented in list of fields
48    def outsupported(f,b):
49        bshape = fty.get_shape(f)+fty.get_shape(b)
50        if (len(bshape)>4):
51            return False
52        dim = f.dim
53        (tf, _) = shapeToTyhelper(bshape, dim)
54        return tf
55    
56    #binary operators between flds fld (limited in some way)
57  # and higher order tensor/tensor field  # and higher order tensor/tensor field
58  def get_vF_n(lb, ub):  def get_inner_n(fld, lb, ub):
59      rtn = []      rtn = []
60      for f in vectorFlds:      for f in fld:
61          for b in l_all:          for b in l_all:
62              n = len(fty.get_shape(b))              n = len(fty.get_shape(b))
63              if((fty.is_Field(b)) and (not check_dim(f,b))): # check equal dim              if((fty.is_Field(b)) and (not check_dim(f,b))): # check equal dim
# Line 57  Line 66 
66                  continue                  continue
67              elif(n<lb):              elif(n<lb):
68                  continue                  continue
69                if(not  outsupported(f,b)):
70                    continue
71              if((fty.get_last_ix(f)==fty.get_first_ix(b))):              if((fty.get_last_ix(f)==fty.get_first_ix(b))):
72                  #print ("["+f.name+","+b.name+"]")                  #print ("["+f.name+","+b.name+"]")
73                  rtn.append([f,b])                  rtn.append([f,b])
# Line 66  Line 77 
77                      rtn.append([b,f])                      rtn.append([b,f])
78      return rtn      return rtn
79    
80  #-------------- make list of type args  ----------------------  
81    #binary operators between flds fld (limited in some way)
82    # and higher order tensor/tensor field
83    def get_outer_n(fld, lb, ub):
84        rtn = []
85        for f in fld:
86            for b in l_all:
87                if(not outsupported(f,b)):
88                    continue
89                n = len(fty.get_shape(b))
90                if((fty.is_Field(b)) and (not check_dim(f,b))): # check equal dim
91                    continue
92                elif(n>ub):
93                    continue
94                elif(n<lb):
95                    continue
96    
97                rtn.append([f,b])
98                if(not fty.isEq_id(f,b)):
99                    rtn.append([b,f])
100        return rtn
101    
102    #binary operators between flds fld (limited in some way)
103    # and higher order tensor/tensor field
104    def get_vF_n(fld, lb, ub):
105        rtn = []
106        for f in fld:
107            for b in l_all:
108                if(not outsupported(f,b)):
109                    continue
110                n = len(fty.get_shape(b))
111                if((fty.is_Field(b)) and (not check_dim(f,b))): # check equal dim
112                    continue
113                elif(n>ub):
114                    continue
115                elif(n<lb):
116                    continue
117    
118                rtn.append([f,b])
119                if(not fty.isEq_id(f,b)):
120                    rtn.append([b,f])
121        return rtn
122    
123    #-------------- binary operators  ----------------------
124    def writeex(e):
125        print (e)
126        # if it works continue
127        f = open("rst/results_ex_1.txt", 'a+')
128        f.write(e)
129        f.close()
130    
131    
132    def itertys(op1, pre, f):
133        print pre
134        print len(f)
135        i = 0
136        writeex(pre)
137        x="\n\n operator: "+op1.name+"\n"
138        for j in f:
139            [a,b]=j
140            x+= "\n"+str(i)+ ":"+ a.name+ ","+ b.name
141            i+=1
142        writeex(x)
143    
144    
145    #--------------unary operators  ----------------------
146  # ps_..  list of unary args   [[a],[b],..]  # ps_..  list of unary args   [[a],[b],..]
147  # unary args  # unary args
148  ps_unu_all =        get_unu(l_all_F)    # all fields  ps_unu_all =        get_unu(l_all_F)    # all fields
# Line 86  Line 162 
162  ex_trace = example(op_trace, ps_unu_mat)            # trace  ex_trace = example(op_trace, ps_unu_mat)            # trace
163  ex_transpose = example(op_transpose, ps_unu_mat)    # tranpose  ex_transpose = example(op_transpose, ps_unu_mat)    # tranpose
164  ex_det = example(op_det, ps_unu_mat)            # det  ex_det = example(op_det, ps_unu_mat)            # det
165    #ex_sine = example(op_sine, ps_unu_s)                # sine
166    exs_unary = [ex_probe, ex_negation, ex_gradient, ex_divergence, ex_curl, ex_jacobian, ex_norm, ex_normalize, ex_trace, ex_transpose, ex_det]
167    #-------------- binary operators  ----------------------
168  # binary args  # binary args
169  # makes sure one arg is a field and the other has the same shape  # makes sure one arg is a field and the other has the same shape
170  ps_bin_add = get_add()  ps_bin_add = get_add()
171  #binary ops between a vector field and higher-order tensors with specific shape  #binary ops between a vector field and higher-order tensors with specific shape
172  ps_bin_vec_cross =  get_vF_n(1,1)           # cross product  ps_bin_vec_cross =  get_vF_n(vectorFlds, 1,1)           # cross product
173  ps_bin_vec_outer =  get_vF_n(1,2)           # outer product  ps_bin_vec_outer =  get_outer_n(vectorFlds+matrixFlds,1,3)           # outer product
174  ps_bin_vec_inner =  get_vF_n(1,3)           # inner product  ps_bin_vec_inner =  get_inner_n(vectorFlds+matrixFlds,1,3)           # inner product
175  ps_bin_sca_all =    get_mul()                  # one arg is a scalar  ps_bin_sca_all =    get_mul()                  # one arg is a scalar
176  ps_bin_sca_second = get_division()          # second arg is a scalar  ps_bin_sca_second = get_division()          # second arg is a scalar
177    #printing it out
178    itertys(op_outer, "ps_bin_vec_outer", ps_bin_vec_outer)
179    itertys(op_inner, "ps_bin_vec_innerr",ps_bin_vec_inner)
180    itertys(op_scale, "op_scale", ps_bin_sca_all)
181  #binary opertaors  #binary opertaors
182  ex_add = example(op_add, ps_bin_add) #     addition  ex_add = example(op_add, ps_bin_add) #     addition
183  ex_subtract = example(op_subtract, ps_bin_add) # subtraction  ex_subtract = example(op_subtract, ps_bin_add) # subtraction
# Line 105  Line 187 
187  ex_scale = example (op_scale, ps_bin_sca_all)   # scaling  ex_scale = example (op_scale, ps_bin_sca_all)   # scaling
188  ex_division= example (op_division, ps_bin_sca_second)   # 11 division  ex_division= example (op_division, ps_bin_sca_second)   # 11 division
189    
190  # order of edxamples  # order of examples
 exs_unary = [ex_probe, ex_negation, ex_gradient, ex_divergence, ex_curl, ex_jacobian, ex_norm, ex_normalize, ex_trace, ex_transpose, ex_det]  
191  exs_binary = [ex_add, ex_subtract, ex_cross, ex_outer, ex_inner, ex_scale, ex_division]  exs_binary = [ex_add, ex_subtract, ex_cross, ex_outer, ex_inner, ex_scale, ex_division]
   
192  exs = exs_unary+exs_binary  exs = exs_unary+exs_binary
193    
194    

Legend:
Removed from v.4235  
changed lines
  Added in v.4236

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