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

SCM Repository

[diderot] Annotation of /branches/ein16/synth/d2/iter.py
ViewVC logotype

Annotation of /branches/ein16/synth/d2/iter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4459 - (view) (download) (as text)

1 : cchiw 4457 import sys
2 :     import re
3 :     import os
4 :    
5 :     from obj_apply import *
6 :     from obj_ex import *
7 :     from obj_field import *
8 :     from obj_counter import *
9 :     from obj_frame import *
10 :    
11 :     from test_createField import createField
12 :     from test_writeDiderot import writeDiderot
13 :     from test_eval import eval
14 :     from test_compare import compare
15 :     from test_observed import observed
16 :    
17 :     from core import *
18 :     from write import *
19 :     from var_ty import *
20 :     from frame import *
21 :    
22 :    
23 :     ##################################################################################################
24 :     # already created app object
25 :     def central(app, coeffs, dimF, names, testing_frame, cnt):
26 :     #print "############################################inside central############################################"
27 :     writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+ names)
28 :     core(app, coeffs, dimF, names, testing_frame, cnt)
29 :     return
30 :    
31 :     ##################################################################################################
32 :     # functions create app objects
33 :     # get example from list of examples
34 :     def create_single_app(opr_inner, t_num, testing_frame, cnt):
35 :     # global variables needed from testing framework
36 :     g_inputfile = frame.get_inputfile(testing_frame)
37 :     g_ucoeff = frame.g_ucoeff(testing_frame)
38 :     g_coeff_style = frame.get_coeff_style(testing_frame) # global variable from set
39 :     g_rst_ty = frame.get_rst_ty(testing_frame)
40 : cchiw 4458 g_krn = frame.get_krn(testing_frame)
41 : cchiw 4457 print "single specific ex"
42 :     (name,opr,ishape)= get_single_example(opr_inner, t_num, g_rst_ty)
43 : cchiw 4459 # get k value of tshape from kernels
44 :     set_ks(g_krn, ishape)
45 :     print "calling tshape"
46 : cchiw 4457 (tf1, tshape1) = get_tshape(opr_inner,ishape)
47 :     if(not tf1):
48 :     write_terrible("\n apply blocked from attempting: "+"b__"+name+str(opr_inner.id)+"_"+str(t_num))
49 :     return None
50 :     print "after calling tshape"
51 :     #create app object
52 :    
53 : cchiw 4458 (app, coeffs, _) = mkApply_fld(name, opr, ishape, g_inputfile, tshape1, g_coeff_style, g_ucoeff, g_krn)
54 : cchiw 4459
55 :    
56 : cchiw 4457 dimF = tshape1.dim
57 :     print "creating app"
58 :     print "app oty", app.oty
59 :     # main
60 :     names= "s_"+str(opr_inner.id)+"__"+"n_"+str(t_num)+"_"
61 :     return (app, coeffs, dimF, names)
62 :    
63 :     # checks to see if specific ex works
64 :     def create_embed_app(ex, opr_inner, opr_outer, t_num, fty, title, testing_frame, cnt):
65 :     # global variables needed from testing framework
66 :     g_inputfile = frame.get_inputfile(testing_frame)
67 :     g_ucoeff = frame.g_ucoeff(testing_frame)
68 :     g_coeff_style = frame.get_coeff_style(testing_frame) # global variable from set
69 : cchiw 4458 g_krn = frame.get_krn(testing_frame)
70 : cchiw 4457 print "current embed inner: "+opr_inner.name+"("+str(opr_inner.id)+") outer: " +opr_outer.name+"("+str(opr_outer.id)+")#"+str(t_num)
71 :     # current example
72 : cchiw 4459 (name, ishape0)= get_single_exampleEx(ex, t_num)
73 :     # get value of k from kernels
74 :     ishape = ishape0+fty
75 :     set_ks(g_krn, ishape)
76 : cchiw 4457 # first layer
77 :     # get result after applying operators
78 :     (tf1, tshape1) = get_tshape(opr_inner,ishape)
79 :     print "tf1",tf1, tshape1
80 :     if(tf1==false):
81 :     print "found false at tf1"
82 :     return None
83 :     else:
84 :     print "tshape1", tshape1.name
85 :     #second layer, adds second field type
86 : cchiw 4459 #ishape = ishape+fty
87 : cchiw 4457 (tf2, tshape2) = get_tshape(opr_outer,[tshape1]+fty)
88 :     print "tf2", tf2, tshape2
89 :     if(tf2==true):# if it works continue
90 :     #create app object
91 :     print "opr_outer", opr_outer.name
92 :     print "tshape2", tshape2.name
93 :     appname = opr_outer.name+"("+opr_inner.name+")"
94 : cchiw 4458 (app, coeffs) = mkApply_twice(appname, opr_inner,opr_outer, ishape, g_inputfile, tshape1, tshape2, g_coeff_style, g_ucoeff, g_krn)
95 : cchiw 4457 dimF = tshape2.dim
96 :     # main part
97 :     print title
98 :     print "appoty",app.oty.name
99 : cchiw 4459 writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+ title)
100 :     writetys("\t ("+ishape[0].name)
101 :     if(len(ishape0)>1):
102 :     writetys(","+ishape[1].name)
103 :     writetys(") -> ("+ tshape1.name)
104 :     if(len(fty)==1):
105 :     writetys(","+fty[0].name)
106 :     writetys(") -> "+ tshape2.name)
107 : cchiw 4457 return (app, coeffs, dimF, title)
108 :     else:
109 :     # "\n\t\tskipped did not apply "+opr_outer.name+" to ("+str(tshape2)+","
110 :     print "tf2 found false at this point"
111 :     return None
112 :     ##################################################################################################
113 :     # get example from list of examples
114 :     def single_specific_ex(opr_inner, t_num, testing_frame, cnt):
115 :     # increment total
116 :     counter.inc_total(cnt)
117 :     # main
118 :     rtn = create_single_app(opr_inner, t_num)
119 :     if (rtn==None):
120 :     return
121 :     else:
122 :     (app, coeffs, dimF, names) = rtn
123 :     print "names",names
124 :     return central(app, coeffs, dimF, names, testing_frame, cnt)
125 :    
126 :     def get_extra(ex_ty2, testing_frame, cnt):
127 :     g_rst_ty = frame.get_rst_ty(testing_frame)
128 : cchiw 4459 g_in_tys = frame.get_in_tys(testing_frame)
129 :     l = get_all_types(g_rst_ty,g_in_tys)
130 : cchiw 4457 return (len(l), l[ex_ty2])
131 :    
132 :     def embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, t_ty2, testing_frame, cnt):
133 :     # increment total
134 :     counter.inc_total(cnt)
135 :     # get specific outer operator
136 :     print "inside embed base specific "
137 :     print "inner", opr_inner.id, "outer", opr_outer.id, "t-num", t_num
138 :     def get_fty(ex_ty2):
139 :     if(needextratype(opr_inner, opr_outer)):
140 :     (_, x) = get_extra(ex_ty2, testing_frame, cnt)
141 :     print "gets extra type @", ex_ty2, x.name
142 :     return ([x], "_fty"+ str(t_ty2))
143 :     else:
144 :     return ([], "")
145 :     (fty, s) = get_fty(t_ty2)
146 :     names="p"+"_i"+str(opr_inner.id)+"_o"+str(opr_outer.id)+"_n"+str(t_num)+s
147 :     print "names",names
148 :     rtn = create_embed_app(ex, opr_inner, opr_outer, t_num, fty, names, testing_frame, cnt)
149 :     if(rtn==None):
150 :     print "found none after create embed app"
151 :     return
152 :     else:
153 :     print "found something after create embed app"
154 :     (app, coeffs, dimF, names) = rtn
155 :    
156 :     return central (app, coeffs, dimF, names, testing_frame, cnt)
157 :    
158 :     ################################################## iterating ###############################################
159 :     def iter_num(ex, opr_inner, opr_outer, n_num, t_ty2, testing_frame, cnt):
160 :     print "inside iter num"
161 :     for t_num in range(n_num):
162 :     embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, t_ty2, testing_frame, cnt)
163 :    
164 :     # operator, and testing framework -> built in example given
165 :     def oprToEx(opr_inner, testing_frame, cnt):
166 :     #get global variables
167 :     g_in_tys = frame.get_in_tys(testing_frame)
168 :     g_rst_ty = frame.get_rst_ty(testing_frame)
169 :     #using s variables get global variables
170 :     tys = transform_tys(g_in_tys) # use global var to get list of types
171 :     #(l_all_T, l_all_F, l_all) = tys
172 :     ex = oprToEx_a(opr_inner, g_rst_ty, tys)
173 :     return ex
174 :    
175 :     #iterates over extra type and ex_num type
176 :     def embed_base_iter_ty2(ex, opr_inner, opr_outer, testing_frame, cnt):
177 :     print "inside embed base iter -ty 2 "
178 :     ex_outer = oprToEx(opr_inner, testing_frame, cnt)
179 :     n_num = len(ex_outer.tys)
180 :     print(" "+str(opr_inner.name)+"-"+str(opr_outer.name)+" tys length:" +str(n_num))
181 :     if(needextratype(opr_inner, opr_outer)):
182 :     (n_ty2, _) = get_extra(0, testing_frame, cnt) # use all field types as extra types
183 :     for t_ty2 in range(n_ty2): #extra type
184 :     print "as extra type using ", t_ty2
185 :     iter_num(ex, opr_inner, opr_outer, n_num, t_ty2, testing_frame, cnt)
186 :     else:
187 :     iter_num(ex, opr_inner, opr_outer, n_num, None, testing_frame, cnt)
188 :     return
189 :    
190 :     #iterating ex_outer from 0...l
191 :     # iterate over outer operator and extra type
192 :     def embed_base_iter_outer2(ex, opr_inner, t_num, testing_frame, cnt):
193 :     # set local counters to zero
194 :     counter.zero_locals(cnt)
195 :     # print "\nembed_base_iter_outer: ex_opr",ex_opr
196 :     n_outer = getN()
197 :    
198 :     #have ex_opr iterating over ex_outer
199 :     for t_outer in range(n_outer):
200 :     opr_outer = id_toOpr(t_outer)
201 :     writeTitle_outer(opr_inner, opr_outer)
202 :     if(needextratype(opr_inner, opr_outer)):
203 :     # use all field types as extra types
204 :     (n_ty2, _) = get_extra(0, testing_frame, cnt)
205 :     for t_ty2 in range(n_ty2): #extra type
206 :     embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, t_ty2, testing_frame, cnt)
207 :     else:
208 :     embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, None, testing_frame, cnt)
209 :     writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
210 :     return
211 :     def embed_base_iter_ty2_wihty1(ex, opr_inner, opr_outer, t_num, testing_frame, cnt):
212 :     # get built-in example
213 :     ex_outer = oprToEx(opr_inner, testing_frame, cnt)
214 :     if(needextratype(opr_inner, opr_outer)):
215 :     # use all field types as extra types
216 :     (n_ty2, _) = get_extra(0, testing_frame, cnt)
217 :     for t_ty2 in range(n_ty2): #extra type
218 :     print "as extra type using ", t_ty2
219 :     embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, t_ty2, testing_frame, cnt)
220 :     else:
221 :     embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, None, testing_frame, cnt)
222 :    
223 :     return
224 :    
225 :     #iterating ex_outer from 0...length(potential outer_operators)
226 :     def embed_base_iter_outer(ex, opr_inner, testing_frame, cnt):
227 :     writeTitle_inner(opr_inner)
228 :     #have ex_opr iterating over ex_outer
229 :     n_outer = getN()
230 :     for t_outer in range(n_outer):
231 :     #zero counters
232 :     counter.zero_locals(cnt)
233 :     counter.zero_total(cnt)
234 :     opr_outer = id_toOpr(t_outer)
235 :     writeTitle_outer(opr_inner, opr_outer)
236 :     embed_base_iter_ty2(ex, opr_inner, opr_outer, testing_frame, cnt)
237 :     writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
238 :     return
239 :    
240 :     #run all possible examples from 0...n
241 :     def embed2_iter_inner(testing_frame, cnt):
242 :     n_opr = getN()
243 :     for t_opr in range(n_opr):
244 :     opr_inner = (id_toOpr(t_opr))
245 :     ex = oprToEx(opr_inner, testing_frame, cnt)
246 :     embed_base_iter_outer(ex, opr_inner, testing_frame, cnt)
247 :     return
248 :    
249 :     #specify outer operator
250 :     def embed2_iter_inner_gotouter(opr_outer, testing_frame, cnt):
251 :     counter.zero_total(cnt) #zero counters
252 :     n_opr = getN()
253 :    
254 :     #iterate over inner operator
255 :     for t_opr in range(n_opr):
256 :     #zero counters
257 :     counter.zero_locals(cnt)
258 :     counter.zero_total(cnt)
259 :     opr_inner = id_toOpr(t_opr)
260 :     writeTitle_outer(opr_inner, opr_outer)
261 :     ex = oprToEx(opr_inner, testing_frame, cnt)
262 :     embed_base_iter_ty2(ex, opr_inner, opr_outer, testing_frame, cnt)
263 :     writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
264 :     return
265 :    
266 :     #run all examples for a specific operator
267 :     def single_all_ops(opr_inner, testing_frame, cnt):
268 :     # get built-in example
269 :     ex = oprToEx(opr_inner, testing_frame, cnt)
270 :     n_num = len(ex.tys)
271 :     if (n_num==0):
272 :     return
273 :     writeTitle_inner(opr_inner)
274 :     #zero counters
275 :     counter.zero_locals(cnt)
276 :     for t_num in range(n_num):
277 :     single_specific_ex(opr_inner, t_num, testing_frame, cnt)
278 :     return

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