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

SCM Repository

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

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

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

revision 4494, Sat Sep 3 01:48:23 2016 UTC revision 4495, Sat Sep 3 06:29:28 2016 UTC
# Line 273  Line 273 
273  def pick_get_ty3s(ty1s, ty2s, rtn3s, tshape1_shape, opr_inner, opr_outer, title, testing_frame, cnt):  def pick_get_ty3s(ty1s, ty2s, rtn3s, tshape1_shape, opr_inner, opr_outer, title, testing_frame, cnt):
274      # can apply (shape1*shape2)* shape3 ->tshape2      # can apply (shape1*shape2)* shape3 ->tshape2
275      titlec ="\n\t"      titlec ="\n\t"
276        k_init = 2
277      for (shape3, tshape2_shape) in rtn3s:      for (shape3, tshape2_shape) in rtn3s:
278          #print "-------------"          #print "-------------"
279          tmp = ""          tmp = ""
# Line 280  Line 281 
281          #writenow("\n\t---Shape3:("+tmp)          #writenow("\n\t---Shape3:("+tmp)
282          #writenow("\n shape3: "+shape3.name+"  tshape2_shape: "+tshape2_shape.name)          #writenow("\n shape3: "+shape3.name+"  tshape2_shape: "+tshape2_shape.name)
283          # convert shape to type          # convert shape to type
284          ty3s = shape_to_fty(shape3)          ty3s = shape_to_fty(shape3, k_init)
285          #pes("ty3s", ty3s)          #pes("ty3s", ty3s)
286          #make sure non-tmpty third types          #make sure non-tmpty third types
287          if (len(ty3s)>3):          if (len(ty3s)>3):
# Line 332  Line 333 
333                  tty = "  time-outer:"+str(endyy - startyy)                  tty = "  time-outer:"+str(endyy - startyy)
334                  writeall(tty)                  writeall(tty)
335                  print (tty)                  print (tty)
336                    writeCumulative(cnt)
337          else:          else:
338              sort(opr_outer)              sort(opr_outer)
339      return      return
# Line 408  Line 410 
410              writeTitle_outer(opr_inner, opr_outer)              writeTitle_outer(opr_inner, opr_outer)
411              sort(opr_outer)              sort(opr_outer)
412              endouter = time.time()              endouter = time.time()
413              ttouter = "  time-outer:"+str(endouter - startouter)              ttouter ="shape-> inner->outer"+opr_inner.name+"_"+opr_outer.name+"  time: "+str(endouter - startouter)
414              writeall(ttouter)              writeall(ttouter)
415              print (ttouter)              print (ttouter)
416      else:      else:
# Line 436  Line 438 
438  ##################################################################################################  ##################################################################################################
439    
440  # go backwards  # go backwards
441    # assume outer is op1
442    # assumes inner is op2
443  def go_backwards(opr_outer, opr_inner, testing_frame, cnt):  def go_backwards(opr_outer, opr_inner, testing_frame, cnt):
444      rst2  =  expected_inshape(opr_outer)      k_init = 2
445        print "opr_outer: ",opr_outer.name, " opr_inner: ",opr_inner.name
446        rst2  =  backward_op1(opr_outer,  k_init)
447      # assumes binary outer      # assumes binary outer
448      # assume unary inner      # assume unary inner
449        title =""
450        print "rst2:", len(rst2)
451      for  (tshape1, tshape2) in rst2:      for  (tshape1, tshape2) in rst2:
452          # (_,_)-> tshape          # (_,_)-> tshape
453          dim = tshape2.dim          dim = tshape2.dim
454          # set one of the expressions to be a field          # set one of the expressions to be a field
455          ty1s = d_tofield(dim)          ty1s = d_tofield(dim)
456           # (exp1, _)-> tshapes           # (exp1, _)-> tshapes
457           # print "##############################"          print "##############################"
458          # print "dim: ", dim, "tshape1:",tshape1.name, "tshape2:",tshape2.name          print "dim: ", dim, "tshape1:",tshape1.name, "tshape2:",tshape2.name
459          # arity is 2          # arity is 2
460          for exp  in ty1s:          for exp  in ty1s:
461              # needs to find 2nd argument              # needs to find 2nd argument
462              #print "#############"              print "#############"
463              #print "exp:",exp.name              print "dim: ", dim, "tshape1:",tshape1.name, "tshape2:",tshape2.name
464                print "exp:",exp.name
465              exp1 = exp              exp1 = exp
466                #(exp1 * shape2) ==> tshape1
467                print "(exp1 * shape2) ==> tshape1"
468              shape2 = backwards_op2_arg1(opr_inner, tshape1, exp1)              shape2 = backwards_op2_arg1(opr_inner, tshape1, exp1)
469              if(not(shape2==None)):              if(not(shape2==None)):
470                  title= "\t\tex.(exp1:"+exp1.name+", shape2:"+shape2.name+")-> "+tshape2.name                  tt ="\t\tex.(exp1:"+exp1.name+", shape2:"+shape2.name+")-> "+tshape2.name
471                  #print(title)                  print(tt)
472                    print "dim: ", dim, "tshape1:",tshape1.name, "tshape2:",tshape2.name
473                    print "outer: ", opr_outer.name,"tshape1:",tshape1.name,"-->tshape2:",tshape2.name
474                    print "inner: ", opr_inner.name, "(exp1: "+exp1.name+ ", shape2: "+shape2.name +  " )-->tshape1:",tshape1.name
475    
476                  # convert shape to type                  # convert shape to type
477                  ty2s = shape_to_fty(shape2)                  k_init  = tshape1.k
478                  #print "(shape2",shape2.name,"ty2s",ty2s                  print "before rt2s"
479                    ty2s = shape_to_fty(shape2, k_init)
480                    print "len:", len(ty2s)
481                    #(exp1 * shape2) ==> tshape1
482                    if(fty.is_Field(tshape1) and (not (fty.is_Field(exp1)))):
483                        # then exp2 must be a field
484                        exp2= ty2s[tshape1.dim]
485                        writeall("mark-a")
486                        core_binary_unary(exp1, exp2, dim, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)
487                        print "inner: ", opr_inner.name, "(exp1: "+exp1.name+ ", ty2s[tshape1.dim]: "+ty2s[tshape1.dim].name +  " )-->tshape1:",tshape1.name
488                    elif(fty.is_Tensor(tshape1)):
489                        print "hi"
490                        # then exp2 must be  a tensor
491                        #exp2= ty2s[0]
492                        #print "inner: ", opr_inner.name, "(exp1: "+exp1.name+ ", ty2s[0]: "+ty2s[0].name +  " )-->tshape1:",tshape1.name
493                        #writeall("mark-b")
494                        #core_binary_unary(exp1, exp2, dim, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)
495                    else:
496                                # then exp2 can by anything
497                        print "inner: ", opr_inner.name, "(exp1: "+exp1.name+ ", ty2s-: ",len(ty2s),  " )-->tshape1:",tshape1.name
498                        writeall("mark-c")
499                  backwards_ty_to_exp2(exp1, dim, ty2s, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)                  backwards_ty_to_exp2(exp1, dim, ty2s, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)
500    
501                    #(shape1 * exp2) ==> tshape1
502                print "(shape1 * exp2) ==> tshape1"
503              exp2 = exp              exp2 = exp
504              shape1 = backwards_op2_arg2(opr_inner, tshape1, exp1)              shape1 = backwards_op2_arg2(opr_inner, tshape1, exp2)
505              if(not (shape1==None)):              if(not (shape1==None)):
506                  title= "\t\tex.(shape1:"+shape1.name+", exp2:"+exp2.name+")-> "+tshape2.name                  t = "\t\tex.(shape1:"+shape1.name+", exp2:"+exp2.name+")-> "+tshape2.name
507                  #print(title)                  print(t)
508                  # convert shape to type                  # convert shape to type
                 # gets duplicated  
                 #ty1s = shape_to_fty(shape1)  
                 #backwards_ty_to_exp1(ty1s, dim, exp2, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)  
509                  exp1 = shape_to_tensor(shape1)                  exp1 = shape_to_tensor(shape1)
510                    writeall("mark-d")
511                  core_binary_unary(exp1, exp2, dim, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)                  core_binary_unary(exp1, exp2, dim, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)
512    
513    
# Line 479  Line 515 
515  ##################################################################################################  ##################################################################################################
516  ##################################################################################################  ##################################################################################################
517  # main does everything fowards  # main does everything fowards
518  def pick(opr_inner, opr_outer, testing_frame, cnt):  # shape -> inner-> outer
519    def pick_shape(testing_frame, cnt):
520      #writeTitle_outer(opr_inner, opr_outer)      #writeTitle_outer(opr_inner, opr_outer)
521      # iterate over shapes for first terms      # iterate over shapes for first terms
522      shapes = tvs+tms+tt2+tt3+tt4      shapes = tvs+tms+tt2+tt3+tt4
523      n = len(op_all)      n = len(op_all)
524      startall = time.time()      startall = time.time()
525        opr_outer = None
526      for shape1 in shapes:      for shape1 in shapes:
527          startshape = time.time()          startshape = time.time()
528          writeall ("shape:"+shape1.name)          writeall ("shape:"+shape1.name)
529          #print "shape1 ", shape1          #print "shape1 ", shape1
530          k_init = 2          k_init = 2
531          ty1s = shape_to_fty(shape1, k_init)          ty1s = shape_to_fty(shape1, k_init)
         if(opr_inner == None):  
532              for t_inner in range(n):              for t_inner in range(n):
533                  startxx = time.time()                  startxx = time.time()
534                  opr_inner = id_toOpr(t_inner)                  opr_inner = id_toOpr(t_inner)
# Line 499  Line 536 
536                  counter.zero_total(cnt)                  counter.zero_total(cnt)
537                  pick_get_ty1s(ty1s, shape1, opr_inner, opr_outer, testing_frame, cnt)                  pick_get_ty1s(ty1s, shape1, opr_inner, opr_outer, testing_frame, cnt)
538                  endxx = time.time()                  endxx = time.time()
539                  ttxx = "  timexx-done inner: "+opr_inner.name+str(endxx - startxx)              ttxx = "shape-> inner->..."+opr_inner.name+" time: "+str(endxx - startxx)
540                  writeall(ttxx)                  writeall(ttxx)
541                  print (ttxx)                  print (ttxx)
542          else:              write_results("done specific inner "+t_inner.name+" for a shape "+shape.name, testing_frame, cnt)
543                writeCumulative(cnt)
544                endx = time.time()
545                tsnap = "time: all-snapshot"+str(endx - startall)
546                writeall(tsnap)
547                print (tsnap)
548    
549            write_results("done all inner for a shape "+shape.name, testing_frame, cnt)
550            endx = time.time()
551            tsnap = "time: all-snapshot"+str(endx - startall)
552            writeall(tsnap)
553            print (tsnap)
554    
555    
556    
557        endall = time.time()
558        ttall = " shape->.. time:"+ str(endall - startall)
559        writeall(ttall)
560        print (ttall)
561        write_results("done everything ", testing_frame, cnt)
562        writeCumulative(cnt)
563        return
564    
565    # inner-> outer -> shape
566    def pick_inner(opr_inner, opr_outer, testing_frame, cnt):
567        #writeTitle_outer(opr_inner, opr_outer)
568        # iterate over shapes for first terms
569        shapes = tvs+tms+tt2+tt3+tt4
570        n = len(op_all)
571        startall = time.time()
572        for shape1 in shapes:
573            writeall ("shape:"+shape1.name)
574            #print "shape1 ", shape1
575            k_init = 2
576            ty1s = shape_to_fty(shape1, k_init)
577              pick_get_ty1s(ty1s, shape1, opr_inner, opr_outer, testing_frame, cnt)              pick_get_ty1s(ty1s, shape1, opr_inner, opr_outer, testing_frame, cnt)
578      endall = time.time()      endall = time.time()
579      ttall = "  time all: "+ str(endall - startall)      ttall = "inner-> outer -> shape: "+ str(endall - startall)
580      writeall(ttall)      writeall(ttall)
581      print (ttall)      print (ttall)
582      #print "forwards"      #print "forwards"
# Line 513  Line 584 
584      return      return
585    
586    
587    
588    
589  #handles some backwards  #handles some backwards
590  def pickback(opr_inner, opr_outer, testing_frame, cnt):  def pick_backwards(opr_inner, opr_outer, testing_frame, cnt):
591      #writeTitle_outer(opr_inner, opr_outer)      #writeTitle_outer(opr_inner, opr_outer)
592      # iterate over shapes for first terms      # iterate over shapes for first terms
593      backwards= False      backwards= True
594        print "inside pick"
595      if(backwards):      if(backwards):
596          if(not (opr_outer==None)):          print "mark"
597              if(opr_outer.fieldop):              if(opr_outer.fieldop):
598                print "mark-a"
599                  go_backwards(opr_outer, opr_inner, testing_frame, cnt)                  go_backwards(opr_outer, opr_inner, testing_frame, cnt)
600    
601          elif(opr_inner.arity == 1):          elif(opr_inner.arity == 2) and (opr_outer.arity == 1):
602                # assume outer is op1
603                # assumes inner is op2
604                print "mark-b"
605              go_backwards(opr_outer, opr_inner, testing_frame, cnt)              go_backwards(opr_outer, opr_inner, testing_frame, cnt)
606      else:      else:
607                print "tried going backwards"
608        else:
609          shapes = tvs+tms+tt2+tt3+tt4          shapes = tvs+tms+tt2+tt3+tt4
610          for shape1 in shapes:          for shape1 in shapes:
611              #print "shape1 ", shape1              #print "shape1 ", shape1
# Line 533  Line 613 
613              ty1s = shape_to_fty(shape1, k_init)              ty1s = shape_to_fty(shape1, k_init)
614              pick_get_ty1s(ty1s, shape1, opr_inner, opr_outer, testing_frame, cnt)              pick_get_ty1s(ty1s, shape1, opr_inner, opr_outer, testing_frame, cnt)
615              #print "forwards"              #print "forwards"
616        if(not(opr_inner==None or  opr_outer==None)):
617      writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)      writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
618      return      return
619    

Legend:
Removed from v.4494  
changed lines
  Added in v.4495

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