Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More documentation for Data.Packed.Static.Shapes

Ignore-this: d515dd332b6cc7c425bbfad183575ae9

darcs-hash:20090412005948-7eff5-10dfce8062d20fe817de650ebe1649e1a6744300.gz
  • Loading branch information...
commit bc682a87ff1d3551f7cccfbca59fb7c036d0a43a 1 parent 31432f0
@reinerp authored
View
3  Data/Packed/Static/Imports.hs
@@ -8,7 +8,8 @@
-- Stability : experimental
-- Portability : portable
--
--- Useful imports from other packages
+-- Useful imports from other packages. In particular:
+-- imports from TFP, Foreign.Storable, and HMatrix.
--
-----------------------------------------------------------------------------
View
4 Data/Packed/Static/Matrix.hs
@@ -452,15 +452,19 @@ liftMatrix2 :: (Element t, Element a, Element b) =>
-> Matrix (m,n) t
liftMatrix2 f a b = Matrix $ H.liftMatrix2 (\v w -> unVector $ f (Vector v) (Vector w)) (unMatrix a) (unMatrix b)
+-- | See hmatrix's 'H.format'.
format :: (Element t) => String -> (t -> String) -> Matrix (m,n) t -> String
format s f = H.format s f . unMatrix
+-- | See hmatrix's 'H.readMatrix'.
readMatrix :: String -> Matrix (Unknown,Unknown) Double
readMatrix = wrapU . H.readMatrix
+-- | See hmatrix's 'H.fromFile'.
fromFile :: FilePath -> (Int, Int) -> IO (Matrix (Unknown,Unknown) Double)
fromFile f s = fmap wrapU $ H.fromFile f s
+-- | See hmatrix's 'H.fromArray2D'.
fromArray2D :: (Element t) => Array (Int, Int) t -> Matrix (Unknown,Unknown) t
fromArray2D = wrapU . H.fromArray2D
View
30 Data/Packed/Static/Shapes.hs
@@ -25,27 +25,55 @@ module Data.Packed.Static.Shapes (
import qualified Numeric.LinearAlgebra as H
+-- | Uninhabited type. Represents unknown lengths.
+-- Instances of 'ShapedContainer' use 'Unknown'
+-- for the 'UnknownShape' type.
data Unknown
class ShapedContainer a where
- -- | Typed representation
+ -- | Less-typed, hmatrix representation
type Unwrapped a :: * -> *
+ -- | Convert to hmatrix representation
unWrap :: a s t -> Unwrapped a t
+ -- | Convert from hmatrix representation
wrapU :: Unwrapped a t -> a (UnknownShape a) t
-- | standard \'unknown\' shape. For vectors, @Unknown@; for matrices, @(Unknown,Unknown)@.
type UnknownShape a
+ -- | Coerce the static shape. Unsafe; the user
+ -- of this function has an obligation to prove that
+ -- the object's dynamic shape is the same as that
+ -- represented by s'.
unsafeReshape :: a s t -> a s' t
+-- | For type hints.
+--
+-- @\> constant (5::Double) `atShape` d4
+-- [$vec| 5.0, 5.0, 5.0, 5.0 |] :: Vector D4 Double@
+--
+-- Implementation:
+--
+-- @atShape = const@.
atShape :: a s t -> s -> a s t
atShape = const
+-- | For type hints.
+--
+-- @\> constant (5::Double) `atShape` shapeOf [$vec|1|]
+-- [$vec| 5.0 |]@
+--
+-- Implementation:
+--
+-- @shapeOf _ = undefined@
shapeOf :: a s t -> s
shapeOf _ = undefined
+-- | @unsafeWrap = unsafeReshape . wrapU@.
unsafeWrap :: ShapedContainer a => Unwrapped a t -> a s t
unsafeWrap = unsafeReshape . wrapU
+-- | Changes the static shape to the UnknownShape.
+-- Dynamic representation is unchanged.
forgetShapeU :: ShapedContainer a => a s t -> a (UnknownShape a) t
forgetShapeU = unsafeReshape
View
4 hmatrix-static.cabal
@@ -18,6 +18,10 @@ Description: A thin, lightweight wrapper over hmatrix to support
of hmatrix. This is cheap in comparison to representing
unknown sizes with exisential types, which forces pervasive
continuation passing style.
+ .
+ WARNING: when using the QuasiQuoting in this package,
+ be aware of infix expressions. See the note in
+ "Data.Packed.Static.Syntax" for details.
Category: Math
Tested-with: GHC == 6.10.1
Cabal-Version: >= 1.6
Please sign in to comment.
Something went wrong with that request. Please try again.