Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

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

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

Tue Jun 15 17:13:55 2010 UTC (11 years, 1 month ago) by jhr
Original Path: trunk/src/IL/kernel.sml
File size: 1609 byte(s)
```  Adding file
```
```(* kernel.sml
*
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
*)

structure Kernel : sig

type coefficient = FloatLit.float

(* polynomial represented as list of coefficients, where ith element is
* coefficient for x^i.
*)
type polynomial = coefficient list

type kernel = {
support : int,		(* number of samples to left/right *)
segs : polynomial list,	(* piece-wise polynomial that defines the *)
(* kernel; there are 2*support segments *)
}

val differentiate : polynomial -> polynomial

val evaluate : polynomial * int -> FloatLit.float

end = struct

structure F = FloatLit

type coefficient = F.float

(* polynomial represented as list of coefficients, where ith element is
* coefficient for x^i.
*)
type polynomial = coefficient list

type kernel = {
support : int,		(* number of samples to left/right *)
segs : polynomial list,	(* piece-wise polynomial that defines the *)
(* kernel; there are 2*support segments *)
}

fun differentiate [] = raise Fail "invalid polynomial"
| differentiate [_] = [F.zero]
| differentiate (_::coeffs) = let
fun lp (_, []) = []
| lp (i, c::r) = F.mul(F.fromInt i, c) :: lp(i+1, r)
in
lp (1, coeffs)
end

(* evaluate a polynomial at an integer coordinate (used to test continuity) *)
fun evaluate (poly, x) = let
val x = F.fromInt x
fun eval (sum, [], xn) = sum
| eval (sum, c::r, xn) = eval(F.add(sum, F.mul(c, xn)), r, F.mul(x, xn))
in
eval (F.zero, poly, F.one)
end

end
```