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

SCM Repository

[diderot] View of /branches/ein16/synth/d2/main.py
ViewVC logotype

View of /branches/ein16/synth/d2/main.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4483 - (download) (as text) (annotate)
Fri Sep 2 05:07:01 2016 UTC (2 years, 8 months ago) by cchiw
File size: 8562 byte(s)
shape based iteration
import sys
import re
import os
import time

from obj_apply import *
from obj_ex import  *
from obj_field import *
from obj_counter import *
from obj_frame import  *
from obj_counter import *

from iter import *
from fold import *
# unu save -f nrrd -e ascii -i out.nrrd | less
##################################################################################################
# possible commands
# unu grid -i inputfile.nrrd | unu save -f text
# ^ where all the points are.

##############################################################################################
def cmd(layer, testing_frame, cnt, shift, args):
    if (layer==0):
        #does nothing
        print "******************************************"
        print "List of commands"
        print "*** single layered program"
        print "Ex. (A+B). operation (+) has id \"i\" and types to arguments ([A,B]) are specificed with \"t\""
        print "cmd: 1 2 i t \t single program with specific operator(i) and argument(s) (t)"
        print "cmd: 1 1 i \t specifies operator(i) and iterates over applicable argument types"
        print "cmd: 1 0 \t iterates over all possibilities"
        print "***  double layered programs -(A+B)"
        print "Ex. -(A+B).  outer operator(-) is specified with \"o\""
        print "cmd: 2 3 i o m \t  specifies inner operator(i), outer operator(o) and args (t)"
        print "cmd: 2 2 i o   \t  specifies inner operator(i), outer operator(o) and iterates over args"
        print "cmd: 2 20 i m  \t  specifies inner operator(i), args(t) and iterates over outer operations (o)"
        print "cmd: 2 1 i     \t  specifies inner operator(i) and iterates over outer operator, and args"
        print "cmd: 2 0       \t  iterate over all possibilities"

        print "ex. cmd: 2 2 1 3  => normalize (-F)"
        print "ex. cmd: 2 2 24 3 => normalize(F0+F1)"
        print "ex. cmd: 2 2 _ n => n must be less than <24"
        print "ex. cmd: 3 2 1 24  => (-F)+F1"
        print "ex. cmd: 3 2 25 24 => (F-F)+F"
        print "******************************************"
    elif(layer==0): #run all the programs
        embed2_iter_inner(testing_frame, cnt)
        writeCumulative(cnt)

    elif (layer==1):
        if(args==0):
            # iterate over single layer
            rtn = []
            for t_inner in range(getN()):
                opr_inner = id_toOpr(t_inner)
                writeTitle_inner(opr_inner)
                single_all_ops(opr_inner, testing_frame, cnt)
                writeResults_inner(opr_inner, testing_frame, cnt)
            writeCumulative(cnt)
        elif (args==1):
            # iterate over single layer
            t_inner= int(sys.argv[shift+1])
            opr_inner = id_toOpr(t_inner)
            writeTitle_inner(opr_inner)
            single_all_ops(opr_inner, testing_frame, cnt)
            writeResults_inner(opr_inner, testing_frame, cnt)
        elif (args==2):
            t_inner= int(sys.argv[shift+1])
            opr_inner = id_toOpr(t_inner)
            t_num= int(sys.argv[shift+2])
            single_specific_ex(opr_inner,t_num, testing_frame, cnt)
            writeResults_inner(opr_inner, testing_frame, cnt)
    elif (layer==2):
        if(args==0):
            #run all the programs
            embed2_iter_inner(testing_frame, cnt)
            writeCumulative(cnt)
        elif(args==1):
            # iterate over double layer with unary operator
            t_inner = int(sys.argv[shift+1])
            opr_inner = id_toOpr(t_inner)
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_iter_outer(ex, opr_inner, testing_frame, cnt)
            writeCumulative(cnt)
        elif(args==5):
            t_outer = int(sys.argv[shift+1])
            opr_outer = id_toOpr(t_outer)
            writeTitle_outer2(opr_outer)
            embed2_iter_inner_gotouter(opr_outer, testing_frame, cnt)
            writeCumulative(cnt)
        elif (args==2):
            t_inner = int(sys.argv[shift+1])
            t_outer = int(sys.argv[shift+2])#outer  operator
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_iter_ty2(ex, opr_inner, opr_outer, testing_frame, cnt)
            writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
        elif (args==20):
            t_inner = int(sys.argv[shift+1])
            t_num = int(sys.argv[shift+2])#outer binary operator
            opr_inner = id_toOpr(t_inner)
            writeTitle_inner(opr_inner)
            embed_base_iter_outer2(opr_inner, t_num, testing_frame, cnt)
            writeResults_inner(opr_inner, testing_frame, cnt)
        elif(args==3):
            #  run a specific iterate over double layer with unary operator
            t_inner = int(sys.argv[shift+1])
            t_outer= int(sys.argv[shift+2])
            t_num = int(sys.argv[shift+3])
            t_ty2 = None
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_iter_ty2_wihty1(ex, opr_inner, opr_outer, t_num, testing_frame, cnt)
            writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
        elif(args==4):
            #  run a specific iterate over double layer with unary operator
            t_inner = int(sys.argv[shift+1])
            t_outer= int(sys.argv[shift+2])
            t_num = int(sys.argv[shift+3])
            t_ty2 = int(sys.argv[shift+4])
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            # get example
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, t_ty2, testing_frame, cnt)
            writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)

    else:
      raise "unsupported"

#ends with Clean up
def clean():
    os.system("rm *.o")
    os.system("rm *.pyc")
    os.system("rm *.h")
    os.system("rm *.nrrd")
    os.system("rm *.cxx")
    os.system("rm *.diderot")
    os.system("rm fs3d-vec2")
    os.system("rm fs3d-vec2")

# iterating over the different types
def main_Standard():
    n_frame = 0 # int(sys.argv[1])
    args = 2 #int(sys.argv[2])
    shift = 1 # how many commands used so far
    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    write_heading(testing_frame)
    # constants (decides layer of testing)
    layer = 2
    # layer, and shift from constants (decides layer of testing)

    #choose testing range based on commands
    cmd(layer, testing_frame, cnt, shift, args)
    clean()


def main():
    #n_frame = int(sys.argv[1])
    #args = int(sys.argv[2])
    #shift = 2 # how many commands used so far
    n_frame = 0
    shift = 1

    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    #write_heading(testing_frame)

    #choose testing range based on commands
    t_inner = int(sys.argv[shift+1])
    t_outer = int(sys.argv[shift+2])#outer  operator
    opr_outer = id_toOpr(t_outer)
    opr_inner = id_toOpr(t_inner)
    writeTitle_outer(opr_inner, opr_outer)
    
    #choose testing range based on commands
    pick(opr_inner, opr_outer, testing_frame, cnt)
    clean()

def main_iter():
    #n_frame = int(sys.argv[1])
    #args = int(sys.argv[2])
    #shift = 2 # how many commands used so far
    n_frame = 0
    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    #write_heading(testing_frame)
    
    #choose testing range based on commands
    n = len(op_all)
    for i in range(n):
        for j in range(n):
            t_inner = int(sys.argv[i])
            t_outer = int(sys.argv[j])
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            #choose testing range based on commands
            pick(opr_inner, opr_outer, testing_frame, cnt)
            clean()

start = time.time()
x = int(sys.argv[1])
if(x==0):
    main_Standard()
else:
    main()
    end = time.time()
t = "  time:"+str(end - start)
writeall(t)
print (t)

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