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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/einTest/testkrn.sml
ViewVC logotype

View of /branches/charisee/src/compiler/einTest/testkrn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2521 - (download) (annotate)
Thu Jan 9 02:17:07 2014 UTC (5 years, 7 months ago) by cchiw
File size: 3466 byte(s)
Added type Checker
(*hashs Ein Function after substitution*)
structure tkrn = struct
    local
    structure E = Ein
    structure G=genType
    structure genEin=genEin
    structure genKrn=genKrn
    structure P=Printer
    in



fun createKrn(sumi,0,dels)=let
        val dels'=List.map (fn(e)=>(E.C 0, e)) dels
        val posx=E.Sub(E.Tensor(0,[E.C 0]), E.Value(sumi))
        in [E.Krn(0,dels',posx)] end
    | createKrn(sumi,d,dels)=let
            val dels'=List.map (fn(e)=>(E.C d, e)) dels
            val posx=E.Sub(E.Tensor(0,[E.C d]), E.Value(sumi+d))
            val k1=E.Krn(d,dels',posx)
            in createKrn(sumi, d-1,dels)@[k1]
            end


val [k1,k2,k3]=createKrn(0,2,[])
val [h11,h12,h13] =createKrn(1,2,[E.V 0])
val [h21,h22,h23] =createKrn(2,2,[E.V 0,E.V 1])

val img01=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 0]])
val img02=E.Img(2,[],
    [E.Add[E.Tensor(1,[E.C 0]),E.Value 0],E.Add[E.Tensor(1,[E.C 1]),E.Value 1]])
val img03=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 0],
    E.Add[E.Tensor(1,[E.C 1]),E.Value 1], E.Add[E.Tensor(1,[E.C 2]),E.Value 2]])

val img11=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 1]])
val img12=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 1],E.Add[E.Tensor(1,[E.C 1]),E.Value 2]])
val img13=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 1],
    E.Add[E.Tensor(1,[E.C 1]),E.Value 2], E.Add[E.Tensor(1,[E.C 2]),E.Value 3]])

val img21=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 2]])
val img22=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 2],E.Add[E.Tensor(1,[E.C 1]),E.Value 3]])
val img23=E.Img(2,[],[E.Add[E.Tensor(1,[E.C 0]),E.Value 2],E.Add[E.Tensor(1,[E.C 1]),E.Value 3],
            E.Add[E.Tensor(1,[E.C 2]),E.Value 4]])


(*Scalar Field, Image*)
(* {k=0 } *)
val S01=E.EIN{params=[E.TEN 1,E.KRN], index=[],
    body=E.Sum([(E.V 0,6,7)],E.Prod[img01,k1])}
val S02=E.EIN{params=[E.TEN 1,E.KRN], index=[],
    body=E.Sum([(E.V 0,6,7),(E.V 1,8,9)],E.Prod[img02,k1,k2])}
val S03=E.EIN{params=[E.TEN 1,E.KRN], index=[],
    body=E.Sum([(E.V 0,6,6),(E.V 1,8,8),(E.V 2,3,4)],
    E.Prod[img03,k1,k2,k3])}
val scaF0=[S01,S02,S03]

(*Differentiation*)
(* {h0^δ_0i+h1^δ_1i }i *)
(*k=1*)

val S11=E.EIN{params=[E.TEN 1,E.KRN], index=[0],
    body=E.Sum([(E.V 1,6,7)],E.Prod[img11,h11])}
val S12=E.EIN{params=[E.TEN 1,E.KRN], index=[1],
    body=E.Sum([(E.V 1,6,6),(E.V 2,8,9)],E.Prod[img12,h11,h12])}
val S13=E.EIN{params=[E.TEN 1,E.KRN], index=[2],
    body=E.Sum([(E.V 1,6,6),(E.V 2,8,8),(E.V 3, 9,9)],E.Prod[img13,h11,h12,h13])}
val scaF1=[S11,S12,S13]

(*Differentiation, k=2*)
val S22=E.EIN{params=[E.TEN 1,E.KRN], index=[1,1],
body=E.Sum([(E.V 2,6,6),(E.V 3,8,9)],E.Prod[img22,h21,h22])}
val S23=E.EIN{params=[E.TEN 1,E.KRN], index=[2,2],
body=E.Sum([(E.V 2,6,6),(E.V 3,8,8),(E.V 4, 9,9)],E.Prod[img23,h21,h22,h23])}
val scaF2=[S22]

(*Vector Field*)
val img11=E.Img(2,[E.V 0],[E.Add[E.Tensor(1,[E.C 0]),E.Value 1]])

val img12=E.Img(2,[E.V 0],[E.Add[E.Tensor(1,[E.C 0]),E.Value 1],E.Add[E.Tensor(1,[E.C 1]),E.Value 2]])
val img13=E.Img(2,[E.V 0],[E.Add[E.Tensor(1,[E.C 0]),E.Value 1],E.Add[E.Tensor(1,[E.C 1]),E.Value 2], E.Add[E.Tensor(1,[E.C 2]),E.Value 3]])
val [k1,k2,k3]=createKrn(1,2,[])


val V01=E.EIN{params=[E.TEN 1,E.KRN], index=[1],
    body=E.Sum([(E.V 1,6,7)],E.Prod[img11,k1])}

val vec=[V01]

fun m e =let
    val x=print(P.printerE e)
    val e'=genKrn.genfn e
   in  List.map (fn e1=> print(String.concat["\n",G.printOp(e1,"")])) e'
    end

val ta=List.map m vec
end (* local *)

end 

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