Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Synopsis
- data Array sh a
- shape :: Array sh a -> sh
- reshape :: (C sh0, C sh1) => sh1 -> Array sh0 a -> Array sh1 a
- mapShape :: (C sh0, C sh1) => (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
- accessMaybe :: (Indexed sh, Storable a) => Array sh a -> Index sh -> Maybe a
- (!) :: (Indexed sh, Storable a) => Array sh a -> Index sh -> a
- toList :: (C sh, Storable a) => Array sh a -> [a]
- vectorFromList :: Storable a => [a] -> Array (ZeroBased Int) a
- toAssociations :: (Indexed sh, Storable a) => Array sh a -> [(Index sh, a)]
- fromList :: (C sh, Storable a) => sh -> [a] -> Array sh a
- fromMap :: (Ord k, Storable a) => Map k a -> Array (Set k) a
- toMap :: (Ord k, Storable a) => Array (Set k) a -> Map k a
- fromIntMap :: Storable a => IntMap a -> Array IntSet a
- toIntMap :: Storable a => Array IntSet a -> IntMap a
- fromTuple :: (NestedTuple tuple, Storable a) => DataTuple tuple a -> Array (NestedTuple ixtype tuple) a
- toTuple :: (NestedTuple tuple, Storable a) => Array (NestedTuple ixtype tuple) a -> DataTuple tuple a
- fromRecord :: (Traversable f, Storable a) => f a -> Array (Record f) a
- toRecord :: (Traversable f, Storable a) => Array (Record f) a -> f a
- fromContainer :: (C f, Storable a) => f a -> Array (Shape f) a
- toContainer :: (C f, Storable a) => Array (Shape f) a -> f a
- sample :: (Indexed sh, Storable a) => sh -> (Index sh -> a) -> Array sh a
- replicate :: (Indexed sh, Storable a) => sh -> a -> Array sh a
- fromBoxed :: (C sh, Storable a) => Array sh a -> Array sh a
- toBoxed :: (C sh, Storable a) => Array sh a -> Array sh a
- fromStorableVector :: Storable a => Vector a -> Array (ZeroBased Int) a
- toStorableVector :: (C sh, Storable a) => Array sh a -> Vector a
- fromBlockArray1 :: (Ord k, C shape, Storable a) => Array (Set k) (Array shape a) -> Array (Map k shape) a
- fromBlockArray2 :: (Ord row, C height, Eq height) => (Ord column, C width, Eq width) => Storable a => Map row height -> Map column width -> Array (Set row, Set column) (Array (height, width) a) -> Array (Map row height, Map column width) a
- fromNonEmptyBlockArray2 :: (Ord row, C height, Eq height) => (Ord column, C width, Eq width) => Storable a => Array (Set row, Set column) (Array (height, width) a) -> Array (Map row height, Map column width) a
- map :: (C sh, Storable a, Storable b) => (a -> b) -> Array sh a -> Array sh b
- mapWithIndex :: (Indexed sh, Index sh ~ ix, Storable a, Storable b) => (ix -> a -> b) -> Array sh a -> Array sh b
- zipWith :: (C sh, Eq sh, Storable a, Storable b, Storable c) => (a -> b -> c) -> Array sh a -> Array sh b -> Array sh c
- (//) :: (Indexed sh, Storable a) => Array sh a -> [(Index sh, a)] -> Array sh a
- accumulate :: (Indexed sh, Storable a) => (a -> b -> a) -> Array sh a -> [(Index sh, b)] -> Array sh a
- fromAssociations :: (Indexed sh, Storable a) => a -> sh -> [(Index sh, a)] -> Array sh a
- pick :: (Indexed sh0, C sh1, Storable a) => Array (sh0, sh1) a -> Index sh0 -> Array sh1 a
- toRowArray :: (Indexed sh0, C sh1, Storable a) => Array (sh0, sh1) a -> Array sh0 (Array sh1 a)
- fromRowArray :: (C sh0, C sh1, Eq sh1, Storable a) => sh1 -> Array sh0 (Array sh1 a) -> Array (sh0, sh1) a
- singleton :: Storable a => a -> Array () a
- append :: (C shx, C shy, Storable a) => Array shx a -> Array shy a -> Array (shx ::+ shy) a
- take :: (Integral n, Storable a) => n -> Array (ZeroBased n) a -> Array (ZeroBased n) a
- drop :: (Integral n, Storable a) => n -> Array (ZeroBased n) a -> Array (ZeroBased n) a
- takeLeft :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> Array sh0 a
- takeRight :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> Array sh1 a
- split :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> (Array sh0 a, Array sh1 a)
- takeCenter :: (C sh0, C sh1, C sh2, Storable a) => Array (sh0 ::+ (sh1 ::+ sh2)) a -> Array sh1 a
- sum :: (C sh, Storable a, Num a) => Array sh a -> a
- product :: (C sh, Storable a, Num a) => Array sh a -> a
- minimum :: (C sh, Storable a, Ord a) => Array sh a -> a
- argMinimum :: (InvIndexed sh, Storable a, Ord a) => Array sh a -> (Index sh, a)
- maximum :: (C sh, Storable a, Ord a) => Array sh a -> a
- argMaximum :: (InvIndexed sh, Storable a, Ord a) => Array sh a -> (Index sh, a)
- limits :: (C sh, Storable a, Ord a) => Array sh a -> (a, a)
- foldl :: (C sh, Storable a) => (b -> a -> b) -> b -> Array sh a -> b
- foldl1 :: (C sh, Storable a) => (a -> a -> a) -> Array sh a -> a
- foldMap :: (C sh, Storable a, Ord a, Semigroup m) => (a -> m) -> Array sh a -> m
Documentation
Instances
(AppendMonoid sh, Storable a) => Monoid (Array sh a) Source # | |
(AppendSemigroup sh, Storable a) => Semigroup (Array sh a) Source # | |
(C sh, Show sh, Storable a, Show a) => Show (Array sh a) Source # | |
NFData sh => NFData (Array sh a) Source # | |
Defined in Data.Array.Comfort.Storable.Private | |
(C sh, Eq sh, Storable a, Eq a) => Eq (Array sh a) Source # | |
fromList :: (C sh, Storable a) => sh -> [a] -> Array sh a Source #
>>>
Array.fromList (shapeInt 5) ['a'..]
StorableArray.fromList (ZeroBased {zeroBasedSize = 5}) "abcde"
fromTuple :: (NestedTuple tuple, Storable a) => DataTuple tuple a -> Array (NestedTuple ixtype tuple) a Source #
>>>
Array.fromTuple ('a',('b','c')) :: Array (Shape.NestedTuple Shape.TupleIndex (X,(X,X))) Char
StorableArray.fromList (NestedTuple {getNestedTuple = (Element 0,(Element 1,Element 2))}) "abc"
>>>
let arr :: Array (Shape.NestedTuple Shape.TupleAccessor (X,(X,X))) Char arr = Array.fromTuple ('a',('b','c')) in (arr ! fst, arr ! (fst.snd))
('a','b')
toTuple :: (NestedTuple tuple, Storable a) => Array (NestedTuple ixtype tuple) a -> DataTuple tuple a Source #
fromRecord :: (Traversable f, Storable a) => f a -> Array (Record f) a Source #
>>>
let arr = Array.fromRecord ('a' :+ 'b') in let (real:+imag) = Shape.indexRecordFromShape $ Array.shape arr in (arr ! real, arr ! imag)
('a','b')
fromBlockArray1 :: (Ord k, C shape, Storable a) => Array (Set k) (Array shape a) -> Array (Map k shape) a Source #
>>>
Array.fromBlockArray1 $ BoxedArray.fromList Set.empty [] :: Array (Map Char ShapeInt) Word16
StorableArray.fromList (fromList []) []
>>>
let block n a = Array.replicate (shapeInt n) (a::Word16) in Array.fromBlockArray1 $ BoxedArray.fromList (Set.fromList "ABC") [block 2 0, block 3 1, block 5 2]
StorableArray.fromList (fromList [('A',ZeroBased {... 2}),('B',ZeroBased {... 3}),('C',ZeroBased {... 5})]) [0,0,1,1,1,2,2,2,2,2]
fromBlockArray2 :: (Ord row, C height, Eq height) => (Ord column, C width, Eq width) => Storable a => Map row height -> Map column width -> Array (Set row, Set column) (Array (height, width) a) -> Array (Map row height, Map column width) a Source #
Explicit parameters for the shape of the result matrix allow for working with arrays of zero rows or columns.
>>>
(id :: Id (array (height, Map Char ShapeInt) Word16)) $ Array.fromBlockArray2 (Map.singleton 'A' (shapeInt 2) <> Map.singleton 'B' (shapeInt 3)) Map.empty $ BoxedArray.fromList (Set.fromList "AB", Set.empty) []
StorableArray.fromList (fromList [('A',ZeroBased {... 2}),('B',ZeroBased {... 3})],fromList []) []
QC.forAll genArray2 $ \block -> let height = Map.singleton 'A' $ fst $ Array.shape block in let width = Map.singleton '1' $ snd $ Array.shape block in Array.reshape (height,width) block QC.=== Array.fromBlockArray2 height width (BoxedArray.replicate (Set.singleton 'A', Set.singleton '1') block)
fromNonEmptyBlockArray2 :: (Ord row, C height, Eq height) => (Ord column, C width, Eq width) => Storable a => Array (Set row, Set column) (Array (height, width) a) -> Array (Map row height, Map column width) a Source #
Only the outer BoxedArray
need to be non-empty.
>>>
let shapeR0 = shapeInt 2; shapeR1 = shapeInt 3 in let shapeC0 = shapeInt 3; shapeC1 = shapeInt 2 in let block sh a = Array.replicate sh (a::Word16) in Array.fromBlockArray2 (Map.singleton 'A' shapeR0 <> Map.singleton 'B' shapeR1) (Map.singleton '1' shapeC0 <> Map.singleton '2' shapeC1) $ BoxedArray.fromList (Set.fromList "AB", Set.fromList "12") [block (shapeR0,shapeC0) 0, block (shapeR0,shapeC1) 1, block (shapeR1,shapeC0) 2, block (shapeR1,shapeC1) 3]
StorableArray.fromList (fromList [('A',ZeroBased {... 2}),('B',ZeroBased {... 3})],fromList [('1',ZeroBased {... 3}),('2',ZeroBased {... 2})]) [0,0,0,1,1,0,0,0,1,1,2,2,2,3,3,2,2,2,3,3,2,2,2,3,3]
QC.forAll genArray2 $ \blockA1 -> QC.forAll genArray2 $ \blockB2 -> let shapeR0 = fst $ Array.shape blockA1 in let shapeC0 = snd $ Array.shape blockA1 in let shapeR1 = fst $ Array.shape blockB2 in let shapeC1 = snd $ Array.shape blockB2 in QC.forAll (genArrayForShape (shapeR0, shapeC1)) $ \blockA2 -> QC.forAll (genArrayForShape (shapeR1, shapeC0)) $ \blockB1 -> let blocked = BoxedArray.fromList (Set.fromList "AB", Set.fromList "12") [blockA1, blockA2, blockB1, blockB2] in transpose (Array.fromNonEmptyBlockArray2 blocked) QC.=== Array.fromNonEmptyBlockArray2 (TestBoxedArray.transpose (fmap transpose blocked))
QC.forAll genArray2 $ \blockA1 -> QC.forAll genArray2 $ \blockB2 -> QC.forAll genArray2 $ \blockC3 -> let shapeR0 = fst $ Array.shape blockA1 in let shapeC0 = snd $ Array.shape blockA1 in let shapeR1 = fst $ Array.shape blockB2 in let shapeC1 = snd $ Array.shape blockB2 in let shapeR2 = fst $ Array.shape blockC3 in let shapeC2 = snd $ Array.shape blockC3 in QC.forAll (genArrayForShape (shapeR0, shapeC1)) $ \blockA2 -> QC.forAll (genArrayForShape (shapeR0, shapeC2)) $ \blockA3 -> QC.forAll (genArrayForShape (shapeR1, shapeC0)) $ \blockB1 -> QC.forAll (genArrayForShape (shapeR1, shapeC2)) $ \blockB3 -> QC.forAll (genArrayForShape (shapeR2, shapeC0)) $ \blockC1 -> QC.forAll (genArrayForShape (shapeR2, shapeC1)) $ \blockC2 -> let blocked = BoxedArray.fromList (Set.fromList "ABC", Set.fromList "123") [blockA1, blockA2, blockA3, blockB1, blockB2, blockB3, blockC1, blockC2, blockC3] in transpose (Array.fromNonEmptyBlockArray2 blocked) QC.=== Array.fromNonEmptyBlockArray2 (TestBoxedArray.transpose (fmap transpose blocked))
mapWithIndex :: (Indexed sh, Index sh ~ ix, Storable a, Storable b) => (ix -> a -> b) -> Array sh a -> Array sh b Source #
zipWith :: (C sh, Eq sh, Storable a, Storable b, Storable c) => (a -> b -> c) -> Array sh a -> Array sh b -> Array sh c Source #
accumulate :: (Indexed sh, Storable a) => (a -> b -> a) -> Array sh a -> [(Index sh, b)] -> Array sh a Source #
pick :: (Indexed sh0, C sh1, Storable a) => Array (sh0, sh1) a -> Index sh0 -> Array sh1 a Source #
QC.forAll genNonEmptyArray2 $ \xs -> QC.forAll (QC.elements $ Shape.indices $ Array.shape xs) $ \(ix0,ix1) -> Array.pick xs ix0 ! ix1 == xs!(ix0,ix1)
toRowArray :: (Indexed sh0, C sh1, Storable a) => Array (sh0, sh1) a -> Array sh0 (Array sh1 a) Source #
fromRowArray :: (C sh0, C sh1, Eq sh1, Storable a) => sh1 -> Array sh0 (Array sh1 a) -> Array (sh0, sh1) a Source #
It is a checked error if a row width differs from the result array width.
QC.forAll genArray2 $ \xs -> xs == Array.fromRowArray (snd $ Array.shape xs) (Array.toRowArray xs)
append :: (C shx, C shy, Storable a) => Array shx a -> Array shy a -> Array (shx ::+ shy) a infixr 5 Source #
take :: (Integral n, Storable a) => n -> Array (ZeroBased n) a -> Array (ZeroBased n) a Source #
\(QC.NonNegative n) (Array16 x) -> x == Array.mapShape (Shape.ZeroBased . Shape.size) (Array.append (Array.take n x) (Array.drop n x))
drop :: (Integral n, Storable a) => n -> Array (ZeroBased n) a -> Array (ZeroBased n) a Source #
\(QC.NonNegative n) (Array16 x) -> x == Array.mapShape (Shape.ZeroBased . Shape.size) (Array.append (Array.take n x) (Array.drop n x))
takeLeft :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> Array sh0 a Source #
\(Array16 x) (Array16 y) -> let xy = Array.append x y in x == Array.takeLeft xy && y == Array.takeRight xy
takeCenter :: (C sh0, C sh1, C sh2, Storable a) => Array (sh0 ::+ (sh1 ::+ sh2)) a -> Array sh1 a Source #
\(Array16 x) (Array16 y) (Array16 z) -> let xyz = Array.append x $ Array.append y z in y == Array.takeCenter xyz
sum :: (C sh, Storable a, Num a) => Array sh a -> a Source #
\(Array16 xs) -> Array.sum xs == sum (Array.toList xs)
product :: (C sh, Storable a, Num a) => Array sh a -> a Source #
\(Array16 xs) -> Array.product xs == product (Array.toList xs)
minimum :: (C sh, Storable a, Ord a) => Array sh a -> a Source #
It is a checked error if the vector is empty.
forAllNonEmpty $ \xs -> Array.minimum xs ==? minimum (Array.toList xs)
argMinimum :: (InvIndexed sh, Storable a, Ord a) => Array sh a -> (Index sh, a) Source #
maximum :: (C sh, Storable a, Ord a) => Array sh a -> a Source #
It is a checked error if the vector is empty.
forAllNonEmpty $ \xs -> Array.maximum xs ==? maximum (Array.toList xs)
argMaximum :: (InvIndexed sh, Storable a, Ord a) => Array sh a -> (Index sh, a) Source #