-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.hs
More file actions
88 lines (71 loc) · 2.03 KB
/
Graph.hs
File metadata and controls
88 lines (71 loc) · 2.03 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{-# OPTIONS
-XMultiParamTypeClasses
-XFunctionalDependencies
-XFlexibleInstances
-XRank2Types
-XGADTs
-XPolyKinds
-XLambdaCase
-XTemplateHaskell
-XFlexibleContexts
-XDeriveFunctor
#-}
module Graph where
import Prelude hiding ((+), (*), (-))
import Algebra.Additive as Additive
import Algebra.Ring hiding (product)
import Control.Monad
import Control.Monad.Free
import Control.Lens
import Data.Maybe
import Text.Printf
import qualified Data.Set as S
import Data.List
import qualified Data.Map as M
import Data.Functor
import Control.Applicative
import MonadUtilities
import Shape
import Tensor
import Args
-- |
-- = TensorFlow graph and monad
data TGraph next =
SetDefaultInits String next
| InitVar String Shape Py (T -> next)
| InitVarWithDefault String Shape (T -> next)
| InitPH String Shape (T -> next)
-- | GetScope String (String -> next)
-- | SetScope String next
| AddScope String next
-- | NewScope next
| ExitScope next
| Get String (T -> next)
| Save T (T -> next)
deriving Functor
-- | Fun String T (T -> (String, T)) (T -> next)
type Flow = Free TGraph
setDefaultInits str = liftF (SetDefaultInits str ())
initVar :: (Shapable a, Argable s) => String -> a -> s -> Flow T
initVar str li f = Free $ InitVar str (s li) (p f) Pure
--liftF (InitVar str li f id)
initPH :: (Shapable a) => String -> a -> Flow T
initPH str sh = Free $ InitPH str (s sh) Pure
initVarWithDefault :: (Shapable a) => String -> a -> Flow T
initVarWithDefault str li = Free $ InitVarWithDefault str (s li) Pure
--liftF (InitVarWithDefault str id)
get str = liftF (Get str id)
save t = liftF (Save t id)
--getScope str = liftF (GetScope str id)
--setScope str = liftF (SetScope str ())
addScope str = liftF (AddScope str ())
exitScope = liftF (ExitScope ())
scope :: String -> Flow a -> Flow a
scope str tf = do
-- cur <- getScope
addScope str
x <- tf
-- setScope cur
exitScope
return x
--set default init within scope