# SCM Repository

# View of /trunk/src/compiler/fields/field-def.sml

Parent Directory | Revision Log

Revision

File size: 2378 byte(s)

**244**- (**download**) (**annotate**)*Fri Aug 6 15:31:13 2010 UTC*(10 years, 5 months ago) by*jhr*File size: 2378 byte(s)

Added smart constructors

(* field-def.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. *) structure FieldDef = struct (* the static definition of a field value *) datatype field_def = CONV of ImageInfo.info * Kernel.kernel (* convolution *) | DIFF of int * field_def (* k levels of differentiation *) | NEG of field_def | SUM of field_def * field_def (* scaling too? *) (* slightly smart constructor for DIFF *) fun diff (DIFF(k, fld)) = DIFF(k+1, fld) | diff fld = DIFF(1, fld) (* slightly smart constructor for NEG *) fun neg (NEG fld) = fld | neg fld = (NEG fld) (* normalize a field definition by pushing the DIFF operators to the * leaves *) fun normalize fld = let fun norm fld = (case fld of CONV _ => fld | DIFF(k, fld) => diff (k, fld) | NEG(NEG fld) => norm fld | NEG fld => NEG(norm fld) | SUM(fld1, fld2) => SUM(norm fld1, norm fld2) (* end case *)) and diff (k, fld) = (case fld of CONV _ => DIFF(k, fld) | DIFF(k', fld) => diff (k+k', fld) | NEG(NEG fld) => norm fld | NEG fld => NEG(diff(k, fld)) | SUM(fld1, fld2) => SUM(diff(k, fld1), diff(k, fld2)) (* end case *)) in norm fld end (* equality test for field definitions *) fun same (CONV(img1, kern1), CONV(img2, kern2)) = ImageInfo.same(img1, img2) andalso Kernel.same(kern1, kern2) | same (DIFF(k1, fld1), DIFF(k2, fld2)) = (k1 = k2) andalso same(fld1, fld2) | same (NEG fld1, NEG fld2) = same(fld1, fld2) | same (SUM(fld11, fld12), SUM(fld21, fld22)) = same(fld11, fld21) andalso same(fld12, fld22) (* hash value *) fun hash (CONV(img, kern)) = 0w3 * ImageInfo.hash img + Kernel.hash kern | hash (DIFF(k, fld)) = Word.fromInt k * 0w17 + hash fld | hash (NEG fld) = 0w3 * hash fld + 0w11 | hash (SUM(fld1, fld2)) = 0w7 * hash fld1 + hash fld2 fun toString (CONV(img, kern)) = concat["<", ImageInfo.toString img, "*", Kernel.name kern, ">"] | toString (DIFF(k, fld)) = concat["(D", Int.toString k, " ", toString fld, ")"] | toString (NEG fld) = "-" ^ toString fld | toString (SUM(fld1, NEG fld2)) = concat["(", toString fld1, "-", toString fld2, ")"] | toString (SUM(fld1, fld2)) = concat["(", toString fld1, "+", toString fld2, ")"] end

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

Powered by ViewVC 1.0.0 |