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

SCM Repository

[diderot] Diff of /trunk/src/compiler/fields/kernel.sml
ViewVC logotype

Diff of /trunk/src/compiler/fields/kernel.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 110, Wed Jun 23 19:28:48 2010 UTC revision 117, Thu Jun 24 14:00:22 2010 UTC
# Line 2  Line 2 
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5     *
6     * QUESTION: should we
7   *)   *)
8    
9  structure Kernel : sig  structure Kernel : sig
10    
11      type coefficient = FloatLit.float      type coefficient = Rational.rat
12    
13    (* polynomial represented as list of coefficients, where ith element is    (* polynomial represented as list of coefficients, where ith element is
14     * coefficient for x^i.     * coefficient for x^i.
# Line 15  Line 17 
17    
18      type kernel = {      type kernel = {
19          support : int,          (* number of samples to left/right *)          support : int,          (* number of samples to left/right *)
20          segs : polynomial list, (* piece-wise polynomial that defines the *)          segs : polynomial list, (* piece-wise polynomial that defines the kernel.  Since *)
21                                  (* kernel; there are 2*support segments *)                                  (* a kernel is symmetric, we only store the positive *)
22                                    (* segments, with segs[i] covering the domain [i,i+1) *)
23        }        }
24    
25      val differentiate : polynomial -> polynomial      val differentiate : polynomial -> polynomial
26    
27      val evaluate : polynomial * int -> FloatLit.float      val evaluate : polynomial * int -> Rational.rat
28    
29    end = struct    end = struct
30    
31      structure F = FloatLit      structure R = Rational
32    
33      type coefficient = F.float      type coefficient = R.rat
34    
35        val zero = R.fromInt 0
36        val one = R.fromInt 1
37    
38    (* polynomial represented as list of coefficients, where ith element is    (* polynomial represented as list of coefficients, where ith element is
39     * coefficient for x^i.     * coefficient for x^i.
# Line 41  Line 47 
47        }        }
48    
49      fun differentiate [] = raise Fail "invalid polynomial"      fun differentiate [] = raise Fail "invalid polynomial"
50        | differentiate [_] = [F.zero]        | differentiate [_] = [zero]
51        | differentiate (_::coeffs) = let        | differentiate (_::coeffs) = let
52            fun lp (_, []) = []            fun lp (_, []) = []
53              | lp (i, c::r) = F.mul(F.fromInt i, c) :: lp(i+1, r)              | lp (i, c::r) = R.mul(F.fromInt i, c) :: lp(i+1, r)
54            in            in
55              lp (1, coeffs)              lp (1, coeffs)
56            end            end
# Line 53  Line 59 
59      fun evaluate (poly, x) = let      fun evaluate (poly, x) = let
60            val x = F.fromInt x            val x = F.fromInt x
61            fun eval (sum, [], xn) = sum            fun eval (sum, [], xn) = sum
62              | eval (sum, c::r, xn) = eval(F.add(sum, F.mul(c, xn)), r, F.mul(x, xn))              | eval (sum, c::r, xn) = eval(F.add(sum, R.mul(c, xn)), r, R.mul(x, xn))
63            in            in
64              eval (F.zero, poly, F.one)              eval (zero, poly, one)
65              end
66    
67      (* 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                    [ 2/3, 0, -1, 1/2 ],
87                    [ 4/3, -2, 1, ~1/6 ]'
88                  ]
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                    [ 17/40, 5/8, ~7/4, 5/4, ~3/8, 1/24 ]
95                    [ 81/40, ~27/8, 9/4, ~3/4, 1/8, ~1/120 ]
96                  ]
97              }
98            end            end
99    
100    end    end

Legend:
Removed from v.110  
changed lines
  Added in v.117

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