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 3349 - (view) (download)

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

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