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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 110 - (download) (annotate)
Wed Jun 23 19:28:48 2010 UTC (9 years, 3 months ago) by jhr
File size: 1609 byte(s)
  Moving compiler sources into src/compiler
(* 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