SCM Repository
View of /trunk/src/compiler/IL/test-kernel.sml
Parent Directory
|
Revision Log
Revision 153 -
(download)
(annotate)
Fri Jul 9 18:59:12 2010 UTC (12 years ago) by jhr
File size: 2589 byte(s)
Fri Jul 9 18:59:12 2010 UTC (12 years ago) by jhr
File size: 2589 byte(s)
Debugging kernel support using test driver
(* test-kenel.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. * * Text driver for the kernel code. *) structure Test = struct structure R = Rational structure K = Kernel fun eval ({isOdd, isCont, segs}, x) = let fun eval' x = let val {whole, frac} = Real.split x val i = Real.trunc whole fun evalPoly [] = 0.0 | evalPoly (c::r) = R.toReal c + x * evalPoly r in evalPoly (List.nth(segs, i)) handle _ => 0.0 end in if (x >= 0.0) then eval' x else if isOdd then ~(eval' (~x)) else eval' (~x) end local (* Path to Ploticus command *) val plPath = "/usr/local/bin/pl" val env = [ "PLOTICUS_PREFABS=/usr/local/src/ploticus/prefabs" ]; in fun ploticus args outFn = let val proc = Unix.executeInEnv (plPath, args, env) val outS = Unix.textOutstreamOf proc in outFn outS; TextIO.closeOut outS; Unix.reap proc end fun output mergedData outS = let fun plotRow (x, l) = ( TextIO.output(outS, Format.format "%f" [Format.REAL x]); List.app (fn t => TextIO.output(outS, Format.format " %f" [Format.REAL t])) l; TextIO.output(outS, "\n")) in List.app plotRow mergedData end (* command-line arguments for ploticus *) fun args (file, name) = [ "-prefab", "lines", "-eps", "-o", file, "-font", "/Times-Roman", "-textsize", "12", "data=-", "rectangle= 0 1.0 5.5 5.5", "legend= max-1 max", "x=1", "xlbl=X", "xnearest=1", "y=2", "y2=3", "y3=4", "y4=5", "ylbl=Y", "ynearest=1", "pointsym=none", "pointsym2=none", "pointsym3=none", "pointsym4=none", "name= D0", "name2= D1", "name3= D2", "name4= D3", "title= "^name ]; end; (* given a kernel, kernel and its derivatives *) fun plotKernel kern = let val s = Kernel.support kern val curve0 = Kernel.curve(kern, 0) val curve1 = Kernel.curve(kern, 1) val curve2 = Kernel.curve(kern, 2) val curve3 = Kernel.curve(kern, 3) val maxX = Real.fromInt s val step = 1.0 / 64.0 fun lp (x, rows) = if (x <= maxX) then let val rows = (x, [eval(curve0, x), eval(curve1, x), eval(curve2, x), eval(curve3, x)]) :: rows in lp (x+step, rows) end else List.rev rows val rows = lp (~maxX, []) val name = K.name kern in ploticus (args (name ^ ".eps", name)) (output rows); OS.Process.system (concat["/usr/bin/open ", name, ".eps"]) end end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |