Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] Diff of /trunk/src/compiler/fields/shape.sml
 [diderot] / trunk / src / compiler / fields / shape.sml

# Diff of /trunk/src/compiler/fields/shape.sml

revision 342, Wed Sep 15 21:52:14 2010 UTC revision 353, Fri Sep 24 21:43:11 2010 UTC
# Line 3  Line 3
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
5   *   *
6   * A tree representation of the shape of a tensor.  The height of the tree   * A tree representation of the shape of a tensor (or loop nest).  The height
7   * corresponds to the order of the tensor plus one.  I.e., a 0-order tensor   * of the tree corresponds to the order of the tensor (or nesting depth) plus
8   * is represented by a leaf, a 1-order tensor will be ND(_, [LF _, ..., LF _]),   * one.  I.e., a 0-order tensor is represented by a leaf, a 1-order tensor
9   * etc.   * will be ND(_, [LF _, ..., LF _]), etc.
10   *)   *)
11
12  structure Shape =  structure Shape : sig
13    struct
14        datatype ('nd, 'lf) shape
15          = LF of 'lf
16          | ND of ('nd * ('nd, 'lf) shape list)
17
18      (* create (depth, wid, labelNd, f, labelLf, root)
19       *)
20        val create : int * int * ('a -> 'nd) * (int * 'a -> 'a) * ('a -> 'lf) * 'a -> ('nd, 'lf) shape
21
22        val map : ('a -> 'b) * ('c -> 'd) -> ('a,'c) shape -> ('b,'d) shape
23
24      (* right-to-left traversal of the tree *)
25        val foldr : ('a * 'b -> 'b) -> 'b -> ('c,'a) shape -> 'b
26
27        val appPreOrder : ('nd -> unit) * ('lf -> unit) -> ('nd, 'lf) shape -> unit
28
29      end = struct
30
31      datatype ('nd, 'lf) shape      datatype ('nd, 'lf) shape
32        = LF of 'lf        = LF of 'lf
# Line 36  Line 52
52            fun fold (LF x, acc) = f(x, acc)            fun fold (LF x, acc) = f(x, acc)
53              | fold (ND(_, kids), acc) = List.foldr fold acc kids              | fold (ND(_, kids), acc) = List.foldr fold acc kids
54            in            in
55              fold t              fold (t, init)
56              end
57
58        fun appPreOrder (ndFn, lfFn) = let
59              fun app (ND(attr, kids)) = (ndFn attr; List.app app kids)
60                | app (LF attr) = lfFn attr
61              in
62                app
63            end            end
64
65    end    end

Legend:
 Removed from v.342 changed lines Added in v.353