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 1115, Thu May 5 04:42:18 2011 UTC revision 1116, Thu May 5 04:49:02 2011 UTC
# Line 7  Line 7
7   * of the tree corresponds to the order of the tensor (or nesting depth) plus   * of the tree corresponds to the order of the tensor (or nesting depth) plus
8   * one.  I.e., a 0-order tensor is represented by a leaf, a 1-order tensor   * one.  I.e., a 0-order tensor is represented by a leaf, a 1-order tensor
9   * will be ND(_, [LF _, ..., LF _]), etc.   * will be ND(_, [LF _, ..., LF _]), etc.
10     *
11     *
12   *)   *)
13
14  structure Shape : sig  structure Shape : sig
# Line 15  Line 17
17        = LF of 'lf        = LF of 'lf
18        | ND of ('nd * ('nd, 'lf) shape list)        | ND of ('nd * ('nd, 'lf) shape list)
19
20    (* create (depth, wid, labelNd, f, labelLf, root)    (* create (h, w, labelNd, f, labelLf, root)
21       * creates a tree of height h (>= 1), with each interior node having
22       * w (>= 1) children.
23     *)     *)
24      val create : int * int * ('a -> 'nd) * (int * 'a -> 'a) * ('a -> 'lf) * 'a -> ('nd, 'lf) shape      val create : int * int * ('a -> 'nd) * (int * 'a -> 'a) * ('a -> 'lf) * 'a -> ('nd, 'lf) shape
25
26      (* map functions over the nodes and leaves of a shape *)
27      val map : ('a -> 'b) * ('c -> 'd) -> ('a,'c) shape -> ('b,'d) shape      val map : ('a -> 'b) * ('c -> 'd) -> ('a,'c) shape -> ('b,'d) shape
28
29    (* right-to-left traversal of the tree *)    (* right-to-left traversal of the tree *)
# Line 32  Line 37
37        = LF of 'lf        = LF of 'lf
38        | ND of ('nd * ('nd, 'lf) shape list)        | ND of ('nd * ('nd, 'lf) shape list)
39
40    (* creates a shape with the given depth and width at each level *)    (* creates a shape with the given height and width at each level *)
41      fun create (depth, width, ndAttr, f, lfAttr, init) = let      fun create (height, width, ndAttr, f, lfAttr, init) = let
42            fun mk (d, i, arg) = if (d < depth)            fun mk (0, arg) = LF(lfAttr arg)
43                  then ND(ndAttr arg, List.tabulate(width, fn j => mk(d+1, j, f(j, arg))))              | mk (d, arg) = ND(ndAttr arg, List.tabulate(width, fn j => mk(d-1, f(j, arg))))
else LF(lfAttr arg)
44            in            in
45              mk (0, 0, init)              if (height < 0) orelse (width < 1)
46                  then raise Size
47                  else mk (height, init)
48            end            end
49
50      fun map (nd, lf) t = let      fun map (nd, lf) t = let

Legend:
 Removed from v.1115 changed lines Added in v.1116