Safe Haskell | None |
---|---|
Language | Haskell2010 |
Arrays of dynamic size. The arrays are polymorphic in the underlying linear data structure used to store the actual values.
Synopsis
- data Array v a = A !ShapeL !(T v a)
- class Vector v
- type family VecElem v :: Type -> Constraint
- size :: Array v a -> Int
- shapeL :: Array v a -> ShapeL
- rank :: Array v a -> Int
- toList :: (Vector v, VecElem v a) => Array v a -> [a]
- fromList :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> [a] -> Array v a
- toVector :: (Vector v, VecElem v a) => Array v a -> v a
- fromVector :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> v a -> Array v a
- normalize :: (Vector v, VecElem v a) => Array v a -> Array v a
- scalar :: (Vector v, VecElem v a) => a -> Array v a
- unScalar :: (HasCallStack, Vector v, VecElem v a) => Array v a -> a
- constant :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> a -> Array v a
- reshape :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> Array v a -> Array v a
- stretch :: HasCallStack => ShapeL -> Array v a -> Array v a
- stretchOuter :: HasCallStack => Int -> Array v a -> Array v a
- transpose :: HasCallStack => [Int] -> Array v a -> Array v a
- index :: (HasCallStack, Vector v) => Array v a -> Int -> Array v a
- pad :: forall a v. (Vector v, VecElem v a) => [(Int, Int)] -> a -> Array v a -> Array v a
- mapA :: (Vector v, VecElem v a, VecElem v b) => (a -> b) -> Array v a -> Array v b
- zipWithA :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c) => (a -> b -> c) -> Array v a -> Array v b -> Array v c
- zipWith3A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d) => (a -> b -> c -> d) -> Array v a -> Array v b -> Array v c -> Array v d
- zipWith4A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d, VecElem v e) => (a -> b -> c -> d -> e) -> Array v a -> Array v b -> Array v c -> Array v d -> Array v e
- zipWith5A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d, VecElem v e, VecElem v f) => (a -> b -> c -> d -> e -> f) -> Array v a -> Array v b -> Array v c -> Array v d -> Array v e -> Array v f
- append :: (HasCallStack, Vector v, VecElem v a) => Array v a -> Array v a -> Array v a
- concatOuter :: (HasCallStack, Vector v, VecElem v a) => [Array v a] -> Array v a
- ravel :: (HasCallStack, Vector v, Vector v', VecElem v a, VecElem v' (Array v a)) => Array v' (Array v a) -> Array v a
- unravel :: (Vector v, Vector v', VecElem v a, VecElem v' (Array v a)) => Array v a -> Array v' (Array v a)
- window :: (HasCallStack, Vector v) => [Int] -> Array v a -> Array v a
- stride :: (HasCallStack, Vector v) => [Int] -> Array v a -> Array v a
- rotate :: (HasCallStack, Vector v, VecElem v a) => Int -> Int -> Array v a -> Array v a
- slice :: HasCallStack => [(Int, Int)] -> Array v a -> Array v a
- rerank :: (HasCallStack, Vector v, Vector v', VecElem v a, VecElem v' b) => Int -> (Array v a -> Array v' b) -> Array v a -> Array v' b
- rerank2 :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c) => Int -> (Array v a -> Array v b -> Array v c) -> Array v a -> Array v b -> Array v c
- rev :: HasCallStack => [Int] -> Array v a -> Array v a
- reduce :: (Vector v, VecElem v a) => (a -> a -> a) -> a -> Array v a -> Array v a
- foldrA :: (Vector v, VecElem v a) => (a -> b -> b) -> b -> Array v a -> b
- traverseA :: (Vector v, VecElem v a, VecElem v b, Applicative f) => (a -> f b) -> Array v a -> f (Array v b)
- allSameA :: (Vector v, VecElem v a, Eq a) => Array v a -> Bool
- sumA :: (Vector v, VecElem v a, Num a) => Array v a -> a
- productA :: (Vector v, VecElem v a, Num a) => Array v a -> a
- maximumA :: (HasCallStack, Vector v, VecElem v a, Ord a) => Array v a -> a
- minimumA :: (HasCallStack, Vector v, VecElem v a, Ord a) => Array v a -> a
- anyA :: (Vector v, VecElem v a) => (a -> Bool) -> Array v a -> Bool
- allA :: (Vector v, VecElem v a) => (a -> Bool) -> Array v a -> Bool
- broadcast :: (HasCallStack, Vector v, VecElem v a) => [Int] -> ShapeL -> Array v a -> Array v a
- update :: (HasCallStack, Vector v, VecElem v a) => Array v a -> [([Int], a)] -> Array v a
- generate :: (Vector v, VecElem v a) => ShapeL -> ([Int] -> a) -> Array v a
- iterateN :: forall v a. (Vector v, VecElem v a) => Int -> (a -> a) -> a -> Array v a
- iota :: forall v a. (Vector v, VecElem v a, Enum a, Num a) => Int -> Array v a
Documentation
Arrays stored in a v with values of type a.
Instances
a ~ b => Convert (Array a) (Array Vector b) Source # | |
a ~ b => Convert (Array a) (Array Vector b) Source # | |
a ~ b => Convert (Array a) (Array Vector b) Source # | |
(Vector v, Eq a, VecElem v a, Eq (v a)) => Eq (Array v a) Source # | |
(Typeable v, Typeable a, Data (v a)) => Data (Array v a) Source # | |
Defined in Data.Array.Internal.DynamicG gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Array v a -> c (Array v a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Array v a) # toConstr :: Array v a -> Constr # dataTypeOf :: Array v a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Array v a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Array v a)) # gmapT :: (forall b. Data b => b -> b) -> Array v a -> Array v a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Array v a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Array v a -> r # gmapQ :: (forall d. Data d => d -> u) -> Array v a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Array v a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Array v a -> m (Array v a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Array v a -> m (Array v a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Array v a -> m (Array v a) # | |
(Vector v, Ord a, Ord (v a), VecElem v a) => Ord (Array v a) Source # | |
Defined in Data.Array.Internal.DynamicG | |
(Vector v, Read a, VecElem v a) => Read (Array v a) Source # | |
(Vector v, Show a, VecElem v a) => Show (Array v a) Source # | |
Generic (Array v a) Source # | |
(Vector v, VecElem v a, Arbitrary a) => Arbitrary (Array v a) Source # | |
NFData (v a) => NFData (Array v a) Source # | |
Defined in Data.Array.Internal.DynamicG | |
(Vector v, Pretty a, VecElem v a) => Pretty (Array v a) Source # | |
Defined in Data.Array.Internal.DynamicG pPrintPrec :: PrettyLevel -> Rational -> Array v a -> Doc # pPrintList :: PrettyLevel -> [Array v a] -> Doc # | |
type Rep (Array v a) Source # | |
Defined in Data.Array.Internal.DynamicG type Rep (Array v a) = D1 ('MetaData "Array" "Data.Array.Internal.DynamicG" "orthotope-0.1.1.0-8N9XOymS4o4K1BvtpFJxFr" 'False) (C1 ('MetaCons "A" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ShapeL) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (T v a)))) |
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
type family VecElem v :: Type -> Constraint Source #
Instances
type VecElem [] Source # | |
Defined in Data.Array.Internal | |
type VecElem Vector Source # | |
Defined in Data.Array.Internal.DynamicU | |
type VecElem Vector Source # | |
Defined in Data.Array.Internal.DynamicS | |
type VecElem Vector Source # | |
Defined in Data.Array.Internal.Dynamic |
shapeL :: Array v 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 :: Array v a -> Int Source #
The rank of an array, i.e., the number if dimensions it has. O(1) time.
toList :: (Vector v, VecElem v a) => Array v a -> [a] Source #
Convert to a list with the elements in the linearization order. O(n) time.
fromList :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> [a] -> Array v 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 :: (Vector v, VecElem v a) => Array v a -> v 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 :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> v a -> Array v 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 :: (Vector v, VecElem v a) => Array v a -> Array v 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.
scalar :: (Vector v, VecElem v a) => a -> Array v a Source #
Convert a value to a scalar (rank 0) array. O(1) time.
unScalar :: (HasCallStack, Vector v, VecElem v a) => Array v a -> a Source #
Convert a scalar (rank 0) array to a value. O(1) time.
constant :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> a -> Array v a Source #
Make an array with all elements having the same value. O(1) time
reshape :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> Array v a -> Array v a Source #
Change the shape of an array. Fails if the arrays have different number of elements. O(n) or O(1) time.
stretch :: HasCallStack => ShapeL -> Array v a -> Array v 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 :: HasCallStack => Int -> Array v a -> Array v a Source #
Change the size of the outermost dimension by replication.
transpose :: HasCallStack => [Int] -> Array v a -> Array v 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, Vector v) => Array v a -> Int -> Array v a Source #
Index into an array. Fails if the array has rank 0 or if the index is out of bounds. O(1) time.
pad :: forall a v. (Vector v, VecElem v a) => [(Int, Int)] -> a -> Array v a -> Array v a Source #
Pad each dimension on the low and high side with the given value. O(n) time.
mapA :: (Vector v, VecElem v a, VecElem v b) => (a -> b) -> Array v a -> Array v b Source #
Map over the array elements. O(n) time.
zipWithA :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c) => (a -> b -> c) -> Array v a -> Array v b -> Array v c Source #
Map over the array elements. O(n) time.
zipWith3A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d) => (a -> b -> c -> d) -> Array v a -> Array v b -> Array v c -> Array v d Source #
Map over the array elements. O(n) time.
zipWith4A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d, VecElem v e) => (a -> b -> c -> d -> e) -> Array v a -> Array v b -> Array v c -> Array v d -> Array v e Source #
Map over the array elements. O(n) time.
zipWith5A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d, VecElem v e, VecElem v f) => (a -> b -> c -> d -> e -> f) -> Array v a -> Array v b -> Array v c -> Array v d -> Array v e -> Array v f Source #
Map over the array elements. O(n) time.
append :: (HasCallStack, Vector v, VecElem v a) => Array v a -> Array v a -> Array v a Source #
Append two arrays along the outermost dimension. All dimensions, except the outermost, must be the same. O(n) time.
concatOuter :: (HasCallStack, Vector v, VecElem v a) => [Array v a] -> Array v a Source #
Concatenate a number of arrays into a single array. Fails if any, but the outer, dimensions differ. O(n) time.
ravel :: (HasCallStack, Vector v, Vector v', VecElem v a, VecElem v' (Array v a)) => Array v' (Array v a) -> Array v 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 :: (Vector v, Vector v', VecElem v a, VecElem v' (Array v a)) => Array v a -> Array v' (Array v a) Source #
Turn an array into a nested array, this is the inverse of ravel
.
I.e., ravel . unravel == id
.
window :: (HasCallStack, Vector v) => [Int] -> Array v a -> Array v 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]
.
E.g., window [2] (fromList [4] [1,2,3,4]) == fromList [3,2] [1,2, 2,3, 3,4]
O(1) time.
If the window parameter ws = [w1,...,wk]
and wa = window ws a
then
wa
.index
i1 ... index
ik == slice [(i1,w1),...,(ik,wk)] a
stride :: (HasCallStack, Vector v) => [Int] -> Array v a -> Array v 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]
.
The rank of the stride list must not exceed the rank of the array.
O(1) time.
rotate :: (HasCallStack, Vector v, VecElem v a) => Int -> Int -> Array v a -> Array v a Source #
Rotate the array k times along the d'th dimension.
E.g., if the array shape is [2, 3, 2]
, d is 1, and k is 4,
the resulting shape will be [2, 4, 3, 2]
.
slice :: HasCallStack => [(Int, Int)] -> Array v a -> Array v 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 arrar.
The extracted slice mul fall within the array dimensions.
E.g. slice [1,2] (fromList [4] [1,2,3,4]) == [2,3]
.
O(1) time.
rerank :: (HasCallStack, Vector v, Vector v', VecElem v a, VecElem v' b) => Int -> (Array v a -> Array v' b) -> Array v a -> Array v' 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 :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c) => Int -> (Array v a -> Array v b -> Array v c) -> Array v a -> Array v b -> Array v 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 :: HasCallStack => [Int] -> Array v a -> Array v a Source #
Reverse the given dimensions, with the outermost being dimension 0. O(1) time.
foldrA :: (Vector v, VecElem v a) => (a -> b -> b) -> b -> Array v a -> b Source #
Right fold across all elements of an array.
traverseA :: (Vector v, VecElem v a, VecElem v b, Applicative f) => (a -> f b) -> Array v a -> f (Array v b) Source #
allSameA :: (Vector v, VecElem v a, Eq a) => Array v a -> Bool Source #
Check if all elements of the array are equal.
maximumA :: (HasCallStack, Vector v, VecElem v a, Ord a) => Array v a -> a Source #
Maximum of all elements.
minimumA :: (HasCallStack, Vector v, VecElem v a, Ord a) => Array v a -> a Source #
Minimum of all elements.
anyA :: (Vector v, VecElem v a) => (a -> Bool) -> Array v a -> Bool Source #
Test if the predicate holds for any element.
allA :: (Vector v, VecElem v a) => (a -> Bool) -> Array v a -> Bool Source #
Test if the predicate holds for all elements.
broadcast :: (HasCallStack, Vector v, VecElem v a) => [Int] -> ShapeL -> Array v a -> Array v 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.
update :: (HasCallStack, Vector v, VecElem v a) => Array v a -> [([Int], a)] -> Array v a Source #
Update the array at the specified indicies to the associated value.
generate :: (Vector v, VecElem v a) => ShapeL -> ([Int] -> a) -> Array v a Source #
Generate an array with a function that computes the value for each index.