[<<][compsci][>>][..]
Sun Apr 1 12:11:48 CEST 2012

Node binding (equation solving) : sequential approach

It seems too much hassle to find a "family of functions" approach,
especially because the result just needs to be a table.  Might be
simpler to just do it in-place, and define a single "fill in solver"
for each primitive equation type.

Still, that makes it difficult to separate the structural compilation
step (network -> function) from the evaluation step.

Still very confused.

So what about this:

  - structural compilation (abstract evaluation) produces indices for
    the shared data function.

  - function is an array -> array map, parameterized by 2 lists of
    indices for input and output.

Let's make an example for a linear functional.

I'd like to be able to work with mutable arrays inside the
implementation, so which should be the array at the interface
boundary?  This is determined by the type of

  runSTArray ::  Ix i => (forall s. ST s (STArray s i e)) -> Array i e

which is Array[1], for which the simplest constructor is:

  listArray :: (IArray a e, Ix i) => (i, i) -> [e] -> a i e



After playing with direct imperative access and looping indices for a
bit, it turns out that there are simpler ways.  I.e. the function
below solves a sum functional given a vector of coordinates and the
index to update.

  sumA = Data.Foldable.foldr1 (+)
  type Nodes = Array Int Double
  eqSum :: [Int] -> Nodes -> Nodes
  eqSum [o] ia = runSTArray $ do
    oa <- thaw ia
    writeArray oa o $ (ia ! o) - sumA ia
    return oa

But..  this doesn't take into account that the equations should have
references to nodes.  It seems that it's best to put the lowlevel
stuff inside an ST monad and work with references.  ( The excursion to
arrays was actually just a roundabout way of working with
references.. maybe also to not have to specificy holes by keeping them
implicit. )

  type Node s = STRef s (Maybe Double)
  foldNodes f = foldM (\accu el -> do
                          me <- readSTRef el
                          return $ me >>= f accu)
  foldNodes1 f (x:xs) = foldNodes f x xs

What about this as basic datastructure:
  - nb of nodes to satisfy
  - ordered list of references to nodes
  - op: fold over Just components

Probably an array of STRefs is easier to work with since it allows for
direct indexing.


[1] http://www.haskell.org/ghc/docs/latest/html/libraries/array/Data-Array-IArray.html#t:Array




[Reply][About]
[<<][compsci][>>][..]