Safe Haskell | None |
---|---|
Language | Haskell2010 |
N-dimensional arrays. Two classes are supplied:
Tensor
where shape information is held at type level, andSomeTensor
where shape is held at the value level.
In both cases, the underlying data is contained as a flat vector for efficiency purposes.
- newtype Tensor r a = Tensor {
- flattenTensor :: Vector a
- data SomeTensor a = SomeTensor [Int] (Vector a)
- someTensor :: SingI r => Tensor (r :: [Nat]) a -> SomeTensor a
- unsafeToTensor :: SomeTensor a -> Tensor (r :: [Nat]) a
- toTensor :: forall a r. SingI r => SomeTensor a -> Maybe (Tensor (r :: [Nat]) a)
- flatten1 :: SomeTensor a -> [SomeTensor a]
Documentation
an n-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.
Tensor | |
|
Functor (Tensor k r) Source # | |
Foldable (Tensor k r) Source # | |
SingI [Nat] r => Distributive (Tensor [Nat] r) Source # | |
SingI [Nat] r => Representable (Tensor [Nat] r) Source # | |
SingI [Nat] r => Naperian (Tensor [Nat] r) Source # | |
SingI [Nat] r => HasShape (Tensor [Nat] r) Source # | |
(SingI [Nat] r, AdditiveUnital a) => IsList (Tensor [Nat] r a) Source # | from flat list |
Eq a => Eq (Tensor k r a) Source # | |
(Show a, SingI [Nat] r) => Show (Tensor [Nat] r a) Source # | |
(SingI [Nat] r, Arbitrary a, AdditiveUnital a) => Arbitrary (Tensor [Nat] r a) Source # | |
type Rep (Tensor [Nat] r) Source # | |
type Shape (Tensor [Nat] r) Source # | |
type Item (Tensor [Nat] r a) Source # | |
data SomeTensor a Source #
an n-dimensional array where shape is specified at the value level as an '[Int]'
Use this to avoid type-level hasochism by demoting a Tensor
with someTensor
SomeTensor [Int] (Vector a) |
Functor SomeTensor Source # | |
Foldable SomeTensor Source # | |
HasShape SomeTensor Source # | |
Eq a => Eq (SomeTensor a) Source # | |
Show a => Show (SomeTensor a) Source # | |
(Arbitrary a, AdditiveUnital a) => Arbitrary (SomeTensor a) Source # | |
type Shape SomeTensor Source # | |
Conversion
someTensor :: SingI r => Tensor (r :: [Nat]) a -> SomeTensor a Source #
convert a Tensor
to a SomeTensor
, losing the type level shape
unsafeToTensor :: SomeTensor a -> Tensor (r :: [Nat]) a Source #
convert a SomeTensor
to a Tensor
with no checks on shape.
toTensor :: forall a r. SingI r => SomeTensor a -> Maybe (Tensor (r :: [Nat]) a) Source #
convert a SomeTensor
to a Tensor
, check for shape equality.
flatten1 :: SomeTensor a -> [SomeTensor a] Source #
convert the top layer of a SomeTensor to a [SomeTensor]