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

# SCM Repository

[diderot] Annotation of /trunk/src/compiler/fields/kernel.sml
 [diderot] / trunk / src / compiler / fields / kernel.sml

# Annotation of /trunk/src/compiler/fields/kernel.sml

Revision 108 - (view) (download)
Original Path: trunk/src/IL/kernel.sml

 1 : jhr 108 (* kernel.sml 2 : * 3 : * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) 4 : * All rights reserved. 5 : *) 6 : 7 : structure Kernel : sig 8 : 9 : type coefficient = FloatLit.float 10 : 11 : (* polynomial represented as list of coefficients, where ith element is 12 : * coefficient for x^i. 13 : *) 14 : type polynomial = coefficient list 15 : 16 : type kernel = { 17 : support : int, (* number of samples to left/right *) 18 : segs : polynomial list, (* piece-wise polynomial that defines the *) 19 : (* kernel; there are 2*support segments *) 20 : } 21 : 22 : val differentiate : polynomial -> polynomial 23 : 24 : val evaluate : polynomial * int -> FloatLit.float 25 : 26 : end = struct 27 : 28 : structure F = FloatLit 29 : 30 : type coefficient = F.float 31 : 32 : (* polynomial represented as list of coefficients, where ith element is 33 : * coefficient for x^i. 34 : *) 35 : type polynomial = coefficient list 36 : 37 : type kernel = { 38 : support : int, (* number of samples to left/right *) 39 : segs : polynomial list, (* piece-wise polynomial that defines the *) 40 : (* kernel; there are 2*support segments *) 41 : } 42 : 43 : fun differentiate [] = raise Fail "invalid polynomial" 44 : | differentiate [_] = [F.zero] 45 : | differentiate (_::coeffs) = let 46 : fun lp (_, []) = [] 47 : | lp (i, c::r) = F.mul(F.fromInt i, c) :: lp(i+1, r) 48 : in 49 : lp (1, coeffs) 50 : end 51 : 52 : (* evaluate a polynomial at an integer coordinate (used to test continuity) *) 53 : fun evaluate (poly, x) = let 54 : val x = F.fromInt x 55 : fun eval (sum, [], xn) = sum 56 : | eval (sum, c::r, xn) = eval(F.add(sum, F.mul(c, xn)), r, F.mul(x, xn)) 57 : in 58 : eval (F.zero, poly, F.one) 59 : end 60 : 61 : end

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