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

SCM Repository

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

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

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

revision 4410, Fri Aug 12 18:28:32 2016 UTC revision 4411, Fri Aug 12 18:28:57 2016 UTC
# Line 147  Line 147 
147    
148  #evaluate jacob  #evaluate jacob
149  def fn_jacob(fld):  def fn_jacob(fld):
150        #print "inside jacob"
151      exp = field.get_data(fld)      exp = field.get_data(fld)
152      ityp = field.get_ty(fld)      ityp = field.get_ty(fld)
153      dim = field.get_dim(fld)      dim = field.get_dim(fld)
154      #print " exp1: ",exp1," exp2: ",exp2      #print " exp1: ",exp1," exp2: ",exp2
155        shape = fty.get_shape(ityp)
156      # vectors      # vectors
157      n = fty.get_vecLength(ityp) #vector      if(field.is_VectorField (fld)):
158            print "found a vector"
159            [n] = shape #vector
160      if(n!=dim):      if(n!=dim):
161         raise (" type not supported for jacob")         raise (" type not supported for jacob")
162      if(n==2):          if(dim==2):
163          return [[diff(exp[0],x), diff(exp[0],y)],          return [[diff(exp[0],x), diff(exp[0],y)],
164                  [diff(exp[1],x), diff(exp[1],y)]]                  [diff(exp[1],x), diff(exp[1],y)]]
165      elif(n==3):          elif(dim==3):
166          return  [[diff(exp[0],x), diff(exp[0],y), diff(exp[0],z)],          return  [[diff(exp[0],x), diff(exp[0],y), diff(exp[0],z)],
167                   [diff(exp[1],x), diff(exp[1],y), diff(exp[1],z)],                   [diff(exp[1],x), diff(exp[1],y), diff(exp[1],z)],
168                   [diff(exp[2],x), diff(exp[2],y), diff(exp[2],z)]]                   [diff(exp[2],x), diff(exp[2],y), diff(exp[2],z)]]
169      else:      else:
170                raise (" type not supported for jacob")
171        elif(field.is_Matrix (fld)):
172            #print "inside matrix"
173            [n,m] = shape #vector
174            if(n!=dim and n!=m):
175                raise (" type not supported for jacob")
176            elif(dim==2):
177                e_00 = exp[0][0]
178                e_10 = exp[1][0]
179                e_01 = exp[0][1]
180                e_11 = exp[1][1]
181                f_00 = [diff(e_00,x), diff(e_00,y)]
182                f_01 = [diff(e_01,x), diff(e_01,y)]
183                f_10 = [diff(e_10,x), diff(e_10,y)]
184                f_11 = [diff(e_11,x), diff(e_11,y)]
185                return [[f_00,f_01],[f_10,f_11]]
186            elif(dim==3):
187                e_00 = exp[0][0]
188                e_10 = exp[1][0]
189                e_20 = exp[2][0]
190                e_01 = exp[0][1]
191                e_11 = exp[1][1]
192                e_21 = exp[2][1]
193                e_02 = exp[0][2]
194                e_12 = exp[1][2]
195                e_22 = exp[2][2]
196                def diff_d3(e):
197                    return [diff(e,x), diff(e,y), diff(e,z)]
198                f_00 = diff_d3(e_00)
199                f_01 = diff_d3(e_01)
200                f_02 = diff_d3(e_02)
201                f_10 = diff_d3(e_10)
202                f_11 = diff_d3(e_11)
203                f_12 = diff_d3(e_12)
204                f_20 = diff_d3(e_20)
205                f_21 = diff_d3(e_21)
206                f_22 = diff_d3(e_22)
207                return [[f_00,f_01,f_02],[f_10,f_11,f_12],[f_20,f_21,f_22]]
208            else:
209                raise (" type not supported for jacob")
210        else:
211          raise "unsupported type for jacob"          raise "unsupported type for jacob"
212    
213  #evaluate norm  #evaluate norm
# Line 421  Line 466 
466      else:      else:
467          raise "unsupported trace"          raise "unsupported trace"
468    
469    #evaluate det
470    def fn_inverse(fld):
471        exp = field.get_data(fld)
472        ityp = field.get_ty(fld)
473        rtn=[]
474        if(field.is_Matrix(fld)):
475            [n, m] = fty.get_shape(ityp)
476            if (n!=m):
477                raise Exception("matrix is not identitical")
478            a = exp[0][0]
479            d = exp[1][1]
480            c = exp[1][0]
481            b = exp[0][1]
482            if(n==2):
483                denom = a*d-b*c
484                return [[d/denom,-b/denom],[-c/denom, a/denom]]
485            elif(n==3):
486                a = exp[0][0]
487                b = exp[0][1]
488                c = exp[0][2]
489                d = exp[1][0]
490                e = exp[1][1]
491                f = exp[1][2]
492                g = exp[2][0]
493                h = exp[2][1]
494                i = exp[2][2]
495                denom  =  a*(e*i-f*h)-b*(d*i-f*g)+c*(d*h-e*g)
496                num1 = [(e*i - f*h), -(b*i - c*h), (b*f - c*e)]
497                num2 = [-(d*i - f*g), (a*i -c*g), -(a*f - c*d)]
498                num3 = [(d*h - e*g), -(a*h - b*g),(a*e - b*d)]
499                num =[num1,num2,num3]
500    
501                rtn = []
502                for i in range(n):
503                    tmp = []
504                    for j in range(n):
505                        tmp.append(num[i][j]/denom)
506                    rtn.append(tmp)
507                return rtn
508            else:
509                raise "unsupported matrix field"
510        else:
511            raise "unsupported trace"
512    
513    
514    
515    
516    
517  #evaluate outer product  #evaluate outer product
518  def fn_outer(fld1, fld2):  def fn_outer(fld1, fld2):
# Line 742  Line 834 
834      elif(op_negation==fn_name): #negation      elif(op_negation==fn_name): #negation
835          return applyToM(exp, fn_negation)          return applyToM(exp, fn_negation)
836      elif(op_jacob==fn_name): #jacob      elif(op_jacob==fn_name): #jacob
837          return fn_jacob(fld)          #print "app u-m"
838            x = fn_jacob(fld)
839            #print "x", x
840            return x
841      elif(op_slicem0==fn_name) :      elif(op_slicem0==fn_name) :
842          return fn_slicem0(fld)          return fn_slicem0(fld)
843      elif(op_slicem1==fn_name):      elif(op_slicem1==fn_name):
# Line 753  Line 848 
848          return fn_transpose(fld)          return fn_transpose(fld)
849      elif(op_det==fn_name):      elif(op_det==fn_name):
850          return fn_det(fld)          return fn_det(fld)
851        elif(op_inverse == fn_name):
852            return fn_inverse(fld)
853      else:      else:
854          raise Exception("unsupported unary operator:"+ fn_name.name)          raise Exception("unsupported unary operator:"+ fn_name.name)
855    
# Line 1090  Line 1187 
1187  def eval_ten3_d3(pos0, pos1, pos2,ten3):  def eval_ten3_d3(pos0, pos1, pos2,ten3):
1188      rtn = []      rtn = []
1189      for i in ten3:      for i in ten3:
1190    
1191          for j in i:          for j in i:
1192    
1193              for v in j:              for v in j:
1194    
1195                  rtn.append(eval_d3(pos0, pos1, pos2, v))                  rtn.append(eval_d3(pos0, pos1, pos2, v))
1196      return rtn      return rtn
1197    
# Line 1130  Line 1230 
1230    
1231  def probeField(otyp1,pos, ortn):  def probeField(otyp1,pos, ortn):
1232      dim = fty.get_dim(otyp1)      dim = fty.get_dim(otyp1)
1233      print "output type"+otyp1.name      #print "output type"+otyp1.name
1234        #print "inside probe field ortn", ortn
1235      if (dim==nonefield_dim):      if (dim==nonefield_dim):
1236          #still need to flatten          #still need to flatten
1237          rtn = []          rtn = []

Legend:
Removed from v.4410  
changed lines
  Added in v.4411

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