Safe Haskell | None |
---|---|
Language | Haskell2010 |
NumHask.Matrix
Contents
Description
Two-dimensional arrays. Two classes are supplied
Matrix
where shape information is held at type level, andSomeMatrix
where shape is held at the value level.
In both cases, the underlying data is contained as a flat vector for efficiency purposes.
- newtype Matrix m n a = Matrix {
- flattenMatrix :: Vector a
- data SomeMatrix a = SomeMatrix (Int, Int) (Vector a)
- newtype ShapeM = ShapeM {}
- someMatrix :: (KnownNat m, KnownNat n) => Matrix (m :: Nat) (n :: Nat) a -> SomeMatrix a
- unsafeToMatrix :: SomeMatrix a -> Matrix (m :: Nat) (n :: Nat) a
- toMatrix :: forall a m n. (KnownNat m, KnownNat n) => SomeMatrix a -> Maybe (Matrix (m :: Nat) (n :: Nat) a)
- unsafeFromVV :: forall a m n. Vector m (Vector n a) -> Matrix m n a
- toCol :: forall a n. Vector n a -> Matrix 1 n a
- toRow :: forall a m. Vector m a -> Matrix m 1 a
- fromCol :: forall a n. Matrix 1 n a -> Vector n a
- fromRow :: forall a m. Matrix m 1 a -> Vector m a
- col :: forall a m n. (KnownNat m, KnownNat n) => Int -> Matrix m n a -> Vector m a
- row :: forall a m n. (KnownNat m, KnownNat n) => Int -> Matrix m n a -> Vector n a
- mmult :: forall m n k a. (CRing a, KnownNat m, KnownNat n, KnownNat k) => Matrix m k a -> Matrix k n a -> Matrix m n a
Documentation
a two-dimensional array where shape is specified at the type level
The main purpose of this, beyond safe typing, is to supply the Representable instance with an initial object.
A single Boxed Vector
is used underneath for efficient slicing, but this may change or become polymorphic in the future.
Constructors
Matrix | |
Fields
|
Instances
Functor (Matrix k1 k m n) Source # | |
Foldable (Matrix k1 k m n) Source # | |
(KnownNat m, KnownNat n) => Distributive (Matrix Nat Nat m n) Source # | |
(KnownNat m, KnownNat n) => Representable (Matrix Nat Nat m n) Source # | |
(KnownNat m, KnownNat n) => Naperian (Matrix Nat Nat m n) Source # | |
(KnownNat m, KnownNat n) => HasShape (Matrix Nat Nat m n) Source # | |
(KnownNat m, KnownNat n, AdditiveUnital a) => IsList (Matrix Nat Nat m n a) Source # | from flat list |
Eq a => Eq (Matrix k1 k m n a) Source # | |
(Show a, KnownNat m, KnownNat n) => Show (Matrix Nat Nat m n a) Source # | |
(KnownNat m, KnownNat n, Arbitrary a, AdditiveUnital a) => Arbitrary (Matrix Nat Nat m n a) Source # | |
type Rep (Matrix Nat Nat m n) Source # | |
type Shape (Matrix Nat Nat m n) Source # | |
type Item (Matrix Nat Nat m n a) Source # | |
data SomeMatrix a Source #
a two-dimensional array where shape is specified at the value level as a '(Int,Int)'
Use this to avoid type-level hasochism by demoting a Matrix
with someMatrix
Constructors
SomeMatrix (Int, Int) (Vector a) |
Instances
Functor SomeMatrix Source # | |
Foldable SomeMatrix Source # | |
HasShape SomeMatrix Source # | |
IsList (SomeMatrix a) Source # | from nested list |
Eq a => Eq (SomeMatrix a) Source # | |
Show a => Show (SomeMatrix a) Source # | |
Arbitrary a => Arbitrary (SomeMatrix a) Source # | |
type Shape SomeMatrix Source # | |
type Item (SomeMatrix a) Source # | |
just used to get sensible arbitrary instances of SomeMatrix
Conversion
someMatrix :: (KnownNat m, KnownNat n) => Matrix (m :: Nat) (n :: Nat) a -> SomeMatrix a Source #
convert from a Matrix
to a SomeMatrix
unsafeToMatrix :: SomeMatrix a -> Matrix (m :: Nat) (n :: Nat) a Source #
convert from a SomeMatrix
to a Matrix
with no shape check
toMatrix :: forall a m n. (KnownNat m, KnownNat n) => SomeMatrix a -> Maybe (Matrix (m :: Nat) (n :: Nat) a) Source #
convert from a SomeMatrix
to a Matrix
, checking shape
unsafeFromVV :: forall a m n. Vector m (Vector n a) -> Matrix m n a Source #
conversion from a double Vector representation