comfort-array-0.5.4.1: Arrays where the index type is a function of the shape type
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Array.Comfort.Storable

Synopsis

Documentation

data Array sh a Source #

Instances

Instances details
(AppendMonoid sh, Storable a) => Monoid (Array sh a) Source # 
Instance details

Defined in Data.Array.Comfort.Storable.Private

Methods

mempty :: Array sh a #

mappend :: Array sh a -> Array sh a -> Array sh a #

mconcat :: [Array sh a] -> Array sh a #

(AppendSemigroup sh, Storable a) => Semigroup (Array sh a) Source # 
Instance details

Defined in Data.Array.Comfort.Storable.Private

Methods

(<>) :: Array sh a -> Array sh a -> Array sh a #

sconcat :: NonEmpty (Array sh a) -> Array sh a #

stimes :: Integral b => b -> Array sh a -> Array sh a #

(C sh, Show sh, Storable a, Show a) => Show (Array sh a) Source # 
Instance details

Defined in Data.Array.Comfort.Storable.Private

Methods

showsPrec :: Int -> Array sh a -> ShowS #

show :: Array sh a -> String #

showList :: [Array sh a] -> ShowS #

NFData sh => NFData (Array sh a) Source # 
Instance details

Defined in Data.Array.Comfort.Storable.Private

Methods

rnf :: Array sh a -> () #

(C sh, Eq sh, Storable a, Eq a) => Eq (Array sh a) Source # 
Instance details

Defined in Data.Array.Comfort.Storable.Private

Methods

(==) :: Array sh a -> Array sh a -> Bool #

(/=) :: Array sh a -> Array sh a -> Bool #

shape :: Array sh a -> sh Source #

reshape :: (C sh0, C sh1) => sh1 -> Array sh0 a -> Array sh1 a Source #

mapShape :: (C sh0, C sh1) => (sh0 -> sh1) -> Array sh0 a -> Array sh1 a Source #

accessMaybe :: (Indexed sh, Storable a) => Array sh a -> Index sh -> Maybe a Source #

(!) :: (Indexed sh, Storable a) => Array sh a -> Index sh -> a infixl 9 Source #

toList :: (C sh, Storable a) => Array sh a -> [a] Source #

toAssociations :: (Indexed sh, Storable a) => Array sh a -> [(Index 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"

fromMap :: (Ord k, Storable a) => Map k a -> Array (Set k) a Source #

toMap :: (Ord k, Storable a) => Array (Set k) a -> Map k a Source #

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')

toRecord :: (Traversable f, Storable a) => Array (Record f) a -> f a Source #

fromContainer :: (C f, Storable a) => f a -> Array (Shape f) a Source #

toContainer :: (C f, Storable a) => Array (Shape f) a -> f a Source #

sample :: (Indexed sh, Storable a) => sh -> (Index sh -> a) -> Array sh a Source #

replicate :: (Indexed sh, Storable a) => sh -> a -> Array sh a Source #

fromBoxed :: (C sh, Storable a) => Array sh a -> Array sh a Source #

toBoxed :: (C sh, Storable a) => Array sh a -> Array sh a Source #

toStorableVector :: (C sh, Storable a) => Array sh a -> Vector a Source #

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))

map :: (C sh, Storable a, Storable b) => (a -> b) -> Array sh a -> Array sh b Source #

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 #

(//) :: (Indexed sh, Storable a) => Array sh a -> [(Index sh, a)] -> Array sh a Source #

accumulate :: (Indexed sh, Storable a) => (a -> b -> a) -> Array sh a -> [(Index sh, b)] -> Array sh a Source #

fromAssociations :: (Indexed sh, Storable a) => a -> sh -> [(Index sh, a)] -> 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)

singleton :: Storable a => a -> Array () a Source #

\x  ->  Array.singleton x ! () == (x::Word16)

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

takeRight :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> Array sh1 a Source #

split :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> (Array sh0 a, Array sh1 a) Source #

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 #

limits :: (C sh, Storable a, Ord a) => Array sh a -> (a, a) Source #

forAllNonEmpty $ \xs -> Array.limits xs ==? (Array.minimum xs, Array.maximum xs)

foldl :: (C sh, Storable a) => (b -> a -> b) -> b -> Array sh a -> b Source #

foldl1 :: (C sh, Storable a) => (a -> a -> a) -> Array sh a -> a Source #

foldMap :: (C sh, Storable a, Ord a, Semigroup m) => (a -> m) -> Array sh a -> m Source #