SCM Repository
Annotation of /trunk/src/compiler/IL/field-def.sml
Parent Directory
|
Revision Log
Revision 192 - (view) (download)
1 : | jhr | 130 | (* field-def.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | *) | ||
6 : | |||
7 : | structure FieldDef = | ||
8 : | struct | ||
9 : | |||
10 : | (* the static definition of a field value *) | ||
11 : | jhr | 135 | datatype field_def |
12 : | jhr | 130 | = CONV of ImageInfo.info * Kernel.kernel (* convolution *) |
13 : | jhr | 131 | | DIFF of int * field_def (* k levels of differentiation *) |
14 : | jhr | 130 | | NEG of field_def |
15 : | | SUM of field_def * field_def | ||
16 : | (* scaling too? *) | ||
17 : | |||
18 : | jhr | 131 | (* normalize a field definition by pushing the DIFF operators to the |
19 : | * leaves | ||
20 : | *) | ||
21 : | fun normalize fld = let | ||
22 : | fun norm fld = (case fld | ||
23 : | of CONV _ => fld | ||
24 : | | DIFF(k, fld) => diff (k, fld) | ||
25 : | | NEG fld => NEG(norm fld) | ||
26 : | | SUM(fld1, fld2) => SUM(norm fld1, norm fld2) | ||
27 : | (* end case *)) | ||
28 : | and diff (k, fld) = (case fld | ||
29 : | of CONV _ => DIFF(k, fld) | ||
30 : | | DIFF(k', fld) => diff (k+k', fld) | ||
31 : | | NEG fld => NEG(diff(k, fld)) | ||
32 : | | SUM(fld1, fld2) => SUM(diff(k, fld1), diff(k, fld2)) | ||
33 : | (* end case *)) | ||
34 : | in | ||
35 : | norm fld | ||
36 : | end | ||
37 : | |||
38 : | jhr | 165 | (* equality test for field definitions *) |
39 : | fun same (CONV(img1, kern1), CONV(img2, kern2)) = | ||
40 : | ImageInfo.same(img1, img2) andalso Kernel.same(kern1, kern2) | ||
41 : | | same (DIFF(k1, fld1), DIFF(k2, fld2)) = | ||
42 : | (k1 = k2) andalso same(fld1, fld2) | ||
43 : | | same (NEG fld1, NEG fld2) = same(fld1, fld2) | ||
44 : | | same (SUM(fld11, fld12), SUM(fld21, fld22)) = | ||
45 : | same(fld11, fld21) andalso same(fld12, fld22) | ||
46 : | |||
47 : | (* hash value *) | ||
48 : | fun hash (CONV(img, kern)) = 0w3 * ImageInfo.hash img + Kernel.hash kern | ||
49 : | | hash (DIFF(k, fld)) = Word.fromInt k * 0w17 + hash fld | ||
50 : | | hash (NEG fld) = 0w3 * hash fld + 0w11 | ||
51 : | | hash (SUM(fld1, fld2)) = 0w7 * hash fld1 + hash fld2 | ||
52 : | |||
53 : | jhr | 192 | fun toString (CONV(img, kern)) = |
54 : | concat["<", ImageInfo.toString img, "*", Kernel.name kern, ">"] | ||
55 : | | toString (DIFF(k, fld)) = | ||
56 : | concat["(D", Int.toString k, " ", toString fld, ")"] | ||
57 : | | toString (NEG fld) = "-" ^ toString fld | ||
58 : | | toString (SUM(fld1, NEG fld2)) = | ||
59 : | concat["(", toString fld1, "-", toString fld2, ")"] | ||
60 : | | toString (SUM(fld1, fld2)) = | ||
61 : | concat["(", toString fld1, "+", toString fld2, ")"] | ||
62 : | |||
63 : | jhr | 130 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |