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 3997, Sun Jun 19 15:55:49 2016 UTC revision 3998, Sun Jun 19 17:12:03 2016 UTC
# Line 183  Line 183 
183              elif(n1==3):              elif(n1==3):
184                  return (true,fty.convertTy(ty_mat3x3F_d3, k-1))                  return (true,fty.convertTy(ty_mat3x3F_d3, k-1))
185          else:          else:
186              return (false, ("curl not supported for this type: "+ityp1.name))              return (false, ("jacob not supported for this type: "+ityp1.name))
187        elif(op_norm==op1):            # apply op_norm
188            dim = ityp1.dim
189            k = ityp1.k
190            if((dim==2)):
191                return (true, fty.convertTy(ty_scalarF_d2, k))
192            elif(dim==3):
193                return (true, fty.convertTy(ty_scalarF_d3, k))
194            else:
195                return (false, ("norm not supported for this type: "+ityp1.name))
196        elif(op_normalize==op1):            # apply op_normalize
197            return (true, ityp1)
198        elif(op_slice==op1):            # apply op_slice
199            if(fty.is_Matrix(ityp1)):
200                k = ityp1.k
201                dim = ityp1.dim
202                shapeout = fty.drop_last(ityp1)
203                return (true, shapeToTy(shapeout, dim))
204            else:
205                return (false, " can not apply slice to scalar")
206        elif((op_trace==op1) or (op_det==op1)):
207            # apply op_trace
208            if(fty.is_Matrix(ityp1)):
209                k = ityp1.k
210                dim = ityp1.dim
211                [n, m] = fty.get_shape(ityp1)
212                if(n!=m):
213                     return (false, "non-symmetrical matrix")
214                if((dim==2)):
215                    return (true, fty.convertTy(ty_scalarF_d2, k))
216                elif(dim==3):
217                    return (true, fty.convertTy(ty_scalarF_d3, k))
218                else:
219                    return (false, " can not apply trace to nonmatrix")
220            else:
221                return (false, "apply trace to non-matrix")
222        elif(op_transpose==op1):            # apply op_tranpose
223            if(fty.is_Matrix(ityp1)):
224                k = ityp1.k
225                dim = ityp1.dim
226                [n, m] = fty.get_shape(ityp1)
227                return (true,  shapeToTy([m, n], dim))
228            else:
229                return (false, "apply tranpose to non-matrix")
230      else:      else:
231          raise Exception("operation not represented in unary operations:"+op1.name)          raise Exception("operation not represented in unary operations:"+op1.name)
232    
233  #type of field after operation is applied  #type of field after operation is applied
234  def applyBinaryOp(op1,ityps):  def applyBinaryOp(op1,ityps):
235      # print "iypes:",len(ityps),"-", ityps      # print "iypes:",len(ityps),"-", ityps
   
236      ityp1=ityps[0]      ityp1=ityps[0]
   
237      ityp2=ityps[1]      ityp2=ityps[1]
238    
239      #print "checking",op1.name,"-",ityp1.name,"-",ityp2.name      #print "checking",op1.name,"-",ityp1.name,"-",ityp2.name
240      (tf, fldty) = find_field(ityp1,ityp2) #assures same dimension for both fields      (tf, fldty) = find_field(ityp1,ityp2) #assures same dimension for both fields
   
241      if(not tf):      if(not tf):
242          return (false, "not the same dimension")          return (false, "not the same dimension")
   
243      k = fldty.k      k = fldty.k
244      dim = fldty.dim      dim = fldty.dim
   
245      if (op_add==op1) or (op_subtract==op1):      if (op_add==op1) or (op_subtract==op1):
246          if(ityp1.id==ityp2.id):          ashape = fty.get_shape(ityp1)
247            bshape = fty.get_shape(ityp2)
248            if(ashape==bshape):
249              return (true, ityp1) #type unaffected by operation              return (true, ityp1) #type unaffected by operation
250          else:          else:
251              return (false, "not the right shape")              return (false, "not the right shape")
252      elif(op_scale==op1):      elif(op_scale==op1):
   
253          if(fty.is_Scalar(ityp1) or fty.is_Scalar(ityp2)):          if(fty.is_Scalar(ityp1) or fty.is_Scalar(ityp2)):
254              shape1 = fty.get_shape(ityp1)              shape1 = fty.get_shape(ityp1)
255              shape2 = fty.get_shape(ityp2)              shape2 = fty.get_shape(ityp2)
# Line 219  Line 258 
258              return (true, rtn2)              return (true, rtn2)
259          else:          else:
260              return (false, "scaling applied to non scalar fields")              return (false, "scaling applied to non scalar fields")
261        elif(op_division==op1):
262            if(fty.is_Scalar(ityp2)):
263                shape1 = fty.get_shape(ityp1)
264                rty1 = shapeToTy(shape1, dim)
265                rtn2 = fty.convertTy(rty1, k)
266                return (true, rtn2)
267            else:
268                return (false, "division applied to non-scalar fields")
269      elif(op_outer==op1):      elif(op_outer==op1):
270          if(fty.is_Scalar(ityp1) or fty.is_Scalar(ityp2)):          if(fty.is_Scalar(ityp1) or fty.is_Scalar(ityp2)):
271              return  (false,  "outer product applied to scalar fields")              return  (false,  "outer product applied to scalar fields")

Legend:
Removed from v.3997  
changed lines
  Added in v.3998

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