From a262e233fc1da0aa01148fd6532c85a6b59e5a75 Mon Sep 17 00:00:00 2001 From: Justin Le Date: Thu, 7 Jan 2016 02:46:11 -0800 Subject: added withRows and withColumns, for ease of working with lists of rows and columns and as inverses of toRows and toColumns --- packages/base/src/Numeric/LinearAlgebra/Static.hs | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index 43a21a3..86c13d7 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs @@ -58,8 +58,8 @@ module Numeric.LinearAlgebra.Static( -- * Misc mean, meanCov, Disp(..), Domain(..), - withVector, exactLength, withMatrix, exactDims, - toRows, toColumns, + withVector, withMatrix, exactLength, exactDims, + toRows, toColumns, withRows, withColumns, Sized(..), Diag(..), Sym, sym, mTm, unSym, (<ยท>) ) where @@ -381,10 +381,30 @@ splitCols = (tr *** tr) . splitRows . tr toRows :: forall m n . (KnownNat m, KnownNat n) => L m n -> [R n] toRows (LA.toRows . extract -> vs) = map mkR vs +withRows + :: forall n z . KnownNat n + => [R n] + -> (forall m . KnownNat m => L m n -> z) + -> z +withRows (LA.fromRows . map extract -> m) f = + case someNatVal $ fromIntegral $ LA.rows m of + Nothing -> error "static/dynamic mismatch" + Just (SomeNat (_ :: Proxy m)) -> f (mkL m :: L m n) toColumns :: forall m n . (KnownNat m, KnownNat n) => L m n -> [R m] toColumns (LA.toColumns . extract -> vs) = map mkR vs +withColumns + :: forall m z . KnownNat m + => [R m] + -> (forall n . KnownNat n => L m n -> z) + -> z +withColumns (LA.fromColumns . map extract -> m) f = + case someNatVal $ fromIntegral $ LA.cols m of + Nothing -> error "static/dynamic mismatch" + Just (SomeNat (_ :: Proxy n)) -> f (mkL m :: L m n) + + -------------------------------------------------------------------------------- -- cgit v1.2.3