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

SCM Repository

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

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

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

revision 4307, Fri Jul 29 19:29:48 2016 UTC revision 4308, Fri Jul 29 20:53:07 2016 UTC
# Line 169  Line 169 
169      return (k>0)      return (k>0)
170    
171  #type of field after operation is applied  #type of field after operation is applied
172    # note need to generalize for field and tensor operators
173    # note need to check if field for correct
174  def applyUnaryOp(op1,ityps):  def applyUnaryOp(op1,ityps):
175      ityp1=ityps[0]      ityp1=ityps[0]
176      print "itype1", ityp1      print "itype1", ityp1.name
177      k = ityp1.k      k = ityp1.k
178      dim = ityp1.dim      dim = ityp1.dim
179      ashape = ityp1.shape      ashape = ityp1.shape
180      name =  "op1 "+op1.name+"("+ityp1.name+")"      name =  "op1 "+op1.name+"("+ityp1.name+")"
181      #print "apply unary op", name, ashape      print "apply unary op", name, ashape
182      def same():      def same():
183          return (true, ityp1)          return (true, ityp1)
184      def err():      def err():
185          return (false, name)          return (false, name)
186      def mkTyp(shape):      def mkTyp(shape):
187            print "mark-a"
188          (tf, rty1) = shapeToTyhelper(shape, dim)          (tf, rty1) = shapeToTyhelper(shape, dim)
189          if(tf):          if(tf):
190                print "mark-b"
191              rtn1 = fty.convertTy(rty1, k)              rtn1 = fty.convertTy(rty1, k)
192              return (true, rtn1)              return (true, rtn1)
193          else:          else:
194                print "mark-c"
195              return err()              return err()
196    
197      def mkTyp_deductk(shape):      def mkTyp_deductk(shape):
# Line 202  Line 207 
207      if ((op_probe==op1) or (op_negation==op1) or (op_normalize==op1)):      if ((op_probe==op1) or (op_negation==op1) or (op_normalize==op1)):
208          return same() #type unaffected by operation          return same() #type unaffected by operation
209      elif(op_norm==op1):            # apply op_norm      elif(op_norm==op1):            # apply op_norm
210            print "norm "
211          return mkTyp([])          return mkTyp([])
212        elif (op_negationT==op1):
213    
214            return same() #type unaffected by operation
215      elif(fty.is_Scalar(ityp1)):      elif(fty.is_Scalar(ityp1)):
216          if(op_sqrt==op1):          if(op_sqrt==op1):
217              return same()              return same()
# Line 254  Line 263 
263          elif(op_transpose==op1):            # apply op_tranpose          elif(op_transpose==op1):            # apply op_tranpose
264              return mkTyp([m, n])              return mkTyp([m, n])
265          elif((op_trace==op1) or (op_det==op1)):          elif((op_trace==op1) or (op_det==op1)):
266              if(dim==2 or dim==3):              if(n==m and n>1):
267                  return mkTyp([])                  return mkTyp([])
268              else:              else:
269                  return err()                  return err()
# Line 322  Line 331 
331          if(fty.is_Vector(ityp1) and fty.is_Vector(ityp2)):          if(fty.is_Vector(ityp1) and fty.is_Vector(ityp2)):
332              n1 = fty.get_vecLength(ityp1)              n1 = fty.get_vecLength(ityp1)
333              n2 = fty.get_vecLength(ityp2)              n2 = fty.get_vecLength(ityp2)
334              if((n1==n2) and (n1==2) and (dim==2)):              if(not (n1==n2)):
335                  return (true, fty.convertTy(ty_scalarF_d2,k))                  return err()
336              elif((n1==n2) and (n1==3) and (dim==3)):              if(fty.is_Field(fldty)):
337                  return (true, fldty)                  if ((dim==2) and (n1==2)):
338                        return mkTyp([])
339                    elif((dim==3) and (n1==3)):
340                        return mkTyp([3])
341              else:              else:
342                  return err()                  return err()
343                else:
344                    if(n1==2):
345                        return mkTyp([])
346                    elif(n1==3):
347                        return mkTyp([3])
348                    else:
349                        return err()
350            else:
351          return err()          return err()
352      else:      else:
353          # rest of operators are non scalar          # rest of operators are non scalar
# Line 342  Line 362 
362              elif(op_outer==op1):              elif(op_outer==op1):
363                  return mkTyp(ashape+bshape)                  return mkTyp(ashape+bshape)
364              elif(op_doubledot==op1):              elif(op_doubledot==op1):
365                  if(fty.is_Matrix(ityp1) and fty.is_Matrix(ityp2)):                  if(len(ashape)>1):
366                      if(ashape==bshape):                      if(ashape==bshape):
367                          print "same shape"                          print "same shape"
368                          return mkTyp([])                          return mkTyp([])
# Line 366  Line 386 
386  ##################################################################################################  ##################################################################################################
387  # apply unary and binary operator  # apply unary and binary operator
388  def get_tshape(opr1, ishape):  def get_tshape(opr1, ishape):
389      print "getting tshape of", opr1.name, ishape      print "getting tshape of", opr1.name,"arg0=", ishape[0].name
390      arity=opr1.arity      arity=opr1.arity
391      if(arity==1):      if(arity==1):
392          return applyUnaryOp(opr1,ishape)          return applyUnaryOp(opr1,ishape)

Legend:
Removed from v.4307  
changed lines
  Added in v.4308

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