# SCM Repository

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

Parent Directory | Revision Log

Revision

File size: 2094 byte(s)

**201**- (**download**) (**annotate**)*Tue Aug 3 12:57:10 2010 UTC*(11 years, 9 months ago) by*jhr*File size: 2094 byte(s)

Reorganizing source

(* 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? *) (* 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 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 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 |