diff options
-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 | ||