Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /branches/ein16/synth/d2/test_eval.py
 [diderot] / branches / ein16 / synth / d2 / test_eval.py

# View of /branches/ein16/synth/d2/test_eval.py

Mon May 16 16:32:19 2016 UTC (3 years, 5 months ago) by cchiw
File size: 2309 byte(s)
`moved steps to run program`
```import sys
import re
from test_examples import value_probe
from test_examples import value_negation
from test_examples import value_scalarFd2
from test_examples import value_vec2Fd2
from test_examples import value_scalarT
from test_examples import value_vec2T

#fixed variables
op_probe = value_probe()
op_negation = value_negation()
ty_scalarF_d2 = value_scalarFd2()
ty_vec2F_d2 = value_vec2Fd2()
ty_scalarT = value_scalarT()
ty_vec2T = value_vec2T()

def printFunc(a,b,c,d,e,f,g,h,i):
if(b!=0):
print b, "*x"
if(c!=0):
print " +", c,"y"
if(d!=0):
print " +", d, "x^2"
if(g!=0):
print " + ", g, "y*x^2"
if(f!=0):
print " + ", f, "y^2"
if(h!=0):
print " + ", h, "x*y^2"
if(a!=0):
print " + ", a
if(e!=0):
print " + ", e, "x*y"
if(i!=0):
print " + ", i, "x^2*y^2"

#evaluate field defined by coefficients at position
def eval(x,y,a,b,c,d,e,f,g,h,i):
#evaluate field defined by coefficients at position
t0 = b*x + c*y
t1 = d*x*x + g*y*x*x
t2 = f*y*y + h*x*y*y
t3 = a + e*x*y + i*(y*y)*(x*x)
t4= t0+t1+t2+t3
return t4

def negation(x,y,a,b,c,d,e,f,g,h,i):
return (-1*eval(x,y,a,b,c,d,e,f,g,h,i))

#gradient of field defined by coefficients at position
x0 = b
x1 = d*2*x + g*y*2*x
x2 = h*y*y
x3 = e*y + i*(y*y)*(2*x)
x4= x0+x1+x2+x3 #xaxis
y0 = c
y1 = g*x*x
y2 = f*2*y + h*x*2*y
y3 = e*x + i*(y*2)*(x*x)
y4= y0+y1+y2+y3 #yaxis
return [x4,y4]

def iter(k, pos, base, xsq, ysq, diag):
corr = []
b = base[0]
c = base[1]
d = xsq[0]
g = xsq[1]
f = ysq[0]
h = ysq[1]
a = diag[0]
e = diag[1]
i = diag[2]
for p in pos:
x=p[0]
y=p[1]
val = k(x,y,a,b,c,d,e,f,g,h,i)
corr.append(val)
return corr

def unary(ex, pos,base,xsq,ysq,diag):
if(ex==op_probe): #probing
return iter(eval,pos,base,xsq,ysq,diag)
elif(ex==op_negation): #negation
return iter(negation,pos,base,xsq,ysq,diag)