# SCM Repository

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

Parent Directory | Revision Log

Revision

Original Path:

File size: 1609 byte(s)

**108**- (**download**) (**annotate**)*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) * All rights reserved. *) 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

root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |

Powered by ViewVC 1.0.0 |