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

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/compiler/fields/shape.sml
ViewVC logotype

Annotation of /branches/pure-cfg/src/compiler/fields/shape.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 342 - (view) (download)
Original Path: trunk/src/compiler/fields/shape.sml

1 : jhr 342 (* shape.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * A tree representation of the shape of a tensor. The height of the tree
7 :     * corresponds to the order of the tensor plus one. I.e., a 0-order tensor
8 :     * is represented by a leaf, a 1-order tensor will be ND(_, [LF _, ..., LF _]),
9 :     * etc.
10 :     *)
11 :    
12 :     structure Shape =
13 :     struct
14 :    
15 :     datatype ('nd, 'lf) shape
16 :     = LF of 'lf
17 :     | ND of ('nd * ('nd, 'lf) shape list)
18 :    
19 :     (* creates a shape with the given depth and width at each level *)
20 :     fun create (depth, width, ndAttr, f, lfAttr, init) = let
21 :     fun mk (d, i, arg) = if (d < depth)
22 :     then ND(ndAttr arg, List.tabulate(width, fn j => mk(d+1, j, f(j, arg))))
23 :     else LF(lfAttr arg)
24 :     in
25 :     mk (0, 0, init)
26 :     end
27 :    
28 :     fun map (nd, lf) t = let
29 :     fun mapf (LF x) = LF(lf x)
30 :     | mapf (ND(i, kids)) = ND(nd i, List.map mapf kids)
31 :     in
32 :     mapf t
33 :     end
34 :    
35 :     fun foldr f init t = let
36 :     fun fold (LF x, acc) = f(x, acc)
37 :     | fold (ND(_, kids), acc) = List.foldr fold acc kids
38 :     in
39 :     fold t
40 :     end
41 :    
42 :     end

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