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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/fields/field-def.sml
ViewVC logotype

Annotation of /trunk/src/compiler/fields/field-def.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 435 - (view) (download)

1 : jhr 130 (* field-def.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 130 * 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 268 = CONV of int * ImageInfo.info * Kernel.kernel (* CONV(k, V, h) represents D^k(V*h) *)
13 : jhr 130 | NEG of field_def
14 :     | SUM of field_def * field_def
15 :     (* scaling too? *)
16 :    
17 : jhr 286 (* base convolution case *)
18 :     fun convolve (v, h) = CONV(0, v, h)
19 :    
20 : jhr 268 (* smart constructor for DIFF *)
21 :     fun diff (CONV(k, img, h)) = CONV(k+1, img, h)
22 :     | diff (NEG fld) = NEG(diff fld)
23 :     | diff (SUM(fld1, fld2)) = SUM(diff fld1, diff fld2)
24 : jhr 244
25 :     (* slightly smart constructor for NEG *)
26 :     fun neg (NEG fld) = fld
27 :     | neg fld = (NEG fld)
28 :    
29 : jhr 165 (* equality test for field definitions *)
30 : jhr 268 fun same (CONV(k1, img1, kern1), CONV(k2, img2, kern2)) =
31 :     (k1 = k2) andalso ImageInfo.same(img1, img2) andalso Kernel.same(kern1, kern2)
32 : jhr 165 | same (NEG fld1, NEG fld2) = same(fld1, fld2)
33 :     | same (SUM(fld11, fld12), SUM(fld21, fld22)) =
34 :     same(fld11, fld21) andalso same(fld12, fld22)
35 :    
36 :     (* hash value *)
37 : jhr 268 fun hash (CONV(k, img, kern)) =
38 :     Word.fromInt k * 0w17 + 0w3 * ImageInfo.hash img + Kernel.hash kern
39 : jhr 165 | hash (NEG fld) = 0w3 * hash fld + 0w11
40 :     | hash (SUM(fld1, fld2)) = 0w7 * hash fld1 + hash fld2
41 :    
42 : jhr 268 fun toString (CONV(0, img, kern)) =
43 : jhr 192 concat["<", ImageInfo.toString img, "*", Kernel.name kern, ">"]
44 : jhr 268 | toString (CONV(k, img, kern)) =
45 :     concat["(D", Int.toString k, " <", ImageInfo.toString img, "*", Kernel.name kern, ">)"]
46 : jhr 192 | toString (NEG fld) = "-" ^ toString fld
47 :     | toString (SUM(fld1, NEG fld2)) =
48 :     concat["(", toString fld1, "-", toString fld2, ")"]
49 :     | toString (SUM(fld1, fld2)) =
50 :     concat["(", toString fld1, "+", toString fld2, ")"]
51 :    
52 : jhr 130 end

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