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

# SCM Repository

[diderot] Annotation of /trunk/src/compiler/IL/kernel.sml
 [diderot] / trunk / src / compiler / IL / kernel.sml

# Annotation of /trunk/src/compiler/IL/kernel.sml

Revision 127 - (view) (download)

 1 : jhr 108 (* kernel.sml 2 : * 3 : * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) 4 : * All rights reserved. 5 : jhr 117 * 6 : * QUESTION: should we 7 : jhr 108 *) 8 : 9 : structure Kernel : sig 10 : 11 : jhr 117 type coefficient = Rational.rat 12 : jhr 108 13 : (* polynomial represented as list of coefficients, where ith element is 14 : * coefficient for x^i. 15 : *) 16 : type polynomial = coefficient list 17 : 18 : type kernel = { 19 : support : int, (* number of samples to left/right *) 20 : jhr 117 segs : polynomial list, (* piece-wise polynomial that defines the kernel. Since *) 21 : (* a kernel is symmetric, we only store the positive *) 22 : (* segments, with segs[i] covering the domain [i,i+1) *) 23 : jhr 108 } 24 : 25 : val differentiate : polynomial -> polynomial 26 : 27 : jhr 117 val evaluate : polynomial * int -> Rational.rat 28 : jhr 108 29 : end = struct 30 : 31 : jhr 117 structure R = Rational 32 : jhr 108 33 : jhr 117 type coefficient = R.rat 34 : jhr 108 35 : jhr 117 val zero = R.fromInt 0 36 : val one = R.fromInt 1 37 : 38 : jhr 108 (* polynomial represented as list of coefficients, where ith element is 39 : * coefficient for x^i. 40 : *) 41 : type polynomial = coefficient list 42 : 43 : type kernel = { 44 : support : int, (* number of samples to left/right *) 45 : segs : polynomial list, (* piece-wise polynomial that defines the *) 46 : (* kernel; there are 2*support segments *) 47 : } 48 : 49 : fun differentiate [] = raise Fail "invalid polynomial" 50 : jhr 117 | differentiate [_] = [zero] 51 : jhr 108 | differentiate (_::coeffs) = let 52 : fun lp (_, []) = [] 53 : jhr 117 | lp (i, c::r) = R.mul(F.fromInt i, c) :: lp(i+1, r) 54 : jhr 108 in 55 : lp (1, coeffs) 56 : end 57 : 58 : (* evaluate a polynomial at an integer coordinate (used to test continuity) *) 59 : fun evaluate (poly, x) = let 60 : val x = F.fromInt x 61 : fun eval (sum, [], xn) = sum 62 : jhr 117 | eval (sum, c::r, xn) = eval(F.add(sum, R.mul(c, xn)), r, R.mul(x, xn)) 63 : jhr 108 in 64 : jhr 117 eval (zero, poly, one) 65 : jhr 108 end 66 : 67 : jhr 117 (* some standard kernels *) 68 : local 69 : val op / = R./ 70 : fun r i = R.fromInt i 71 : in 72 : val tent : kernel = { (* linear interpolation *) 73 : support = 1, 74 : segs = [[r 1, r ~1]] 75 : } 76 : val ctmr : kernel = { (* Catmull-Rom interpolation *) 77 : support = 2, 78 : segs = [ 79 : [r 1, r 0, ~5/2, 3/2], 80 : [r 2, r ~4, 5/2, ~1/2] 81 : ] 82 : } 83 : val bspl3 : kernel = { (* cubic bspline reconstruction, doesn't interpolate *) 84 : support = 2, 85 : segs = [ 86 : jhr 122 [ 2/3, r 0, r ~1, 1/2 ], 87 : [ 4/3, r ~2, r 1, ~1/6 ]' 88 : jhr 117 ] 89 : } 90 : val bspl5 : kernel = { (* quintic bspline reconstruction, doesn't interpolate *) 91 : support = 3, 92 : segs = [ 93 : [ 11/20, r 0, ~1/2, r 0, 1/4, ~1/12 ], 94 : jhr 127 [ 17/40, 5/8, ~7/4, 5/4, ~3/8, 1/24 ], 95 : jhr 117 [ 81/40, ~27/8, 9/4, ~3/4, 1/8, ~1/120 ] 96 : ] 97 : } 98 : end 99 : 100 : jhr 108 end

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