def test_complex_pipeline1(): a = NDArray([1, 2, 3]) b = NDArray([1, 2, 3]) c = NDArray([1, 2, 3]) d = NDArray([1, 2, 3]) line = Pipeline() _, plan = line.run_pipeline(((a * b) + (c * d))**2) # Pow( # Arithmetic( # Add # , Arithmetic( # Mul # , Array(){dshape("3,int64"), 40127160} # , Array(){dshape("3,int64"), 40015272} # ){dshape("int64"), 40076400} # , Arithmetic( # Mul # , Array{dshape("3,int64"), 40069816} # , Array{dshape("3,int64"), 40080448} # ){dshape("int64"), 40076016} # ){dshape("int64"), 40077552} # , 2{dshape("int"), 40090448} # ){dshape("int64"), 40077744} if DEBUG: pprint(plan, width=1)
def test_complex_pipeline1(): a = NDArray([1,2,3]) b = NDArray([1,2,3]) c = NDArray([1,2,3]) d = NDArray([1,2,3]) line = Pipeline() plan = line.run_pipeline(((a*b)+(c*d))**2) # Pow( # Arithmetic( # Add # , Arithmetic( # Mul # , Array(){dshape("3,int64"), 40127160} # , Array(){dshape("3,int64"), 40015272} # ){dshape("int64"), 40076400} # , Arithmetic( # Mul # , Array{dshape("3,int64"), 40069816} # , Array{dshape("3,int64"), 40080448} # ){dshape("int64"), 40076016} # ){dshape("int64"), 40077552} # , 2{dshape("int"), 40090448} # ){dshape("int64"), 40077744} if DEBUG: pprint(plan, width=1)
def test_complex_pipeline2(): a = NDArray([1,2,3]) b = NDArray([1,2,3]) c = NDArray([1,2,3]) d = NDArray([1,2,3]) f = ((a*b)+(c*d)) g = f**(a+b) line = Pipeline() plan = line.run_pipeline(f+g) # Arithmetic( # Add() # , Arithmetic( # Add() # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61582152} # , Array(){dshape("3, int64"), 61469976} # ){dshape("int64"), 61526768} # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61524520} # , Array(){dshape("3, int64"), 61531056} # ){dshape("int64"), 61526864} # ){dshape("int64"), 61527152} # , Pow( # Arithmetic( # Add() # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61582152} # , Array(){dshape("3, int64"), 61469976} # ){dshape("int64"), 61526768} # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61524520} # , Array(){dshape("3, int64"), 61531056} # ){dshape("int64"), 61526864} # ){dshape("int64"), 61527152} # , Arithmetic( # Add() # , Array(){dshape("3, int64"), 61582152} # , Array(){dshape("3, int64"), 61469976} # ){dshape("int64"), 61528304} # ){dshape("int64"), 61528496} # ){dshape("int64"), 61528592} if DEBUG: pprint(plan, width=1)
def test_complex_pipeline2(): a = NDArray([1, 2, 3]) b = NDArray([1, 2, 3]) c = NDArray([1, 2, 3]) d = NDArray([1, 2, 3]) f = ((a * b) + (c * d)) g = f**(a + b) line = Pipeline() _, plan = line.run_pipeline(f + g) # Arithmetic( # Add() # , Arithmetic( # Add() # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61582152} # , Array(){dshape("3, int64"), 61469976} # ){dshape("int64"), 61526768} # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61524520} # , Array(){dshape("3, int64"), 61531056} # ){dshape("int64"), 61526864} # ){dshape("int64"), 61527152} # , Pow( # Arithmetic( # Add() # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61582152} # , Array(){dshape("3, int64"), 61469976} # ){dshape("int64"), 61526768} # , Arithmetic( # Mul() # , Array(){dshape("3, int64"), 61524520} # , Array(){dshape("3, int64"), 61531056} # ){dshape("int64"), 61526864} # ){dshape("int64"), 61527152} # , Arithmetic( # Add() # , Array(){dshape("3, int64"), 61582152} # , Array(){dshape("3, int64"), 61469976} # ){dshape("int64"), 61528304} # ){dshape("int64"), 61528496} # ){dshape("int64"), 61528592} if DEBUG: pprint(plan, width=1)
def test_simple_unify(): A = NDArray([0], dshape('s, t, int')) B = NDArray([0], dshape('u, v, int')) C = NDArray([0], dshape('w, x, int')) D = NDArray([0], dshape('y, z, int')) # ============== g = (A*B+C*D)**2 # ============== # Operator Constraints # # A : (s, t) # B : (u, v) # C : (w, x) # D : (y, z) # # AB : (a, b) # CD : (c, d) # AB + CD : (e, f) # (AB + CD)**2 : (g, h) # Constraint Generation # --------------------- # t = u, a = s, b = v in AB # x = y, c = w, d = z in CD # a = c = e, b = d = f in AB + CD # e = f = g = h in (AB + CD)**2 # Substitution # ------------- # a = b = c = d = e = f = g = h = s = v = w = z # t = u # x = y # Constraint Solution # ------------------- # A : a -> t # B : t -> a # C : a -> x # D : x -> a line = Pipeline() result = line.run_pipeline(g)
def test_simple_unify(): A = NDArray([0], dshape('s, t, int')) B = NDArray([0], dshape('u, v, int')) C = NDArray([0], dshape('w, x, int')) D = NDArray([0], dshape('y, z, int')) # ============== g = (A * B + C * D)**2 # ============== # Operator Constraints # # A : (s, t) # B : (u, v) # C : (w, x) # D : (y, z) # # AB : (a, b) # CD : (c, d) # AB + CD : (e, f) # (AB + CD)**2 : (g, h) # Constraint Generation # --------------------- # t = u, a = s, b = v in AB # x = y, c = w, d = z in CD # a = c = e, b = d = f in AB + CD # e = f = g = h in (AB + CD)**2 # Substitution # ------------- # a = b = c = d = e = f = g = h = s = v = w = z # t = u # x = y # Constraint Solution # ------------------- # A : a -> t # B : t -> a # C : a -> x # D : x -> a line = Pipeline() result = line.run_pipeline(g)
def test_simple_pipeline(): line = Pipeline() plan = line.run_pipeline(x) # Add(1,Mul(2,Abs(3.0))) if DEBUG: pprint(plan, width=1) plan = line.run_pipeline(y) # Add(Add(1,Add(2,3.0)),Add(1,Mul(2,Abs(3.0)))) if DEBUG: pprint(plan, width=1) plan = line.run_pipeline(x+y) # Add(Mul(Add(1,Add(2,3.0)),Add(Add(1,Mul(2,Abs(3.0))),2)),3) if DEBUG: pprint(plan, width=1) plan = line.run_pipeline(x*(y+2)+3) # Add(Array(39558864){dshape("3 int64")},Array(39558864){dshape("3 int64")}) if DEBUG: pprint(plan, width=1) plan = line.run_pipeline(d+d) # Add( # Add(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # , Add(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # ) if DEBUG: pprint(plan, width=1) plan = line.run_pipeline((d+d)+(d+d)) if DEBUG: pprint(plan, width=1) # Mul( # Mul(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # , Mul(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # ) plan = line.run_pipeline((d*d)*(d*d)) if DEBUG: pprint(plan, width=1)
def test_simple_pipeline(): line = Pipeline() _, plan = line.run_pipeline(x) # Add(1,Mul(2,Abs(3.0))) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(y) # Add(Add(1,Add(2,3.0)),Add(1,Mul(2,Abs(3.0)))) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(x+y) # ATerm # ----- # Add(Mul(Add(1,Add(2,3.0)),Add(Add(1,Mul(2,Abs(3.0))),2)),3) # Instructions # ------------ # %0 = <ufunc 'add'> const(2) const(3.0) # %1 = <ufunc 'add'> const(1) '%0' # %2 = <ufunc 'absolute'> const(3.0) # %3 = <ufunc 'multiply'> const(2) '%2' # %4 = <ufunc 'add'> const(1) '%3' # %5 = <ufunc 'add'> '%4' const(2) # %6 = <ufunc 'multiply'> '%1' '%5' # %7 = <ufunc 'add'> '%6' const(3) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(x*(y+2)+3) #------------------------------------------------------------------------ # Add(Array(39558864){dshape("3 int64")},Array(39558864){dshape("3 int64")}) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(d+d) # Add( # Add(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # , Add(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # ) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline((d+d)+(d+d)) if DEBUG: pprint(plan, width=1) # Mul( # Mul(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # , Mul(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # ) ctx, plan = line.run_pipeline((d*d)*(d*d)) if DEBUG: pprint(plan, width=1)
def test_simple_pipeline(): line = Pipeline() _, plan = line.run_pipeline(x) # Add(1,Mul(2,Abs(3.0))) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(y) # Add(Add(1,Add(2,3.0)),Add(1,Mul(2,Abs(3.0)))) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(x + y) # ATerm # ----- # Add(Mul(Add(1,Add(2,3.0)),Add(Add(1,Mul(2,Abs(3.0))),2)),3) # Instructions # ------------ # %0 = <ufunc 'add'> const(2) const(3.0) # %1 = <ufunc 'add'> const(1) '%0' # %2 = <ufunc 'absolute'> const(3.0) # %3 = <ufunc 'multiply'> const(2) '%2' # %4 = <ufunc 'add'> const(1) '%3' # %5 = <ufunc 'add'> '%4' const(2) # %6 = <ufunc 'multiply'> '%1' '%5' # %7 = <ufunc 'add'> '%6' const(3) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(x * (y + 2) + 3) #------------------------------------------------------------------------ # Add(Array(39558864){dshape("3 int64")},Array(39558864){dshape("3 int64")}) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline(d + d) # Add( # Add(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # , Add(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # ) if DEBUG: pprint(plan, width=1) ctx, plan = line.run_pipeline((d + d) + (d + d)) if DEBUG: pprint(plan, width=1) # Mul( # Mul(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # , Mul(Array(39558864){dshape("3 int64")}, Array(39558864){dshape("3 int64")}) # ) ctx, plan = line.run_pipeline((d * d) * (d * d)) if DEBUG: pprint(plan, width=1)