Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Array sh a = A {}
- class Typeable s => Shape (s :: [Nat]) where
- type Size (s :: [Nat]) = Size' 1 s
- type family Rank (s :: [Nat]) :: Nat where ...
- class Vector v
- type ShapeL = [Int]
- class Window (ws :: [Nat]) (ss :: [Nat]) (rs :: [Nat]) | ws ss -> rs
- class Stride (ts :: [Nat]) (ss :: [Nat]) (rs :: [Nat]) | ts ss -> rs
- type Permute (is :: [Nat]) (xs :: [Nat]) = Permute' is (Take (Rank is) xs) ++ Drop (Rank is) xs
- class Permutation (is :: [Nat])
- class ValidDims (rs :: [Nat]) (sh :: [Nat])
- size :: forall sh a. Shape sh => Array sh a -> Int
- shapeL :: Shape sh => Array sh a -> ShapeL
- rank :: (Shape sh, KnownNat (Rank sh)) => Array sh a -> Int
- toList :: forall sh a. Shape sh => Array sh a -> [a]
- fromList :: forall sh a. (HasCallStack, Shape sh) => [a] -> Array sh a
- toVector :: Shape sh => Array sh a -> Vector a
- fromVector :: forall sh a. (HasCallStack, Shape sh) => Vector a -> Array sh a
- normalize :: Shape sh => Array sh a -> Array sh a
- scalar :: a -> Array '[] a
- unScalar :: Array '[] a -> a
- constant :: forall sh a. Shape sh => a -> Array sh a
- reshape :: forall sh' sh a. (Shape sh, Shape sh', Size sh ~ Size sh') => Array sh a -> Array sh' a
- stretch :: forall sh' sh a. (Shape sh, Shape sh', ValidStretch sh sh') => Array sh a -> Array sh' a
- stretchOuter :: (KnownNat s, Shape sh) => Array (1 ': sh) a -> Array (s ': sh) a
- transpose :: forall is sh a. (Permutation is, Rank is <= Rank sh, Shape sh, Shape is, KnownNat (Rank sh)) => Array sh a -> Array (Permute is sh) a
- index :: (HasCallStack, KnownNat s) => Array (s ': sh) a -> Int -> Array sh a
- pad :: forall ps sh' sh a. (HasCallStack, Padded ps sh sh', Shape sh) => a -> Array sh a -> Array sh' a
- mapA :: Shape sh => (a -> b) -> Array sh a -> Array sh b
- zipWithA :: Shape sh => (a -> b -> c) -> Array sh a -> Array sh b -> Array sh c
- zipWith3A :: Shape sh => (a -> b -> c -> d) -> Array sh a -> Array sh b -> Array sh c -> Array sh d
- append :: (Shape sh, KnownNat m, KnownNat n, KnownNat (m + n)) => Array (m ': sh) a -> Array (n ': sh) a -> Array ((m + n) ': sh) a
- ravel :: (Shape sh, KnownNat s) => Array '[s] (Array sh a) -> Array (s ': sh) a
- unravel :: (Shape sh, KnownNat s) => Array (s ': sh) a -> Array '[s] (Array sh a)
- window :: forall ws sh' sh a. (Window ws sh sh', KnownNat (Rank ws)) => Array sh a -> Array sh' a
- stride :: forall ts sh' sh a. (Stride ts sh sh', Shape ts) => Array sh a -> Array sh' a
- slice :: forall sl sh' sh a. Slice sl sh sh' => Array sh a -> Array sh' a
- rerank :: forall n i o sh a b. (Drop n sh ~ i, Shape sh, KnownNat n, Shape o, Shape (Take n sh ++ o)) => (Array i a -> Array o b) -> Array sh a -> Array (Take n sh ++ o) b
- rerank2 :: forall n i o sh a b c. (Drop n sh ~ i, Shape sh, KnownNat n, Shape o, Shape (Take n sh ++ o)) => (Array i a -> Array i b -> Array o c) -> Array sh a -> Array sh b -> Array (Take n sh ++ o) c
- rev :: forall rs sh a. (ValidDims rs sh, Shape rs, Shape sh) => Array sh a -> Array sh a
- reduce :: Shape sh => (a -> a -> a) -> a -> Array sh a -> Array '[] a
- foldrA :: Shape sh => (a -> b -> b) -> b -> Array sh a -> b
- traverseA :: (Applicative f, Shape sh) => (a -> f b) -> Array sh a -> f (Array sh b)
- allSameA :: (Shape sh, Eq a) => Array sh a -> Bool
- sumA :: (Num a, Shape sh) => Array sh a -> a
- productA :: (Num a, Shape sh) => Array sh a -> a
- minimumA :: (Ord a, Shape sh, 1 <= Size sh) => Array sh a -> a
- maximumA :: (Ord a, Shape sh, 1 <= Size sh) => Array sh a -> a
- anyA :: Shape sh => (a -> Bool) -> Array sh a -> Bool
- allA :: Shape sh => (a -> Bool) -> Array sh a -> Bool
- broadcast :: forall ds sh' sh a. (Shape sh, Shape sh', Broadcast ds sh sh') => Array sh a -> Array sh' a
- generate :: Shape sh => ([Int] -> a) -> Array sh a
- iterateN :: forall n a. KnownNat n => (a -> a) -> a -> Array '[n] a
- iota :: (KnownNat n, Enum a, Num a) => Array '[n] a
Documentation
Instances
Shape sh => Foldable (Array sh) Source # | |
Defined in Data.Array.Internal.Shaped fold :: Monoid m => Array sh m -> m # foldMap :: Monoid m => (a -> m) -> Array sh a -> m # foldMap' :: Monoid m => (a -> m) -> Array sh a -> m # foldr :: (a -> b -> b) -> b -> Array sh a -> b # foldr' :: (a -> b -> b) -> b -> Array sh a -> b # foldl :: (b -> a -> b) -> b -> Array sh a -> b # foldl' :: (b -> a -> b) -> b -> Array sh a -> b # foldr1 :: (a -> a -> a) -> Array sh a -> a # foldl1 :: (a -> a -> a) -> Array sh a -> a # elem :: Eq a => a -> Array sh a -> Bool # maximum :: Ord a => Array sh a -> a # minimum :: Ord a => Array sh a -> a # | |
Shape sh => Traversable (Array sh) Source # | |
Shape sh => Applicative (Array sh) Source # | |
Shape sh => Functor (Array sh) Source # | |
(a ~ b, Shape sh) => Convert (Array a) (Array sh b) Source # | |
(Shape sh, Arbitrary a) => Arbitrary (Array sh a) Source # | |
(Typeable sh, Data a) => Data (Array sh a) Source # | |
Defined in Data.Array.Internal.Shaped gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Array sh a -> c (Array sh a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Array sh a) # toConstr :: Array sh a -> Constr # dataTypeOf :: Array sh a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Array sh a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Array sh a)) # gmapT :: (forall b. Data b => b -> b) -> Array sh a -> Array sh a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Array sh a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Array sh a -> r # gmapQ :: (forall d. Data d => d -> u) -> Array sh a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Array sh a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Array sh a -> m (Array sh a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Array sh a -> m (Array sh a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Array sh a -> m (Array sh a) # | |
(Shape sh, Enum a) => Enum (Array sh a) Source # | |
Defined in Data.Array.Shaped.Instances succ :: Array sh a -> Array sh a # pred :: Array sh a -> Array sh a # fromEnum :: Array sh a -> Int # enumFrom :: Array sh a -> [Array sh a] # enumFromThen :: Array sh a -> Array sh a -> [Array sh a] # enumFromTo :: Array sh a -> Array sh a -> [Array sh a] # enumFromThenTo :: Array sh a -> Array sh a -> Array sh a -> [Array sh a] # | |
(Shape sh, Floating a) => Floating (Array sh a) Source # | |
Defined in Data.Array.Shaped.Instances exp :: Array sh a -> Array sh a # log :: Array sh a -> Array sh a # sqrt :: Array sh a -> Array sh a # (**) :: Array sh a -> Array sh a -> Array sh a # logBase :: Array sh a -> Array sh a -> Array sh a # sin :: Array sh a -> Array sh a # cos :: Array sh a -> Array sh a # tan :: Array sh a -> Array sh a # asin :: Array sh a -> Array sh a # acos :: Array sh a -> Array sh a # atan :: Array sh a -> Array sh a # sinh :: Array sh a -> Array sh a # cosh :: Array sh a -> Array sh a # tanh :: Array sh a -> Array sh a # asinh :: Array sh a -> Array sh a # acosh :: Array sh a -> Array sh a # atanh :: Array sh a -> Array sh a # log1p :: Array sh a -> Array sh a # expm1 :: Array sh a -> Array sh a # | |
Generic (Array sh a) Source # | |
(Shape sh, Num a) => Num (Array sh a) Source # | |
Defined in Data.Array.Shaped.Instances | |
(Read a, Shape sh) => Read (Array sh a) Source # | |
(Shape sh, Fractional a) => Fractional (Array sh a) Source # | |
(Shape sh, Integral a) => Integral (Array sh a) Source # | |
Defined in Data.Array.Shaped.Instances quot :: Array sh a -> Array sh a -> Array sh a # rem :: Array sh a -> Array sh a -> Array sh a # div :: Array sh a -> Array sh a -> Array sh a # mod :: Array sh a -> Array sh a -> Array sh a # quotRem :: Array sh a -> Array sh a -> (Array sh a, Array sh a) # divMod :: Array sh a -> Array sh a -> (Array sh a, Array sh a) # | |
(Shape sh, Real a) => Real (Array sh a) Source # | |
Defined in Data.Array.Shaped.Instances toRational :: Array sh a -> Rational # | |
(Show a, Shape sh) => Show (Array sh a) Source # | |
NFData a => NFData (Array sh a) Source # | |
Defined in Data.Array.Internal.Shaped | |
Eq (Array sh Vector a) => Eq (Array sh a) Source # | |
Ord (Array sh Vector a) => Ord (Array sh a) Source # | |
Defined in Data.Array.Internal.Shaped | |
(Pretty a, Shape sh) => Pretty (Array sh a) Source # | |
Defined in Data.Array.Internal.Shaped pPrintPrec :: PrettyLevel -> Rational -> Array sh a -> Doc # pPrintList :: PrettyLevel -> [Array sh a] -> Doc # | |
(a ~ b, Shape sh) => Convert (Array sh a) (Array b) Source # | |
(a ~ b, Rank sh ~ n, Shape sh) => Convert (Array n a) (Array sh b) Source # | |
(a ~ b, n ~ m, Unbox a) => Convert (Array n a) (Array m b) Source # | |
(a ~ b, n ~ m, Unbox a) => Convert (Array n a) (Array m b) Source # | |
(a ~ b, Rank sh ~ n, Shape sh) => Convert (Array sh a) (Array n b) Source # | |
(a ~ b, n ~ m, Unbox a) => Convert (Array n a) (Array m b) Source # | |
(a ~ b, n ~ m, Unbox a) => Convert (Array n a) (Array m b) Source # | |
(a ~ b, s ~ t) => Convert (Array s a) (Array t Vector b) Source # | |
type Rep (Array sh a) Source # | |
Defined in Data.Array.Internal.Shaped |
type Size (s :: [Nat]) = Size' 1 s Source #
Compute the size, i.e., total number of elements of a type level shape.
type family Rank (s :: [Nat]) :: Nat where ... Source #
Compute the rank, i.e., length of a type level shape.
The Vector
class is the interface to the underlying storage for the arrays.
The operations map straight to operations for Vector
.
vIndex, vLength, vToList, vFromList, vSingleton, vReplicate, vMap, vZipWith, vZipWith3, vZipWith4, vZipWith5, vAppend, vConcat, vFold, vSlice, vSum, vProduct, vMaximum, vMinimum, vUpdate, vGenerate, vAll, vAny
Instances
class Window (ws :: [Nat]) (ss :: [Nat]) (rs :: [Nat]) | ws ss -> rs Source #
Instances
Window' ws ws ss rs => Window ws ss rs Source # | |
Defined in Data.Array.Internal.Shape |
class Stride (ts :: [Nat]) (ss :: [Nat]) (rs :: [Nat]) | ts ss -> rs Source #
Instances
Stride ('[] :: [Nat]) ss ss Source # | |
Defined in Data.Array.Internal.Shape | |
(Stride ts ss rs, DivRoundUp s t ~ r) => Stride (t ': ts) (s ': ss) (r ': rs) Source # | |
Defined in Data.Array.Internal.Shape |
type Permute (is :: [Nat]) (xs :: [Nat]) = Permute' is (Take (Rank is) xs) ++ Drop (Rank is) xs Source #
class Permutation (is :: [Nat]) Source #
Instances
AllElem is (Count 0 is) => Permutation is Source # | |
Defined in Data.Array.Internal.Shape |
shapeL :: Shape sh => Array sh a -> ShapeL Source #
The shape of an array, i.e., a list of the sizes of its dimensions. In the linearization of the array the outermost (i.e. first list element) varies most slowly. O(1) time.
rank :: (Shape sh, KnownNat (Rank sh)) => Array sh a -> Int Source #
The rank of an array, i.e., the number of dimensions it has,
which is the n
in Array n a
.
O(1) time.
toList :: forall sh a. Shape sh => Array sh a -> [a] Source #
Convert to a list with the elements in the linearization order. O(n) time.
fromList :: forall sh a. (HasCallStack, Shape sh) => [a] -> Array sh a Source #
Convert from a list with the elements given in the linearization order. Fails if the given shape does not have the same number of elements as the list. O(n) time.
toVector :: Shape sh => Array sh a -> Vector a Source #
Convert to a vector with the elements in the linearization order. O(n) or O(1) time (the latter if the vector is already in the linearization order).
fromVector :: forall sh a. (HasCallStack, Shape sh) => Vector a -> Array sh a Source #
Convert from a vector with the elements given in the linearization order. Fails if the given shape does not have the same number of elements as the list. O(1) time.
normalize :: Shape sh => Array sh a -> Array sh a Source #
Make sure the underlying vector is in the linearization order. This is semantically an identity function, but can have big performance implications. O(n) or O(1) time.
constant :: forall sh a. Shape sh => a -> Array sh a Source #
Make an array with all elements having the same value. O(1) time.
reshape :: forall sh' sh a. (Shape sh, Shape sh', Size sh ~ Size sh') => Array sh a -> Array sh' a Source #
Change the shape of an array. Fails if the arrays have different number of elements. O(n) or O(1) time.
stretch :: forall sh' sh a. (Shape sh, Shape sh', ValidStretch sh sh') => Array sh a -> Array sh' a Source #
Change the size of dimensions with size 1. These dimension can be changed to any size. All other dimensions must remain the same. O(1) time.
stretchOuter :: (KnownNat s, Shape sh) => Array (1 ': sh) a -> Array (s ': sh) a Source #
Change the size of the outermost dimension by replication.
transpose :: forall is sh a. (Permutation is, Rank is <= Rank sh, Shape sh, Shape is, KnownNat (Rank sh)) => Array sh a -> Array (Permute is sh) a Source #
Do an arbitrary array transposition. Fails if the transposition argument is not a permutation of the numbers [0..r-1], where r is the rank of the array. O(1) time.
index :: (HasCallStack, KnownNat s) => Array (s ': sh) a -> Int -> Array sh a Source #
Index into an array. Fails if the index is out of bounds. O(1) time.
pad :: forall ps sh' sh a. (HasCallStack, Padded ps sh sh', Shape sh) => a -> Array sh a -> Array sh' a Source #
Pad each dimension on the low and high side with the given value. O(n) time.
mapA :: Shape sh => (a -> b) -> Array sh a -> Array sh b Source #
Map over the array elements. O(n) time.
zipWithA :: Shape sh => (a -> b -> c) -> Array sh a -> Array sh b -> Array sh c Source #
Map over the array elements. O(n) time.
zipWith3A :: Shape sh => (a -> b -> c -> d) -> Array sh a -> Array sh b -> Array sh c -> Array sh d Source #
Map over the array elements. O(n) time.
append :: (Shape sh, KnownNat m, KnownNat n, KnownNat (m + n)) => Array (m ': sh) a -> Array (n ': sh) a -> Array ((m + n) ': sh) a Source #
Append two arrays along the outermost dimension. All dimensions, except the outermost, must be the same. O(n) time.
ravel :: (Shape sh, KnownNat s) => Array '[s] (Array sh a) -> Array (s ': sh) a Source #
Turn a rank-1 array of arrays into a single array by making the outer array into the outermost dimension of the result array. All the arrays must have the same shape. O(n) time.
unravel :: (Shape sh, KnownNat s) => Array (s ': sh) a -> Array '[s] (Array sh a) Source #
Turn an array into a nested array, this is the inverse of ravel
.
I.e., ravel . unravel == id
.
window :: forall ws sh' sh a. (Window ws sh sh', KnownNat (Rank ws)) => Array sh a -> Array sh' a Source #
Make a window of the outermost dimensions.
The rank increases with the length of the window list.
E.g., if the shape of the array is [10,12,8]
and
the window size is [3,3]
then the resulting array will have shape
[8,10,3,3,8]
.
O(1) time.
stride :: forall ts sh' sh a. (Stride ts sh sh', Shape ts) => Array sh a -> Array sh' a Source #
Stride the outermost dimensions.
E.g., if the array shape is [10,12,8]
and the strides are
[2,2]
then the resulting shape will be [5,6,8]
.
O(1) time.
slice :: forall sl sh' sh a. Slice sl sh sh' => Array sh a -> Array sh' a Source #
Extract a slice of an array.
The first argument is a list of (offset, length) pairs.
The length of the slicing argument must not exceed the rank of the array.
The extracted slice must fall within the array dimensions.
E.g. slice [1,2] (fromList [4] [1,2,3,4]) == [2,3]
.
O(1) time.
rerank :: forall n i o sh a b. (Drop n sh ~ i, Shape sh, KnownNat n, Shape o, Shape (Take n sh ++ o)) => (Array i a -> Array o b) -> Array sh a -> Array (Take n sh ++ o) b Source #
Apply a function to the subarrays n levels down and make the results into an array with the same n outermost dimensions. The n must not exceed the rank of the array. O(n) time.
rerank2 :: forall n i o sh a b c. (Drop n sh ~ i, Shape sh, KnownNat n, Shape o, Shape (Take n sh ++ o)) => (Array i a -> Array i b -> Array o c) -> Array sh a -> Array sh b -> Array (Take n sh ++ o) c Source #
Apply a two-argument function to the subarrays n levels down and make the results into an array with the same n outermost dimensions. The n must not exceed the rank of the array. O(n) time.
rev :: forall rs sh a. (ValidDims rs sh, Shape rs, Shape sh) => Array sh a -> Array sh a Source #
Reverse the given dimensions, with the outermost being dimension 0. O(1) time.
foldrA :: Shape sh => (a -> b -> b) -> b -> Array sh a -> b Source #
Constrained version of foldr
for Arrays.
Note that this Array
actually has Traversable
anyway.
traverseA :: (Applicative f, Shape sh) => (a -> f b) -> Array sh a -> f (Array sh b) Source #
Constrained version of traverse
for Arrays.
Note that this Array
actually has Traversable
anyway.
allSameA :: (Shape sh, Eq a) => Array sh a -> Bool Source #
Check if all elements of the array are equal.
anyA :: Shape sh => (a -> Bool) -> Array sh a -> Bool Source #
Test if the predicate holds for any element.
allA :: Shape sh => (a -> Bool) -> Array sh a -> Bool Source #
Test if the predicate holds for all elements.
broadcast :: forall ds sh' sh a. (Shape sh, Shape sh', Broadcast ds sh sh') => Array sh a -> Array sh' a Source #
Put the dimensions of the argument into the specified dimensions, and just replicate the data along all other dimensions. The list of dimensions indicies must have the same rank as the argument array and it must be strictly ascending.
generate :: Shape sh => ([Int] -> a) -> Array sh a Source #
Generate an array with a function that computes the value for each index.