diff options
author | Justin Le <justin@jle.im> | 2016-01-07 02:46:11 -0800 |
---|---|---|
committer | Justin Le <justin@jle.im> | 2016-01-07 02:46:11 -0800 |
commit | a262e233fc1da0aa01148fd6532c85a6b59e5a75 (patch) | |
tree | 94645732f7ad42dc29edf57bebee6ed18c571918 /packages/base/src | |
parent | 5d703ef02dc7bfd51b953753a7fef0e68a9dcc5b (diff) |
added withRows and withColumns, for ease of working with lists of rows and columns and as inverses of toRows and toColumns
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Static.hs | 24 |
1 files 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( | |||
58 | -- * Misc | 58 | -- * Misc |
59 | mean, meanCov, | 59 | mean, meanCov, |
60 | Disp(..), Domain(..), | 60 | Disp(..), Domain(..), |
61 | withVector, exactLength, withMatrix, exactDims, | 61 | withVector, withMatrix, exactLength, exactDims, |
62 | toRows, toColumns, | 62 | toRows, toColumns, withRows, withColumns, |
63 | Sized(..), Diag(..), Sym, sym, mTm, unSym, (<·>) | 63 | Sized(..), Diag(..), Sym, sym, mTm, unSym, (<·>) |
64 | ) where | 64 | ) where |
65 | 65 | ||
@@ -381,10 +381,30 @@ splitCols = (tr *** tr) . splitRows . tr | |||
381 | toRows :: forall m n . (KnownNat m, KnownNat n) => L m n -> [R n] | 381 | toRows :: forall m n . (KnownNat m, KnownNat n) => L m n -> [R n] |
382 | toRows (LA.toRows . extract -> vs) = map mkR vs | 382 | toRows (LA.toRows . extract -> vs) = map mkR vs |
383 | 383 | ||
384 | withRows | ||
385 | :: forall n z . KnownNat n | ||
386 | => [R n] | ||
387 | -> (forall m . KnownNat m => L m n -> z) | ||
388 | -> z | ||
389 | withRows (LA.fromRows . map extract -> m) f = | ||
390 | case someNatVal $ fromIntegral $ LA.rows m of | ||
391 | Nothing -> error "static/dynamic mismatch" | ||
392 | Just (SomeNat (_ :: Proxy m)) -> f (mkL m :: L m n) | ||
384 | 393 | ||
385 | toColumns :: forall m n . (KnownNat m, KnownNat n) => L m n -> [R m] | 394 | toColumns :: forall m n . (KnownNat m, KnownNat n) => L m n -> [R m] |
386 | toColumns (LA.toColumns . extract -> vs) = map mkR vs | 395 | toColumns (LA.toColumns . extract -> vs) = map mkR vs |
387 | 396 | ||
397 | withColumns | ||
398 | :: forall m z . KnownNat m | ||
399 | => [R m] | ||
400 | -> (forall n . KnownNat n => L m n -> z) | ||
401 | -> z | ||
402 | withColumns (LA.fromColumns . map extract -> m) f = | ||
403 | case someNatVal $ fromIntegral $ LA.cols m of | ||
404 | Nothing -> error "static/dynamic mismatch" | ||
405 | Just (SomeNat (_ :: Proxy n)) -> f (mkL m :: L m n) | ||
406 | |||
407 | |||
388 | 408 | ||
389 | -------------------------------------------------------------------------------- | 409 | -------------------------------------------------------------------------------- |
390 | 410 | ||