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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 267, Wed Aug 11 04:40:44 2010 UTC revision 268, Wed Aug 11 04:41:04 2010 UTC
# Line 9  Line 9 
9    
10    (* the static definition of a field value *)    (* the static definition of a field value *)
11      datatype field_def      datatype field_def
12        = CONV of ImageInfo.info * Kernel.kernel  (* convolution *)        = CONV of int * ImageInfo.info * Kernel.kernel    (* CONV(k, V, h) represents D^k(V*h) *)
       | DIFF of int * field_def                 (* k levels of differentiation *)  
13        | NEG of field_def        | NEG of field_def
14        | SUM of field_def * field_def        | SUM of field_def * field_def
15  (* scaling too? *)  (* scaling too? *)
16    
17    (* slightly smart constructor for DIFF *)    (* smart constructor for DIFF *)
18      fun diff (DIFF(k, fld)) = DIFF(k+1, fld)      fun diff (CONV(k, img, h)) = CONV(k+1, img, h)
19        | diff fld = DIFF(1, fld)        | diff (NEG fld) = NEG(diff fld)
20          | diff (SUM(fld1, fld2)) = SUM(diff fld1, diff fld2)
21    
22    (* slightly smart constructor for NEG *)    (* slightly smart constructor for NEG *)
23      fun neg (NEG fld) = fld      fun neg (NEG fld) = fld
24        | neg fld = (NEG fld)        | neg fld = (NEG fld)
25    
   (* 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  
   
26    (* equality test for field definitions *)    (* equality test for field definitions *)
27      fun same (CONV(img1, kern1), CONV(img2, kern2)) =      fun same (CONV(k1, img1, kern1), CONV(k2, img2, kern2)) =
28            ImageInfo.same(img1, img2) andalso Kernel.same(kern1, kern2)            (k1 = k2) andalso ImageInfo.same(img1, img2) andalso Kernel.same(kern1, kern2)
       | same (DIFF(k1, fld1), DIFF(k2, fld2)) =  
           (k1 = k2) andalso same(fld1, fld2)  
29        | same (NEG fld1, NEG fld2) = same(fld1, fld2)        | same (NEG fld1, NEG fld2) = same(fld1, fld2)
30        | same (SUM(fld11, fld12), SUM(fld21, fld22)) =        | same (SUM(fld11, fld12), SUM(fld21, fld22)) =
31            same(fld11, fld21) andalso same(fld12, fld22)            same(fld11, fld21) andalso same(fld12, fld22)
32    
33    (* hash value *)    (* hash value *)
34      fun hash (CONV(img, kern)) = 0w3 * ImageInfo.hash img + Kernel.hash kern      fun hash (CONV(k, img, kern)) =
35        | hash (DIFF(k, fld)) = Word.fromInt k * 0w17 + hash fld            Word.fromInt k * 0w17 + 0w3 * ImageInfo.hash img + Kernel.hash kern
36        | hash (NEG fld) = 0w3 * hash fld + 0w11        | hash (NEG fld) = 0w3 * hash fld + 0w11
37        | hash (SUM(fld1, fld2)) = 0w7 * hash fld1 + hash fld2        | hash (SUM(fld1, fld2)) = 0w7 * hash fld1 + hash fld2
38    
39      fun toString (CONV(img, kern)) =      fun toString (CONV(0, img, kern)) =
40            concat["<", ImageInfo.toString img, "*", Kernel.name kern, ">"]            concat["<", ImageInfo.toString img, "*", Kernel.name kern, ">"]
41        | toString (DIFF(k, fld)) =        | toString (CONV(k, img, kern)) =
42            concat["(D", Int.toString k, " ", toString fld, ")"]            concat["(D", Int.toString k, " <", ImageInfo.toString img, "*", Kernel.name kern, ">)"]
43        | toString (NEG fld) = "-" ^ toString fld        | toString (NEG fld) = "-" ^ toString fld
44        | toString (SUM(fld1, NEG fld2)) =        | toString (SUM(fld1, NEG fld2)) =
45            concat["(", toString fld1, "-", toString fld2, ")"]            concat["(", toString fld1, "-", toString fld2, ")"]

Legend:
Removed from v.267  
changed lines
  Added in v.268

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