linear-circuit 0.1.0.1 → 0.1.0.2
raw patch · 2 files changed
+30/−10 lines, 2 filesdep ~lapackPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: lapack
API changes (from Hackage documentation)
Files
- linear-circuit.cabal +3/−3
- src/Math/LinearCircuit.hs +27/−7
linear-circuit.cabal view
@@ -1,5 +1,5 @@ Name: linear-circuit-Version: 0.1.0.1+Version: 0.1.0.2 Synopsis: Compute resistance of linear electrical circuits Description: Compute resistance of linear electrical circuits.@@ -15,7 +15,7 @@ Cabal-Version: >=1.10 Source-Repository this- Tag: 0.1.0.1+ Tag: 0.1.0.2 Type: darcs Location: http://hub.darcs.net/thielema/linear-circuit @@ -27,7 +27,7 @@ Exposed-Modules: Math.LinearCircuit Build-Depends:- lapack >=0.3 && <0.4,+ lapack >=0.3.1 && <0.4, netlib-ffi >=0.1.1 && <0.2, comfort-array >=0.4 && <0.5, comfort-graph >=0.0 && <0.1,
src/Math/LinearCircuit.hs view
@@ -5,11 +5,11 @@ import Data.Graph.Comfort (Graph) import qualified Numeric.LAPACK.Matrix.Shape as MatrixShape-import qualified Numeric.LAPACK.Matrix.Triangular as Triangular+import qualified Numeric.LAPACK.Matrix.Symmetric as Symmetric import qualified Numeric.LAPACK.Matrix as Matrix import qualified Numeric.LAPACK.Vector as Vector import qualified Numeric.Netlib.Class as Class-import Numeric.LAPACK.Matrix.Triangular ((#%%%#))+import Numeric.LAPACK.Matrix.Symmetric ((#%%%#)) import Numeric.LAPACK.Matrix ((#\|)) import qualified Data.Array.Comfort.Boxed as BoxedArray@@ -40,7 +40,7 @@ fullMatrix :: (Graph.Edge edge, Ord node, Class.Floating a) => Graph edge node a nodeLabel -> node ->- Triangular.Symmetric (():+:(Set (Wrap edge node):+:Set node)) a+ Matrix.Symmetric (():+:(Set (Wrap edge node):+:Set node)) a fullMatrix gr src = let edges = Map.mapKeysMonotonic IdentityT $ Graph.edgeLabels gr nodes = Graph.nodeSet gr@@ -49,15 +49,35 @@ unit = Vector.unit (Map.keysSet edges :+: nodes) (Right src) in (symmetricZero (), Matrix.singleRow order unit) #%%%#- (Triangular.diagonal order $ Array.fromMap edges,+ (Symmetric.diagonal order $ Array.fromMap edges, voltageMatrix nodes $ Map.keysSet edges) #%%%# symmetricZero nodes -resistance ::+_resistance :: (Graph.Edge edge, Ord node, Class.Floating a) => Graph edge node a nodeLabel -> node -> node -> a-resistance gr src dst =+_resistance gr src dst = let m = fullMatrix gr src ix = Right (Right dst)- in - (m #\| Vector.unit (Triangular.size m) ix) ! ix+ in - (m #\| Vector.unit (Symmetric.size m) ix) ! ix++{-+The above computation with blockwise inversion.+-}+resistance ::+ (Graph.Edge edge, Ord node, Class.Floating a) =>+ Graph edge node a nodeLabel -> node -> node -> a+resistance gr src dst =+ let edges = Map.mapKeysMonotonic IdentityT $ Graph.edgeLabels gr+ nodes = Graph.nodeSet gr+ order = MatrixShape.RowMajor+ schurComplement =+ (Matrix.zero $ MatrixShape.symmetric order (),+ Matrix.singleRow order $ Vector.negate $ Vector.unit nodes src)+ #%%%#+ Symmetric.congruenceDiagonal+ (Vector.recip $ Array.fromMap edges)+ (voltageMatrix nodes $ Map.keysSet edges)+ ix = Right dst+ in (schurComplement #\| Vector.unit (() :+: nodes) ix) ! ix