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

SCM Repository

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

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

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

revision 4482, Thu Sep 1 20:43:01 2016 UTC revision 4483, Fri Sep 2 05:07:01 2016 UTC
# Line 3  Line 3 
3  from __future__ import unicode_literals  from __future__ import unicode_literals
4    
5  class operator:  class operator:
6      def __init__(self, id, name, arity, symb, placement, limit):      def __init__(self, id, name, arity, symb, placement, limit, fieldop):
7          self.id=id          self.id=id
8          self.name=name          self.name=name
9          self.arity=arity          self.arity=arity
10          self.symb=symb          self.symb=symb
11          self.placement=placement          self.placement=placement
12          self.limit = limit          self.limit = limit
13            self.fieldop =fieldop
14      def toStr(self):      def toStr(self):
15          self.name, str(arity)          self.name, str(arity)
16      def get_name(self):      def get_name(self):
# Line 42  Line 43 
43    
44    
45  id=0  id=0
46  #op_none= operator(id,"none", 1,"", place_left, limit_none)  #op_none= operator(id,"none", 1,"", place_left, limit_none, False)
47  op_negationT = operator(0,"negT", 1,"-", place_left, limit_none)  op_negationT = operator(0,"negT", 1,"-", place_left, limit_none, False)
48    
49  op_negation = operator(id,"neg", 1,"-", place_left, limit_none)  op_negation = operator(id,"neg", 1,"-", place_left, limit_none, False)
50  op_norm = operator(id+1,"norm", 1, (u'|',u'|'), place_split, limit_none)  op_norm = operator(id+1,"norm", 1, (u'|',u'|'), place_split, limit_none, False)
51  op_normalize = operator(id+2,"normalize", 1, u'normalize', place_left, limit_none)  op_normalize = operator(id+2,"normalize", 1, u'normalize', place_left, limit_none, False)
52  op_trace = operator(id+3,"trace", 1, u'trace', place_left, limit_none)  op_trace = operator(id+3,"trace", 1, u'trace', place_left, limit_none, False)
53  op_transpose = operator(id+4,"transpose", 1, u'transpose', place_left, limit_none)  op_transpose = operator(id+4,"transpose", 1, u'transpose', place_left, limit_none, False)
54  op_det = operator(id+5,"det", 1, u'det', place_left, limit_none)  op_det = operator(id+5,"det", 1, u'det', place_left, limit_none, False)
55  op_copy= operator(id+6,"probe", 1,"", place_left, limit_none)  op_copy= operator(id+6,"probe", 1,"", place_left, limit_none, False)
56    
57  op_reg = [op_negation, op_norm, op_normalize, op_trace, op_transpose, op_det,op_copy]  op_reg = [op_negation, op_norm, op_normalize, op_trace, op_transpose, op_det,op_copy]
58    
59  id=id+7  id=id+7
60  #differentiation  #differentiation
61  op_gradient = operator(id, "grad", 1, u'∇', place_left, limit_none)  op_gradient = operator(id, "grad", 1, u'∇', place_left, limit_none, True)
62  op_divergence = operator(id+1, "div", 1, u'∇•', place_left, limit_none)  op_divergence = operator(id+1, "div", 1, u'∇•', place_left, limit_none, True)
63  op_curl= operator(id+2, "curl", 1, u'∇×',place_left, limit_none)  op_curl= operator(id+2, "curl", 1, u'∇×',place_left, limit_none, True)
64  op_jacob= operator(id+3, "jacob", 1, u'∇⊗', place_left, limit_none)  op_jacob= operator(id+3, "jacob", 1, u'∇⊗', place_left, limit_none, True)
65  op_diff =[op_gradient, op_divergence, op_curl, op_jacob]  op_diff =[op_gradient, op_divergence, op_curl, op_jacob]
66    
67  id=id+4  id=id+4
68  #slicing  #slicing
69  op_slicem0 = operator(id,"slicem0", 1, u'[1,:]', place_right, limit_none)  op_slicem0 = operator(id,"slicem0", 1, u'[1,:]', place_right, limit_none, False)
70  op_slicem1 = operator(id+1,"slicem1", 1, u'[:,0]', place_right, limit_none)  op_slicem1 = operator(id+1,"slicem1", 1, u'[:,0]', place_right, limit_none, False)
71  op_slicev0 = operator(id+2,"slicev0", 1, u'[0]', place_right, limit_none)  op_slicev0 = operator(id+2,"slicev0", 1, u'[0]', place_right, limit_none, False)
72  op_slicev1 = operator(id+3,"slicev1", 1, u'[1]', place_right, limit_none)  op_slicev1 = operator(id+3,"slicev1", 1, u'[1]', place_right, limit_none, False)
73  op_slicet0 = operator(id+4,"slicet0", 1, u'[:,1,:]', place_right, limit_none)  op_slicet0 = operator(id+4,"slicet0", 1, u'[:,1,:]', place_right, limit_none, False)
74  op_slicet1 = operator(id+5,"slicet1", 1, u'[1,0,:]', place_right, limit_none)  op_slicet1 = operator(id+5,"slicet1", 1, u'[1,0,:]', place_right, limit_none, False)
75  op_slice = [op_slicem0, op_slicem1, op_slicev0, op_slicev1, op_slicet0, op_slicet1]  op_slice = [op_slicem0, op_slicem1, op_slicev0, op_slicev1, op_slicet0, op_slicet1]
76  op_unary= op_reg+ op_diff+op_slice  op_unary= op_reg+ op_diff+op_slice
77    
78  #binary operators  #binary operators
79  id=id+6  id=id+6
80  #print"addition id",id  #print"addition id",id
81  op_add = operator(id,"addition", 2,"+", place_middle, limit_none)  op_add = operator(id,"addition", 2,"+", place_middle, limit_none, False)
82  op_subtract = operator(id+1,"subtraction", 2, "-", place_middle, limit_none)  op_subtract = operator(id+1,"subtraction", 2, "-", place_middle, limit_none, False)
83  op_cross = operator(id+2,"cross product", 2, u'×', place_middle, limit_none)  op_cross = operator(id+2,"cross product", 2, u'×', place_middle, limit_none, False)
84  op_outer = operator(id+3,"outer product", 2, u'⊗', place_middle, limit_none)  op_outer = operator(id+3,"outer product", 2, u'⊗', place_middle, limit_none, False)
85  op_inner = operator(id+4,"inner product", 2, u'•', place_middle, limit_none)  op_inner = operator(id+4,"inner product", 2, u'•', place_middle, limit_none, False)
86  op_scale = operator(id+5,"multiplication", 2, u'*', place_middle, limit_none)  op_scale = operator(id+5,"multiplication", 2, u'*', place_middle, limit_none, False)
87  op_division = operator(id+6,"division", 2, u'/', place_middle, limit_small)  op_division = operator(id+6,"division", 2, u'/', place_middle, limit_small, False)
88  op_modulate = operator(id+7,"modulate", 2, "modulate",  place_left, limit_none)  op_modulate = operator(id+7,"modulate", 2, "modulate",  place_left, limit_none, False)
89  op_doubledot= operator(id+8,"op_doubledot", 2, u':', place_middle, limit_none)  op_doubledot= operator(id+8,"op_doubledot", 2, u':', place_middle, limit_none, False)
90  op_binary = [op_add, op_subtract, op_cross, op_outer, op_inner, op_scale, op_division, op_modulate, op_doubledot]  op_binary = [op_add, op_subtract, op_cross, op_outer, op_inner, op_scale, op_division, op_modulate, op_doubledot]
91    
92    
93  id=id+9  id=id+9
94  op_inverse = operator(id, "inverse", 1, u'inv', place_left, limit_det)  op_inverse = operator(id, "inverse", 1, u'inv', place_left, limit_det, False)
95    
96  #Trig  #Trig
97  id=id+1  id=id+1
98  #any range  #any range
99    
100  op_cosine = operator(id, "cosine", 1, u'cos', place_left, limit_none)  op_cosine = operator(id, "cosine", 1, u'cos', place_left, limit_none, False)
101  op_sine = operator(id+1, "sine", 1, u'sin', place_left, limit_none)  op_sine = operator(id+1, "sine", 1, u'sin', place_left, limit_none, False)
102  op_atangent = operator(id+2, "arctangent", 1, u'atan', place_left, limit_none)  op_atangent = operator(id+2, "arctangent", 1, u'atan', place_left, limit_none, False)
103  op_tangent = operator(id+3, "tangent", 1, u'tan', place_left, limit_none)  op_tangent = operator(id+3, "tangent", 1, u'tan', place_left, limit_none, False)
   
104  # limit- x must be between -1 and 1 for acos|asine and positive for sqrt.  # limit- x must be between -1 and 1 for acos|asine and positive for sqrt.
105  # to avoid getting a bunch of (inf, or NAN)  # to avoid getting a bunch of (inf, or NAN)
106  # operator arguments are augmented here and in test_eval  # operator arguments are augmented here and in test_eval
107  op_acosine = operator(id+4, "arccosine", 1,  (u'acos(0.01*', u')'), place_split, limit_trig)  op_acosine = operator(id+4, "arccosine", 1,  (u'acos(0.01*', u')'), place_split, limit_trig, False)
108  op_asine = operator(id+5, "arcsine", 1,  (u'asin(0.01*', u')'), place_split, limit_trig)  op_asine = operator(id+5, "arcsine", 1,  (u'asin(0.01*', u')'), place_split, limit_trig, False)
109    
110    
111  #note sqrt is 'sqrt' in each branch  #note sqrt is 'sqrt' in each branch
112  op_sqrt = operator(id+6, "sqrt", 1, (u'sqrt(|', u'|)'), place_split, limit_nonzero)  op_sqrt = operator(id+6, "sqrt", 1, (u'sqrt(|', u'|)'), place_split, limit_nonzero, False)
113    
114  op_trig=[ op_cosine, op_sine, op_atangent, op_tangent, op_acosine, op_asine, op_sqrt]  op_trig=[ op_cosine, op_sine, op_atangent, op_tangent, op_acosine, op_asine, op_sqrt]
115    
# Line 122  Line 122 
122      f.close()      f.close()
123    
124    
125    # print all the ops
126    def pnt_ops():
127  i=0  i=0
128  for op1 in op_all:  for op1 in op_all:
129      x= "\n-"+op1.name+"("+str(op1.id)+") "      x= "\n-"+op1.name+"("+str(op1.id)+") "

Legend:
Removed from v.4482  
changed lines
  Added in v.4483

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