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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 2437 - (download) (annotate)
Mon Sep 23 22:28:42 2013 UTC (6 years ago) by cchiw
File size: 2461 byte(s)
structure  tRewrite = struct


    structure E = Ein
    structure S = Specialize
    structure R = RewriteEin
    structure EinOp = Operators
    structure P= Printer
    structure TS =tSpecialize

(*Testing Substitution*)

      fun test(R.App(e, arg))=print (P.printerE e)
        | test _= print"non match"

    fun scalar (id) = R.App(
        Ein.EIN{params=[Ein.TEN], index=[], body=Ein.Tensor(0, [])},[id])

      fun vec (id,n) = R.App(
            Ein.EIN{params=[Ein.TEN], index=[Ein.IX(n)], body=Ein.Tensor(0, [0])},[id])

        fun matrix (id,n,m) = R.App(
        Ein.EIN{params=[Ein.TEN], index=[Ein.IX(n),Ein.IX(m)], body=Ein.Tensor(0, [0,1])},[id])

      val s1= scalar ("s")
      val a = vec ("a",3)
      val b = vec ("b",3)
      val c = vec ("c",3)
      val d = vec ("d",3)
      val v5 = vec ("v",2)

      val m1=matrix ("a",3,3)
      val m2=matrix ("M", 3, 4)
      val m3=matrix ("MM", 2, 2)
   val addT = R.App(R.evalEinApp (TS.additionT, [a, b]))
   val subT = R.App(R.evalEinApp (TS.subtractionT, [b, c]))
   val identityT=R.App(R.evalEinApp (TS.identityT, []))
   val traceT=R.App(R.evalEinApp (TS.traceT, [m1]))
   val scaleT=R.App(R.evalEinApp (TS.scaleT, [s1,m1]))
   val divideT=R.App(R.evalEinApp (TS.divideT, [a,s1]))
   val transposeT=R.App(R.evalEinApp (TS.transposeT, [m2]))
   val outerProductT= R.App(R.evalEinApp(TS.outerProductT, [d,v5]))

   val dotT = R.App(R.evalEinApp (TS.dotProduct, [a, b]))
   val mxm=   R.App(R.evalEinApp (TS.mxm, [m1,m2]))
   val mxv= R.App(R.evalEinApp (TS.mxv, [m3, a]))
    val mxv2= R.App(R.evalEinApp (TS.mxv, [m3, addT]))
  val mxv3= R.App(R.evalEinApp(TS.addition1T, [mxv, v5]))
  val mxv4= R.App(R.evalEinApp(TS.addition1T, [v5, mxv]))
    (*Combination of things*)
    val mm=R.App(R.evalEinApp(TS.outerProductT,[d,c] ))

    fun run n= let
        val tensorOp=[addT,subT, identityT,traceT, scaleT,divideT, transposeT, outerProductT]
        val t2=[dotT, mxm, mxv]
        val t3=[addT, m3, a,mxv, mxv2,mxv3, mxv4]
        val t4=[addT, m1, mxv]
        if (n=1) then List.map test tensorOp
       else if (n=2) then List.map test t2
        else if (n=3) then List.map test t3 
        else List.map test t4

    val r=run 3

    end; (* local *)

val A = R.App(outerproductE, ["u", "v"])

val s = R.App(R.evalEinApp (EinOp.traceT, [A]))  (*incorrect*)

  end; (* local *)
    end (* local *)

ViewVC Help
Powered by ViewVC 1.0.0