-
Notifications
You must be signed in to change notification settings - Fork 0
/
formalize
51 lines (38 loc) · 1.4 KB
/
formalize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
map
reduce -- tree reduce
scan
vectorize -- partition
devectorize -- flatten
upsample
downsample
stencil
broadcast
zip
pad
crop
-- All operations assumed to be 1-dimensional
map :: (a -> b) -> [a] -> [b]
reduce :: (a -> a -> a) -> [a] -> a
scan :: (a -> a -> a) -> [a] -> [a]
zip :: [a] -> [b] -> [(a, b)]
filter :: (a -> bool) -> [a] -> [a]
vectorize :: Int -> [a] -> [a]
partition :: Int -> [a] -> [[a]]
devectorize :: Int -> [a] -> [a] -- @todo: does this take an Int?
flatten :: Int -> [[a]] -> [a] -- @todo: does this take an Int?
upsample :: Int -> Int -> [a] -> [a]
downsample :: Int -> Int -> [a] -> [a]
-- @todo: should this be a -> [a] and then you map stencil instead?
stencil :: Int -> [a] -> [[a]]
broadcast :: Int -> a -> [a]
pad :: Int -> Int -> [a] -> [a]
crop :: Int -> Int -> [a] -> [a]
devectorize(m*n, m) := partition(m) -> map_seq(m)
reduce_seq(m) := vectorize(m) -> reduce_par(m)
reduce_par(m*n) := devectorize(m) -> reduce_par(n) -> reduce_seq(m)
reduce_par(m*n) := devectorize(m) -> reduce_par(n) -> vectorize(m) -> reduce_par(m)
map_par(m*n) := devectorize(m) -> map_par(n) -> vectorize(m)
stencil(m*n) := devectorize(m) -> stencil(n) -> vectorize(m)
downsample(n*m, m) := devectorize(n) -> downsample(m, 1) -> vectorize(n)
reduce_rate(broadcast(m*n, input), k*m*n) := broadcast(1, reduce_rate(input, k)) ?
reduce_rate(broadcast(n), m*n) := vectorize(m) -> vectorize(n)?