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

SCM Repository

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

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

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

revision 2355, Sun Apr 7 11:35:08 2013 UTC revision 2356, Sun Apr 7 14:45:25 2013 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  structure Shape : sig  structure Shape : sig
# Line 23  Line 21 
21     *)     *)
22      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
23    
24      (* createFromShape (shape, labelNd, f, labelLf, root)
25       * creates a shape tree from the given tensor shape (i.e., int list).  The height of the
26       * tree will be length(shape)+1 and the number of children at each level is defined by
27       * the corresponding element of shape.
28       *)
29        val createFromShape : int list * ('a -> 'nd) * (int * 'a -> 'a) * ('a -> 'lf) * 'a -> ('nd, 'lf) shape
30    
31    (* map functions over the nodes and leaves of a shape *)    (* map functions over the nodes and leaves of a shape *)
32      val map : ('a -> 'b) * ('c -> 'd) -> ('a,'c) shape -> ('b,'d) shape      val map : ('a -> 'b) * ('c -> 'd) -> ('a,'c) shape -> ('b,'d) shape
33    
34    (* right-to-left traversal of the tree *)    (* right-to-left traversal of the tree *)
35      val foldr : ('a * 'b -> 'b) -> 'b -> ('c,'a) shape -> 'b      val foldr : ('a * 'b -> 'b) -> 'b -> ('c,'a) shape -> 'b
36    
37      (* apply a node function and a leaf function to the tree in a pre-order traversal *)
38      val appPreOrder : ('nd -> unit) * ('lf -> unit) -> ('nd, 'lf) shape -> unit      val appPreOrder : ('nd -> unit) * ('lf -> unit) -> ('nd, 'lf) shape -> unit
39    
40    end = struct    end = struct
# Line 47  Line 53 
53                else mk (height, init)                else mk (height, init)
54            end            end
55    
56        fun createFromShape (shape, ndAttr, f, lfAttr, init) = let
57              fun mk ([], arg) = LF(lfAttr arg)
58                | mk (d::dd, arg) = ND(ndAttr arg, List.tabulate(d, fn j => mk(dd, f(j, arg))))
59              in
60                mk (shape, init)
61              end
62    
63      fun map (nd, lf) t = let      fun map (nd, lf) t = let
64            fun mapf (LF x) = LF(lf x)            fun mapf (LF x) = LF(lf x)
65              | mapf (ND(i, kids)) = ND(nd i, List.map mapf kids)              | mapf (ND(i, kids)) = ND(nd i, List.map mapf kids)

Legend:
Removed from v.2355  
changed lines
  Added in v.2356

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