diagrams / diagrams-lib

Diagrams standard library
https://diagrams.github.io/
Other
135 stars 63 forks source link

vector implementation of tridiag solver #178

Open cartazio opened 10 years ago

cartazio commented 10 years ago

noticed it in the vector benchmark suite!

module Algo.Tridiag ( tridiag ) where

import Data.Vector.Unboxed as V

tridiag :: (Vector Double, Vector Double, Vector Double, Vector Double)
            -> Vector Double
{-# NOINLINE tridiag #-}
tridiag (as,bs,cs,ds) = V.prescanr' (\(c,d) x' -> d - c*x') 0
                      $ V.prescanl' modify (0,0)
                      $ V.zip (V.zip as bs) (V.zip cs ds)
    where
      modify (c',d') ((a,b),(c,d)) = 
                   let id = 1 / (b - c'*a)
                   in
                   id `seq` (c*id, (d-d'*a)*id)

might be a decent replacement for the list based one. not sure :)

cartazio commented 10 years ago

though given current diagrams design, this would probably be boxed + perhaps with a specialize pragma for the doubles case