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
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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