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 4260, Mon Jul 25 19:03:07 2016 UTC revision 4261, Mon Jul 25 20:14:18 2016 UTC
# Line 171  Line 171 
171  #type of field after operation is applied  #type of field after operation is applied
172  def applyUnaryOp(op1,ityps):  def applyUnaryOp(op1,ityps):
173      ityp1=ityps[0]      ityp1=ityps[0]
174      #print "itype1", ityp1.name      print "itype1", ityp1
175      k = ityp1.k      k = ityp1.k
176      dim = ityp1.dim      dim = ityp1.dim
177      ashape = ityp1.shape      ashape = ityp1.shape
# Line 182  Line 182 
182      def err():      def err():
183          return (false, name)          return (false, name)
184      def mkTyp(shape):      def mkTyp(shape):
185          rty1 = shapeToTy(shape, dim)          (tf, rty1) = shapeToTyhelper(shape, dim)
186            if(tf):
187          rtn1 = fty.convertTy(rty1, k)          rtn1 = fty.convertTy(rty1, k)
         if (len(shape)>3):  
             return err()  
         else:  
188              return (true, rtn1)              return (true, rtn1)
189            else:
190                return err()
191    
192      def mkTyp_deductk(shape):      def mkTyp_deductk(shape):
193          if(k<1 and len(shape)>3):          if(k<1 and len(shape)>3):
194               return err()               return err()
195          else:          else:
196              rty1 = shapeToTy(shape, dim)              (tf, rty1) = shapeToTyhelper(shape, dim)
197                if(tf):
198              rtn1 = fty.convertTy(rty1, k-1)              rtn1 = fty.convertTy(rty1, k-1)
199              return (true, rtn1)              return (true, rtn1)
200                else:
201                    return err()
202      if ((op_probe==op1) or (op_negation==op1) or (op_normalize==op1)):      if ((op_probe==op1) or (op_negation==op1) or (op_normalize==op1)):
203          return same() #type unaffected by operation          return same() #type unaffected by operation
204      elif(op_norm==op1):            # apply op_norm      elif(op_norm==op1):            # apply op_norm
# Line 288  Line 291 
291      k = fldty.k      k = fldty.k
292      dim = fldty.dim      dim = fldty.dim
293      def err():      def err():
294            # type not supported
295          return (false, name)          return (false, name)
296      def mkTyp(shape):      def mkTyp(shape):
297          if (len(shape)>3):          if (len(shape)>3):
298              return err()              return err()
299          else:          else:
300              rty1 = shapeToTy(shape, dim)              (tf, rty1) = shapeToTyhelper(shape, dim)
301                if(tf):
302              rtn1 = fty.convertTy(rty1, k)              rtn1 = fty.convertTy(rty1, k)
303              return (true, rtn1)              return (true, rtn1)
304      def sameshape():              else:
305                    # don't yet have a type to represent this type
306                    # i.e. odd shape such as [2, 3, 3]
307                    return err()
308    
309        def sameshape(ty3):
310          if(ashape==bshape):          if(ashape==bshape):
311              return (true, fldty) #type unaffected by operation              return (true, ty3) #type unaffected by operation
312          else:          else:
313              return err()              return err()
314      if (op_add==op1) or (op_subtract==op1):      if (op_add==op1) or (op_subtract==op1):
315          return sameshape()          return sameshape(fldty)
316      elif(op_division==op1):      elif(op_division==op1):
317          if(fty.is_Scalar(ityp2)):          if(fty.is_Scalar(ityp2)):
318              return mkTyp(ashape)              return mkTyp(ashape)
# Line 328  Line 338 
338                  return err()                  return err()
339          else:          else:
340              if((op_modulate==op1)):              if((op_modulate==op1)):
341                  return sameshape()                  return sameshape(fldty)
342              elif(op_outer==op1):              elif(op_outer==op1):
343                  return mkTyp(ashape+bshape)                  return mkTyp(ashape+bshape)
344              elif(op_doubledot==op1):              elif(op_doubledot==op1):
345                  if(fty.is_Matrix(ityp1) or fty.is_Matrix(ityp2)):                  if(fty.is_Matrix(ityp1) and fty.is_Matrix(ityp2)):
346                        if(ashape==bshape):
347                            print "same shape"
348                      return mkTyp([])                      return mkTyp([])
349                  else:                  else:
350                            print "not the same shape"
351                            return err()
352                    else:
353                      return err()                      return err()
354              elif(op_inner==op1):              elif(op_inner==op1):
355                  n1 = fty.get_last_ix(ityp1)                  n1 = fty.get_last_ix(ityp1)

Legend:
Removed from v.4260  
changed lines
  Added in v.4261

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