Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

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

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

revision 139, Thu Jul 8 18:48:23 2010 UTC revision 155, Fri Jul 9 21:38:01 2010 UTC
# Line 33  Line 33
33
34      val evaluate : polynomial * int -> Rational.rat      val evaluate : polynomial * int -> Rational.rat
35
36      (* some standard kernels *)
37        val tent : kernel           (* linear interpolation *)
38        val ctmr : kernel           (* Catmull-Rom interpolation *)
39        val bspl3 : kernel          (* cubic bspline reconstruction, doesn't interpolate *)
40        val bspl5 : kernel          (* quintic bspline reconstruction, doesn't interpolate *)
41
42    end = struct    end = struct
43
44      structure R = Rational      structure R = Rational
# Line 42  Line 48
48
49      type coefficient = R.rat      type coefficient = R.rat
50
51      val zero = R.fromInt 0      val zero = R.zero
52      val one = R.fromInt 1      val one = R.fromInt 1
53
54    (* polynomial represented as list of coefficients, where ith element is    (* polynomial represented as list of coefficients, where ith element is
# Line 82  Line 88
88        }        }
89
90    (* determine if a list of polynomials represents a continuous piece-wise polynomial *)    (* determine if a list of polynomials represents a continuous piece-wise polynomial *)
91      fun isContinuous polys = let      fun isContinuous [_] = true
92          | isContinuous (f0::r) = let
93            fun chk (i, f_i, []) = (R.zero = evaluate(f_i, i))            fun chk (i, f_i, []) = (R.zero = evaluate(f_i, i))
94              | chk (i, f_i, f_i1::r) = let              | chk (i, f_i, f_i1::r) = let
95                  val y_i = evaluate(f_i, i)                  val y_i = evaluate(f_i, i)
96                  val y_i1 = evaluate(f_i1, i)                  val y_i1 = evaluate(f_i1, i)
97                  in                  in
98                    if (y_i = y_i1)                    (y_i = y_i1) andalso chk(i+1, f_i1, r)
then chk(i+1, f_i1, r)
else false
99                  end                  end
100            in            in
101              case polys of (f0::r) => chk (0, f0, r) | _ => true              chk (1, f0, r)
102            end            end
103
104    (* kernel name *)    (* kernel name *)
# Line 109  Line 114
114                (* compute the (k+1)'th derivative, given the k'th *)                (* compute the (k+1)'th derivative, given the k'th *)
115                  fun diff (k, {isOdd, isCont, segs}) = let                  fun diff (k, {isOdd, isCont, segs}) = let
116                        val segs' = List.map differentiate segs                        val segs' = List.map differentiate segs
117                        val isOdd = not isOdd                        val isOdd' = not isOdd
118                          val isCont' = if isCont andalso isContinuous segs'
119                                then (not isOdd') orelse (evaluate(List.hd segs', 0) = R.zero)
120                                else false
121                        in {                        in {
122                          isOdd = not isOdd,                          isOdd = isOdd',
123                          isCont = isContinuous segs',                          isCont = isCont',
124                          segs = segs'                          segs = segs'
125                        } end                        } end
126                  fun lp (j, curve) = if (j < k)                  fun lp (j, curve) = if (j < k)

Legend:
 Removed from v.139 changed lines Added in v.155