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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/mid-to-low/helper.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/mid-to-low/helper.sml

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

revision 3138, Thu Mar 26 16:27:35 2015 UTC revision 3263, Mon Sep 28 18:01:40 2015 UTC
# Line 55  Line 55 
55              (b,code)              (b,code)
56          end          end
57    
   
   
58      (* mkINt:int->Var*LowIL.ASSGN list      (* mkINt:int->Var*LowIL.ASSGN list
59      *)      *)
60      fun mkInt n=let      fun mkInt n=let
# Line 86  Line 84 
84      fun assgn(opss,args,pre,ty)=let      fun assgn(opss,args,pre,ty)=let
85          val a=DstIL.Var.new(pre ,ty)          val a=DstIL.Var.new(pre ,ty)
86          val code=DstIL.ASSGN (a,DstIL.OP(opss,args))          val code=DstIL.ASSGN (a,DstIL.OP(opss,args))
87          val _ =testp[LowToS.toStringAll(ty,code)]          val _ =print(String.concat[LowToS.toStringAll(ty,code)])
88    
89          in          in
90              (a,[code])              (a,[code])
91          end          end
# Line 104  Line 103 
103      * ->Var*LowIL.ASSGN list      * ->Var*LowIL.ASSGN list
104      * Index Tensor at specific indices to give a scalar result      * Index Tensor at specific indices to give a scalar result
105      *)      *)
106      fun indexTensor(_,(_,_,args,id, [],ty)) =      fun indexTensor(_,(_,_,args,id, [],ty)) = (List.nth(args,id),[])
107          (List.nth(args,id),[])        | indexTensor(_,(_,_,_,_, [_,_,_],DstTy.TensorTy [_,_,_,_] )) = raise Fail "uneven"
108        | indexTensor(mapp,(lhs,params,args,id,ix,ty))= let        | indexTensor(mapp,(lhs,params,args,id,ix,ty))= let
109          val nU=List.nth(args,id)          val nU=List.nth(args,id)
110          val ixx=(List.map (fn (e1)=> mapIndex(e1,mapp)) ix)          val ixx=(List.map (fn (e1)=> mapIndex(e1,mapp)) ix)
# Line 121  Line 120 
120      * projects tensor to a vector      * projects tensor to a vector
121      *just used by EintoVecOps but made sense to keep it here      *just used by EintoVecOps but made sense to keep it here
122      *)      *)
123      fun projTensor(_,(_,_,args,_,id,[]))= (List.nth(args,id),[])      fun (* projTensor(_,(_,_,args,3,id,[]))=let
124            val opp=DstOp.LdVec 3
125            val nU=List.nth(args,id)
126            val name=String.concat["LdVec_"]
127            val vecTy=DstTy.TensorTy [3]
128            in
129                assgn(opp,[nU],name,vecTy)
130            end
131        |*) projTensor(_,(_,_,args,_,id,[]))= (List.nth(args,id),[])
132      | projTensor(mapp,(lhs,params,args,vecIX,id,ix))= let      | projTensor(mapp,(lhs,params,args,vecIX,id,ix))= let
133          val nU=List.nth(args,id)          val nU=List.nth(args,id)
134          val ixx=(List.map (fn (e1)=> mapIndex(e1,mapp)) ix)          val ixx=(List.map (fn (e1)=> mapIndex(e1,mapp)) ix)
135          val ix'=DstTy.indexTy ixx          val ix'=DstTy.indexTy ixx
136          val argTy= getTensorTy(params,id)          val argTy= getTensorTy(params,id)
137          val vecTy=DstTy.TensorTy [vecIX]          val vecTy=DstTy.TensorTy [vecIX]
138          val opp=DstOp.ProjectTensor(id,vecIX,ix',argTy)          val opp=DstOp.ProjectLast(id,vecIX,ix',argTy)
139          val name=String.concat["Proj_",iToss ixx,"_"]          val name=String.concat["ProjLast_",iToss ixx,"_"]
140          in          in
141              assgn(opp,[nU],name,vecTy)              assgn(opp,[nU],name,vecTy)
142          end          end
143    
144    
145        fun projFirst(mapp,(lhs,params,args,vecIX,id,ix))= let
146            val nU=List.nth(args,id)
147            val argTy= getTensorTy(params,id)
148            val vecTy=DstTy.TensorTy [vecIX]
149            val ixx=(List.map (fn (e1)=> mapIndex(e1,mapp)) ix)
150            fun f cnt = let
151                val ix'=DstTy.indexTy ([cnt]@ixx)
152                val opp=DstOp.IndexTensor(id,ix',argTy)
153                val name=String.concat["IndexTensor_",iToss ixx,"_"]
154                in
155                    assgn(opp,[nU],name,realTy)
156                end
157            val ops=List.tabulate( vecIX, fn e=> f e)
158            fun iter ([],vCs,Cs)=(vCs,Cs)
159              | iter((vB,B)::es,vCs,Cs)= iter(es,vCs@[vB],Cs@B)
160    
161             val (vCs,Cs)=iter(ops,[],[])
162             val (vD,D)=assgnCons("projFirstCons", [vecIX], vCs)
163            in
164                (vD, Cs@D)
165            end
166    
167    
168    
169        fun projFirst2(mapp,(lhs,params,args,vecIX,id,ix))= let
170            val nU=List.nth(args,id)
171            val argTy= getTensorTy(params,id)
172            val vecTy=DstTy.TensorTy [vecIX]
173            val ixx=(List.map (fn (e1)=> mapIndex(e1,mapp)) ix)
174            val ix'=DstTy.indexTy ixx
175            val opp=DstOp.ProjectFirst(id,vecIX,ix',argTy)
176            val name=String.concat["ProjFirst_",iToss ixx,"_"]
177            in assgn(opp,[nU],name,vecTy)
178            end
179    
180    
181    
182      fun mkSqrt(nU,code)= let      fun mkSqrt(nU,code)= let
183          val opp=DstOp.Sqrt          val opp=DstOp.Sqrt
184          val name=String.concat["_Sqrt_"]          val name=String.concat["_Sqrt_"]

Legend:
Removed from v.3138  
changed lines
  Added in v.3263

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