Copyright | (c) Alexey Kuleshevich 2018-2022 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data family Array r ix e :: Type
- newtype List ix e = List {
- unList :: [Elt ix e]
- type Vector r e = Array r Ix1 e
- type MVector s r e = MArray s r Ix1 e
- type Matrix r e = Array r Ix2 e
- type MMatrix s r e = MArray s r Ix2 e
- class (Strategy r, Shape r ix) => Load r ix e where
- class Load r ix e => Stream r ix e where
- class (Strategy r, Size r) => Source r e
- data PrefIndex ix e
- = PrefIndex (ix -> e)
- | PrefIndexLinear (Int -> e)
- class Size r
- class Index ix => Shape r ix where
- linearSizeHint :: Array r ix e -> LengthHint
- linearSize :: Array r ix e -> Sz1
- outerSize :: Array r ix e -> Sz ix
- maxLinearSize :: Array r ix e -> Maybe Sz1
- isNull :: Array r ix e -> Bool
- data LengthHint
- class Load r ix e => StrideLoad r ix e where
- class Source r e => Manifest r e
- type Mutable r e = Manifest r e
- class (IsList (Array r ix e), Load r ix e) => Ragged r ix e
- data L = L
- type family ListItem ix e :: Type where ...
- data Scheduler s a
- data SchedulerWS ws a
- class Typeable r => Strategy r
- data Comp where
- getComp :: Strategy r => Array r ix e -> Comp
- setComp :: Strategy r => Comp -> Array r ix e -> Array r ix e
- appComp :: Strategy r => Comp -> Array r ix e -> Array r ix e
- data WorkerStates ws
- initWorkerStates :: MonadIO m => Comp -> (WorkerId -> m ws) -> m (WorkerStates ws)
- scheduleWork :: MonadPrimBase s m => Scheduler s a -> m a -> m ()
- scheduleWork_ :: MonadPrimBase s m => Scheduler s () -> m () -> m ()
- module Data.Massiv.Core.Index
- class (Size r, Num e) => FoldNumeric r e
- class FoldNumeric r e => Numeric r e
- class (Numeric r e, Floating e) => NumericFloat r e
- class Monad m => MonadThrow (m :: Type -> Type) where
- data IndexException where
- IndexZeroException :: Index ix => !ix -> IndexException
- IndexDimensionException :: (NFData ix, Eq ix, Show ix, Typeable ix) => !ix -> !Dim -> IndexException
- IndexOutOfBoundsException :: Index ix => !(Sz ix) -> !ix -> IndexException
- data SizeException where
- SizeMismatchException :: Index ix => !(Sz ix) -> !(Sz ix) -> SizeException
- SizeElementsMismatchException :: (Index ix, Index ix') => !(Sz ix) -> !(Sz ix') -> SizeException
- SizeSubregionException :: Index ix => !(Sz ix) -> !ix -> !(Sz ix) -> SizeException
- SizeEmptyException :: Index ix => !(Sz ix) -> SizeException
- SizeOverflowException :: Index ix => !(Sz ix) -> SizeException
- SizeNegativeException :: Index ix => !(Sz ix) -> SizeException
- data ShapeException
- = DimTooShortException !Dim !(Sz Ix1) !(Sz Ix1)
- | DimTooLongException !Dim !(Sz Ix1) !(Sz Ix1)
- | ShapeNonEmpty
- throwImpossible :: HasCallStack => Exception e => e -> a
- throwEither :: HasCallStack => Either SomeException a -> a
- data Uninitialized = Uninitialized
- guardNumberOfElements :: (MonadThrow m, Index ix, Index ix') => Sz ix -> Sz ix' -> m ()
- class (Typeable e, Show e) => Exception e where
- toException :: e -> SomeException
- fromException :: SomeException -> Maybe e
- displayException :: e -> String
- data SomeException
- type HasCallStack = ?callStack :: CallStack
- class MonadIO m => MonadUnliftIO (m :: Type -> Type)
- class Monad m => MonadIO (m :: Type -> Type) where
- class Monad m => PrimMonad (m :: Type -> Type) where
Documentation
data family Array r ix e :: Type Source #
The array family. Representations r
describe how data is arranged or computed. All
arrays have a common property that each index ix
always maps to the same unique
element e
, even if that element does not yet exist in memory and the array has to be
computed in order to get the value of that element. Data is always arranged in a nested
row-major fashion. Rank of an array is specified by
.Dimensions
ix
Since: 0.1.0
Instances
Index ix => Foldable (Array DI ix) Source # | |
Defined in Data.Massiv.Array.Delayed.Interleaved fold :: Monoid m => Array DI ix m -> m # foldMap :: Monoid m => (a -> m) -> Array DI ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array DI ix a -> m # foldr :: (a -> b -> b) -> b -> Array DI ix a -> b # foldr' :: (a -> b -> b) -> b -> Array DI ix a -> b # foldl :: (b -> a -> b) -> b -> Array DI ix a -> b # foldl' :: (b -> a -> b) -> b -> Array DI ix a -> b # foldr1 :: (a -> a -> a) -> Array DI ix a -> a # foldl1 :: (a -> a -> a) -> Array DI ix a -> a # toList :: Array DI ix a -> [a] # null :: Array DI ix a -> Bool # length :: Array DI ix a -> Int # elem :: Eq a => a -> Array DI ix a -> Bool # maximum :: Ord a => Array DI ix a -> a # minimum :: Ord a => Array DI ix a -> a # | |
Index ix => Foldable (Array D ix) Source # | Row-major sequential folding over a Delayed array. |
Defined in Data.Massiv.Array.Delayed.Pull fold :: Monoid m => Array D ix m -> m # foldMap :: Monoid m => (a -> m) -> Array D ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array D ix a -> m # foldr :: (a -> b -> b) -> b -> Array D ix a -> b # foldr' :: (a -> b -> b) -> b -> Array D ix a -> b # foldl :: (b -> a -> b) -> b -> Array D ix a -> b # foldl' :: (b -> a -> b) -> b -> Array D ix a -> b # foldr1 :: (a -> a -> a) -> Array D ix a -> a # foldl1 :: (a -> a -> a) -> Array D ix a -> a # toList :: Array D ix a -> [a] # null :: Array D ix a -> Bool # length :: Array D ix a -> Int # elem :: Eq a => a -> Array D ix a -> Bool # maximum :: Ord a => Array D ix a -> a # minimum :: Ord a => Array D ix a -> a # | |
Foldable (Array DS Ix1) Source # | |
Defined in Data.Massiv.Array.Delayed.Stream fold :: Monoid m => Array DS Ix1 m -> m # foldMap :: Monoid m => (a -> m) -> Array DS Ix1 a -> m # foldMap' :: Monoid m => (a -> m) -> Array DS Ix1 a -> m # foldr :: (a -> b -> b) -> b -> Array DS Ix1 a -> b # foldr' :: (a -> b -> b) -> b -> Array DS Ix1 a -> b # foldl :: (b -> a -> b) -> b -> Array DS Ix1 a -> b # foldl' :: (b -> a -> b) -> b -> Array DS Ix1 a -> b # foldr1 :: (a -> a -> a) -> Array DS Ix1 a -> a # foldl1 :: (a -> a -> a) -> Array DS Ix1 a -> a # toList :: Array DS Ix1 a -> [a] # null :: Array DS Ix1 a -> Bool # length :: Array DS Ix1 a -> Int # elem :: Eq a => a -> Array DS Ix1 a -> Bool # maximum :: Ord a => Array DS Ix1 a -> a # minimum :: Ord a => Array DS Ix1 a -> a # | |
Index ix => Foldable (Array B ix) Source # | Row-major sequential folding over a Boxed array. |
Defined in Data.Massiv.Array.Manifest.Boxed fold :: Monoid m => Array B ix m -> m # foldMap :: Monoid m => (a -> m) -> Array B ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array B ix a -> m # foldr :: (a -> b -> b) -> b -> Array B ix a -> b # foldr' :: (a -> b -> b) -> b -> Array B ix a -> b # foldl :: (b -> a -> b) -> b -> Array B ix a -> b # foldl' :: (b -> a -> b) -> b -> Array B ix a -> b # foldr1 :: (a -> a -> a) -> Array B ix a -> a # foldl1 :: (a -> a -> a) -> Array B ix a -> a # toList :: Array B ix a -> [a] # null :: Array B ix a -> Bool # length :: Array B ix a -> Int # elem :: Eq a => a -> Array B ix a -> Bool # maximum :: Ord a => Array B ix a -> a # minimum :: Ord a => Array B ix a -> a # | |
Index ix => Foldable (Array BL ix) Source # | Row-major sequential folding over a Boxed array. |
Defined in Data.Massiv.Array.Manifest.Boxed fold :: Monoid m => Array BL ix m -> m # foldMap :: Monoid m => (a -> m) -> Array BL ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array BL ix a -> m # foldr :: (a -> b -> b) -> b -> Array BL ix a -> b # foldr' :: (a -> b -> b) -> b -> Array BL ix a -> b # foldl :: (b -> a -> b) -> b -> Array BL ix a -> b # foldl' :: (b -> a -> b) -> b -> Array BL ix a -> b # foldr1 :: (a -> a -> a) -> Array BL ix a -> a # foldl1 :: (a -> a -> a) -> Array BL ix a -> a # toList :: Array BL ix a -> [a] # null :: Array BL ix a -> Bool # length :: Array BL ix a -> Int # elem :: Eq a => a -> Array BL ix a -> Bool # maximum :: Ord a => Array BL ix a -> a # minimum :: Ord a => Array BL ix a -> a # | |
Index ix => Traversable (Array B ix) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => Traversable (Array BL ix) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => Applicative (Array DI ix) Source # | |
Defined in Data.Massiv.Array.Delayed.Interleaved | |
Index ix => Applicative (Array D ix) Source # | |
Defined in Data.Massiv.Array.Delayed.Pull | |
Applicative (Array DS Ix1) Source # | |
Defined in Data.Massiv.Array.Delayed.Stream | |
Functor (Array DI ix) Source # | |
Functor (Array D ix) Source # | |
Index ix => Functor (Array DL ix) Source # | |
Functor (Array DS Ix1) Source # | |
Functor (Array DW ix) Source # | |
Index ix => Functor (Array B ix) Source # | |
Index ix => Functor (Array BL ix) Source # | |
Monad (Array DS Ix1) Source # | |
Monoid (Array DL Ix1 e) Source # | |
Monoid (Array DS Ix1 e) Source # | |
Semigroup (Array DL Ix1 e) Source # | |
Semigroup (Array DS Ix1 e) Source # | |
IsList (Array DS Ix1 e) Source # | |
(IsList (Array L ix e), Ragged L ix e) => IsList (Array B ix e) Source # | |
(IsList (Array L ix e), Ragged L ix e) => IsList (Array BL ix e) Source # | |
(NFData e, IsList (Array L ix e), Ragged L ix e) => IsList (Array BN ix e) Source # | |
(Prim e, IsList (Array L ix e), Ragged L ix e) => IsList (Array P ix e) Source # | |
(Storable e, IsList (Array L ix e), Ragged L ix e) => IsList (Array S ix e) Source # | |
(Unbox e, IsList (Array L ix e), Ragged L ix e) => IsList (Array U ix e) Source # | |
Coercible (Elt ix e) (ListItem ix e) => IsList (Array L ix e) Source # | |
(Ragged L ix e, Show e) => Show (Array DI ix e) Source # | |
(Ragged L ix e, Show e) => Show (Array D ix e) Source # | |
(Ragged L ix e, Show e) => Show (Array DL ix e) Source # | |
Show e => Show (Array DS Ix1 e) Source # | |
(Ragged L ix e, Load DW ix e, Show e) => Show (Array DW ix e) Source # | |
(Ragged L ix e, Show e) => Show (Array B ix e) Source # | |
(Ragged L ix e, Show e) => Show (Array BL ix e) Source # | |
(Ragged L ix e, Show e, NFData e) => Show (Array BN ix e) Source # | |
(Ragged L ix e, Show e, Prim e) => Show (Array P ix e) Source # | |
(Ragged L ix e, Show e, Storable e) => Show (Array S ix e) Source # | |
(Ragged L ix e, Show e, Unbox e) => Show (Array U ix e) Source # | |
(Ragged L ix e, Show e) => Show (Array L ix e) Source # | |
(Index ix, NFData e) => NFData (Array B ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
(Index ix, NFData e) => NFData (Array BL ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
NFData (Array BN ix e) Source # | O(1) - |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => NFData (Array P ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Primitive | |
NFData ix => NFData (Array S ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Storable | |
NFData ix => NFData (Array U ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Unboxed | |
(Index ix, Eq e) => Eq (Array DI ix e) Source # | |
(Eq e, Index ix) => Eq (Array D ix e) Source # | |
(Index ix, Eq e) => Eq (Array B ix e) Source # | |
(Index ix, Eq e) => Eq (Array BL ix e) Source # | |
(Index ix, NFData e, Eq e) => Eq (Array BN ix e) Source # | |
(Prim e, Eq e, Index ix) => Eq (Array P ix e) Source # | |
(Storable e, Eq e, Index ix) => Eq (Array S ix e) Source # | |
(Unbox e, Eq e, Index ix) => Eq (Array U ix e) Source # | |
(Index ix, Ord e) => Ord (Array DI ix e) Source # | |
Defined in Data.Massiv.Array.Delayed.Interleaved compare :: Array DI ix e -> Array DI ix e -> Ordering # (<) :: Array DI ix e -> Array DI ix e -> Bool # (<=) :: Array DI ix e -> Array DI ix e -> Bool # (>) :: Array DI ix e -> Array DI ix e -> Bool # (>=) :: Array DI ix e -> Array DI ix e -> Bool # | |
(Ord e, Index ix) => Ord (Array D ix e) Source # | |
Defined in Data.Massiv.Array.Delayed.Pull | |
(Index ix, Ord e) => Ord (Array B ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
(Index ix, Ord e) => Ord (Array BL ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed compare :: Array BL ix e -> Array BL ix e -> Ordering # (<) :: Array BL ix e -> Array BL ix e -> Bool # (<=) :: Array BL ix e -> Array BL ix e -> Bool # (>) :: Array BL ix e -> Array BL ix e -> Bool # (>=) :: Array BL ix e -> Array BL ix e -> Bool # | |
(Index ix, NFData e, Ord e) => Ord (Array BN ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Boxed compare :: Array BN ix e -> Array BN ix e -> Ordering # (<) :: Array BN ix e -> Array BN ix e -> Bool # (<=) :: Array BN ix e -> Array BN ix e -> Bool # (>) :: Array BN ix e -> Array BN ix e -> Bool # (>=) :: Array BN ix e -> Array BN ix e -> Bool # | |
(Prim e, Ord e, Index ix) => Ord (Array P ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Primitive | |
(Storable e, Ord e, Index ix) => Ord (Array S ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Storable | |
(Unbox e, Ord e, Index ix) => Ord (Array U ix e) Source # | |
Defined in Data.Massiv.Array.Manifest.Unboxed | |
newtype Array DI ix e Source # | |
data Array D ix e Source # | |
Defined in Data.Massiv.Array.Delayed.Pull | |
data Array DL ix e Source # | |
data Array DW ix e Source # | |
newtype Array B ix e Source # | |
data Array BL ix e Source # | |
newtype Array BN ix e Source # | |
data Array P ix e Source # | |
data Array S ix e Source # | |
Defined in Data.Massiv.Array.Manifest.Storable | |
data Array U ix e Source # | |
data Array L ix e Source # | |
newtype Array DS Ix1 e Source # | |
type Item (Array DS Ix1 e) Source # | |
Defined in Data.Massiv.Array.Delayed.Stream | |
type Item (Array B ix e) Source # | |
type Item (Array BL ix e) Source # | |
type Item (Array BN ix e) Source # | |
type Item (Array P ix e) Source # | |
type Item (Array S ix e) Source # | |
type Item (Array U ix e) Source # | |
type Item (Array L ix e) Source # | |
Defined in Data.Massiv.Core.List |
type Vector r e = Array r Ix1 e Source #
Type synonym for a single dimension array, or simply a flat vector.
Since: 0.5.0
type MVector s r e = MArray s r Ix1 e Source #
Type synonym for a single dimension mutable array, or simply a flat mutable vector.
Since: 0.5.0
type Matrix r e = Array r Ix2 e Source #
Type synonym for a two-dimentsional array, or simply a matrix.
Since: 0.5.0
type MMatrix s r e = MArray s r Ix2 e Source #
Type synonym for a two-dimentsional mutable array, or simply a mutable matrix.
Since: 0.5.0
class (Strategy r, Shape r ix) => Load r ix e where Source #
Any array that can be computed and loaded into memory
:: Scheduler s () | |
-> Array r ix e | Array that is being loaded |
-> (Int -> e -> ST s ()) | Function that writes an element into target array |
-> ST s () |
Iterate over an array with a ST action that is applied to each element and its index.
Since: 1.0.0
iterArrayLinearWithSetST_ Source #
:: Scheduler s () | |
-> Array r ix e | Array that is being loaded |
-> (Ix1 -> e -> ST s ()) | Function that writes an element into target array |
-> (Ix1 -> Sz1 -> e -> ST s ()) | Function that efficiently sets a region of an array to the supplied value target array |
-> ST s () |
Similar to iterArrayLinearST_
. Except it also accepts a function that is
potentially optimized for setting many cells in a region to the same
value.
Since: 1.0.0
Instances
class Load r ix e => Stream r ix e where Source #
toStream :: Array r ix e -> Steps Id e Source #
toStreamIx :: Array r ix e -> Steps Id (ix, e) Source #
Instances
Index ix => Stream D ix e Source # | |
Stream DS Ix1 e Source # | |
Index ix => Stream B ix e Source # | |
Index ix => Stream BL ix e Source # | |
(Index ix, NFData e) => Stream BN ix e Source # | |
(Prim e, Index ix) => Stream P ix e Source # | |
(Index ix, Storable e) => Stream S ix e Source # | |
(Index ix, Unbox e) => Stream U ix e Source # | |
Stream L Ix1 e Source # | |
class (Strategy r, Size r) => Source r e Source #
Arrays that can be used as source to practically any manipulation function.
Instances
Prefered indexing function.
PrefIndex (ix -> e) | |
PrefIndexLinear (Int -> e) |
Arrays that have information about their size availible in constant time.
class Index ix => Shape r ix where Source #
The shape of an array. It is different from Size
in that it can be applicable to
non-square matrices and might not be available in constant time.
Since: 1.0.0
Nothing
linearSizeHint :: Array r ix e -> LengthHint Source #
O(1) - Check what do we know about the number of elements without doing any work
Since: 1.0.0
linearSize :: Array r ix e -> Sz1 Source #
O(n) - possibly iterate over the whole array before producing the answer
Since: 0.5.8
outerSize :: Array r ix e -> Sz ix Source #
O(n) - Rectangular size of an array that is inferred from looking at the first row in
each dimensions. For rectangular arrays this is the same as size
Since: 1.0.0
maxLinearSize :: Array r ix e -> Maybe Sz1 Source #
O(1) - Get the possible maximum linear size of an immutabe array. If the lookup
of size in constant time is not possible, Nothing
will be returned. This value
will be used as the initial size of the mutable array into which the loading will
happen.
Since: 1.0.0
isNull :: Array r ix e -> Bool Source #
O(1) - Check whether an array is empty or not.
Examples
>>>
import Data.Massiv.Array
>>>
isNull $ range Seq (Ix2 10 20) (11 :. 21)
False>>>
isNull $ range Seq (Ix2 10 20) (10 :. 21)
True>>>
isNull (empty :: Array D Ix5 Int)
True>>>
isNull $ sfromList []
True
Since: 1.0.0
Instances
Index ix => Shape DI ix Source # | |
Index ix => Shape D ix Source # | |
Index ix => Shape DL ix Source # | |
Shape DS Ix1 Source # | |
Index ix => Shape DW ix Source # | |
Index ix => Shape B ix Source # | |
Index ix => Shape BL ix Source # | |
Index ix => Shape BN ix Source # | |
Index ix => Shape P ix Source # | |
Index ix => Shape S ix Source # | |
Index ix => Shape U ix Source # | |
Shape L Ix1 Source # | |
Shape L Ix2 Source # | |
(Shape L (Ix (n - 1)), Index (IxN n)) => Shape L (IxN n) Source # | |
data LengthHint Source #
Size hint
Since: 1.0.0
LengthExact Sz1 | Exact known size |
LengthMax Sz1 | Upper bound on the size |
LengthUnknown | Unknown size |
Instances
Show LengthHint Source # | |
Defined in Data.Massiv.Core.Common showsPrec :: Int -> LengthHint -> ShowS # show :: LengthHint -> String # showList :: [LengthHint] -> ShowS # | |
Eq LengthHint Source # | |
Defined in Data.Massiv.Core.Common (==) :: LengthHint -> LengthHint -> Bool # (/=) :: LengthHint -> LengthHint -> Bool # |
class Load r ix e => StrideLoad r ix e where Source #
Nothing
iterArrayLinearWithStrideST_ Source #
:: Scheduler s () | |
-> Stride ix | Stride to use |
-> Sz ix | Size of the target array affected by the stride. |
-> Array r ix e | Array that is being loaded |
-> (Int -> e -> ST s ()) | Function that writes an element into target array |
-> ST s () |
Load an array into memory with stride. Default implementation requires an instance of
Source
.
Instances
Index ix => StrideLoad DI ix e Source # | |
Index ix => StrideLoad D ix e Source # | |
StrideLoad DW Ix1 e Source # | |
StrideLoad DW Ix2 e Source # | |
Index ix => StrideLoad B ix e Source # | |
Index ix => StrideLoad BL ix e Source # | |
(Index ix, NFData e) => StrideLoad BN ix e Source # | |
(Prim e, Index ix) => StrideLoad P ix e Source # | |
(Index ix, Storable e) => StrideLoad S ix e Source # | |
(Unbox e, Index ix) => StrideLoad U ix e Source # | |
(Index (IxN n), StrideLoad DW (Ix (n - 1)) e) => StrideLoad DW (IxN n) e Source # | |
class Source r e => Manifest r e Source #
Manifest arrays are backed by actual memory and values are looked up versus
computed as it is with delayed arrays. Because manifest arrays are located in
memory their contents can be mutated once thawed into MArray
. The process
of changed a mutable MArray
back into an immutable Array
is called
freezing.
unsafeLinearIndexM, sizeOfMArray, unsafeResizeMArray, unsafeLinearSliceMArray, unsafeThaw, unsafeFreeze, unsafeNew, unsafeLinearRead, unsafeLinearWrite, initialize
Instances
class (IsList (Array r ix e), Load r ix e) => Ragged r ix e Source #
generateRaggedM, flattenRagged, loadRaggedST, raggedFormat
Instances
Ragged L Ix1 e Source # | |
Defined in Data.Massiv.Core.List | |
Ragged L Ix2 e Source # | |
Defined in Data.Massiv.Core.List | |
(Shape L (IxN n), Ragged L (Ix (n - 1)) e, Coercible (Elt (Ix (n - 1)) e) (ListItem (Ix (n - 1)) e)) => Ragged L (IxN n) e Source # | |
Defined in Data.Massiv.Core.List generateRaggedM :: Monad m => Comp -> Sz (IxN n) -> (IxN n -> m e) -> m (Array L (IxN n) e) flattenRagged :: Array L (IxN n) e -> Vector L e loadRaggedST :: Scheduler s () -> Array L (IxN n) e -> (Ix1 -> e -> ST s ()) -> Ix1 -> Ix1 -> Sz (IxN n) -> ST s () raggedFormat :: (e -> String) -> String -> Array L (IxN n) e -> String |
Instances
Main type for scheduling work. See withScheduler
or
withScheduler_
for ways to construct and use this data type.
Since: scheduler-1.0.0
data SchedulerWS ws a #
This is a wrapper around Scheduler
, but it also keeps a separate state for each
individual worker. See withSchedulerWS
or
withSchedulerWS_
for ways to construct and use this data type.
Since: scheduler-1.4.0
Computation strategy to use when scheduling work.
Seq | Sequential computation |
ParOn ![Int] | Schedule workers to run on specific capabilities. Specifying an empty list |
ParN !Word16 | Specify the number of workers that will be handling all the jobs. Difference from |
pattern Par :: Comp | Parallel computation using all available cores. Same as Since: scheduler-1.0.0 |
pattern Par' :: Comp | Parallel computation using all available cores. Same as Since: scheduler-1.1.0 |
getComp :: Strategy r => Array r ix e -> Comp Source #
Get computation strategy of this array
Since: 0.1.0
setComp :: Strategy r => Comp -> Array r ix e -> Array r ix e Source #
Set computation strategy for this array
Example
>>>
:set -XTypeApplications
>>>
import Data.Massiv.Array
>>>
a = singleton @DL @Ix1 @Int 0
>>>
a
Array DL Seq (Sz1 1) [ 0 ]>>>
setComp (ParN 6) a -- use 6 capabilities
Array DL (ParN 6) (Sz1 1) [ 0 ]
data WorkerStates ws #
Each worker is capable of keeping it's own state, that can be share for different
schedulers, but not at the same time. In other words using the same WorkerStates
on
withSchedulerS
concurrently will result in an error. Can be initialized with
initWorkerStates
Since: scheduler-1.4.0
initWorkerStates :: MonadIO m => Comp -> (WorkerId -> m ws) -> m (WorkerStates ws) #
Initialize a separate state for each worker.
Since: scheduler-1.4.0
scheduleWork :: MonadPrimBase s m => Scheduler s a -> m a -> m () #
Schedule an action to be picked up and computed by a worker from a pool of
jobs. Similar to scheduleWorkId
, except the job doesn't get the worker id.
Since: scheduler-1.0.0
scheduleWork_ :: MonadPrimBase s m => Scheduler s () -> m () -> m () #
Same as scheduleWork
, but only for a Scheduler
that doesn't keep the results.
Since: scheduler-1.1.0
module Data.Massiv.Core.Index
Numeric
class (Size r, Num e) => FoldNumeric r e Source #
Instances
class FoldNumeric r e => Numeric r e Source #
Instances
class (Numeric r e, Floating e) => NumericFloat r e Source #
Instances
Exceptions
class Monad m => MonadThrow (m :: Type -> Type) where #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
throwM :: Exception e => e -> m a #
Throw an exception. Note that this throws when this action is run in
the monad m
, not when it is applied. It is a generalization of
Control.Exception's throwIO
.
Should satisfy the law:
throwM e >> f = throwM e
Instances
data IndexException where Source #
Exceptions that get thrown when there is a problem with an index, size or dimension.
Since: 0.3.0
IndexZeroException :: Index ix => !ix -> IndexException | Index contains a zero value along one of the dimensions. |
IndexDimensionException :: (NFData ix, Eq ix, Show ix, Typeable ix) => !ix -> !Dim -> IndexException | Dimension is out of reach. |
IndexOutOfBoundsException :: Index ix => !(Sz ix) -> !ix -> IndexException | Index is out of bounds. |
Instances
Exception IndexException Source # | |
Defined in Data.Massiv.Core.Index.Internal | |
Show IndexException Source # | |
Defined in Data.Massiv.Core.Index.Internal showsPrec :: Int -> IndexException -> ShowS # show :: IndexException -> String # showList :: [IndexException] -> ShowS # | |
NFData IndexException Source # | |
Defined in Data.Massiv.Core.Index.Internal rnf :: IndexException -> () # | |
Eq IndexException Source # | |
Defined in Data.Massiv.Core.Index.Internal (==) :: IndexException -> IndexException -> Bool # (/=) :: IndexException -> IndexException -> Bool # |
data SizeException where Source #
Exception that indicates an issue with an array size.
Since: 0.3.0
SizeMismatchException :: Index ix => !(Sz ix) -> !(Sz ix) -> SizeException | Two sizes are expected to be equal along some or all dimensions, but they are not. |
SizeElementsMismatchException :: (Index ix, Index ix') => !(Sz ix) -> !(Sz ix') -> SizeException | Total number of elements does not match between the two sizes. |
SizeSubregionException :: Index ix => !(Sz ix) -> !ix -> !(Sz ix) -> SizeException | Described subregion is too big for the specified size. |
SizeEmptyException :: Index ix => !(Sz ix) -> SizeException | An array with the size cannot contain any elements. |
SizeOverflowException :: Index ix => !(Sz ix) -> SizeException | Total number of elements is too large resulting in overflow. Since: 0.6.0 |
SizeNegativeException :: Index ix => !(Sz ix) -> SizeException | At least one dimensions contain a negative value. Since: 0.6.0 |
Instances
Exception SizeException Source # | |
Defined in Data.Massiv.Core.Index.Internal | |
Show SizeException Source # | |
Defined in Data.Massiv.Core.Index.Internal showsPrec :: Int -> SizeException -> ShowS # show :: SizeException -> String # showList :: [SizeException] -> ShowS # | |
NFData SizeException Source # | |
Defined in Data.Massiv.Core.Index.Internal rnf :: SizeException -> () # | |
Eq SizeException Source # | |
Defined in Data.Massiv.Core.Index.Internal (==) :: SizeException -> SizeException -> Bool # (/=) :: SizeException -> SizeException -> Bool # |
data ShapeException Source #
Exception that can happen upon conversion of a ragged type array into the rectangular kind. Which means conversion from lists is susceptible to this exception.
Since: 0.3.0
DimTooShortException !Dim !(Sz Ix1) !(Sz Ix1) | Across a specific dimension there was not enough elements for the supplied size |
DimTooLongException !Dim !(Sz Ix1) !(Sz Ix1) | Across a specific dimension there was too many elements for the supplied size |
ShapeNonEmpty | Expected an empty size, but the shape was not empty. |
Instances
Exception ShapeException Source # | |
Defined in Data.Massiv.Core.Index.Internal | |
Show ShapeException Source # | |
Defined in Data.Massiv.Core.Index.Internal showsPrec :: Int -> ShapeException -> ShowS # show :: ShapeException -> String # showList :: [ShapeException] -> ShowS # | |
Eq ShapeException Source # | |
Defined in Data.Massiv.Core.Index.Internal (==) :: ShapeException -> ShapeException -> Bool # (/=) :: ShapeException -> ShapeException -> Bool # |
throwImpossible :: HasCallStack => Exception e => e -> a Source #
Throw an impossible error.
Since: 0.5.6
throwEither :: HasCallStack => Either SomeException a -> a Source #
data Uninitialized Source #
An error that gets thrown when an unitialized element of a boxed array gets accessed. Can only
happen when array was constructed with unsafeNew
.
Instances
Exception Uninitialized Source # | |
Defined in Data.Massiv.Core.Exception | |
Show Uninitialized Source # | |
Defined in Data.Massiv.Core.Exception showsPrec :: Int -> Uninitialized -> ShowS # show :: Uninitialized -> String # showList :: [Uninitialized] -> ShowS # |
guardNumberOfElements :: (MonadThrow m, Index ix, Index ix') => Sz ix -> Sz ix' -> m () Source #
Throw SizeElementsMismatchException
whenever number of elements in both sizes do
not match.
Since: 0.3.5
class (Typeable e, Show e) => Exception e where #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception
class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException deriving Show instance Exception MyException
The default method definitions in the Exception
class do what we need
in this case. You can now throw and catch ThisException
and
ThatException
as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException)) Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
--------------------------------------------------------------------- -- Make the root exception type for all the exceptions in a compiler data SomeCompilerException = forall e . Exception e => SomeCompilerException e instance Show SomeCompilerException where show (SomeCompilerException e) = show e instance Exception SomeCompilerException compilerExceptionToException :: Exception e => e -> SomeException compilerExceptionToException = toException . SomeCompilerException compilerExceptionFromException :: Exception e => SomeException -> Maybe e compilerExceptionFromException x = do SomeCompilerException a <- fromException x cast a --------------------------------------------------------------------- -- Make a subhierarchy for exceptions in the frontend of the compiler data SomeFrontendException = forall e . Exception e => SomeFrontendException e instance Show SomeFrontendException where show (SomeFrontendException e) = show e instance Exception SomeFrontendException where toException = compilerExceptionToException fromException = compilerExceptionFromException frontendExceptionToException :: Exception e => e -> SomeException frontendExceptionToException = toException . SomeFrontendException frontendExceptionFromException :: Exception e => SomeException -> Maybe e frontendExceptionFromException x = do SomeFrontendException a <- fromException x cast a --------------------------------------------------------------------- -- Make an exception type for a particular frontend compiler exception data MismatchedParentheses = MismatchedParentheses deriving Show instance Exception MismatchedParentheses where toException = frontendExceptionToException fromException = frontendExceptionFromException
We can now catch a MismatchedParentheses
exception as
MismatchedParentheses
, SomeFrontendException
or
SomeCompilerException
, but not other types, e.g. IOException
:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException)) *** Exception: MismatchedParentheses
Nothing
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
Render this exception value in a human-friendly manner.
Default implementation:
.show
Since: base-4.8.0.0
Instances
data SomeException #
The SomeException
type is the root of the exception type hierarchy.
When an exception of type e
is thrown, behind the scenes it is
encapsulated in a SomeException
.
Instances
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type | |
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # |
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack
is an
implementation detail and should not be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
Stateful Monads
class MonadIO m => MonadUnliftIO (m :: Type -> Type) #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any function run
provided by withRunInIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
run . return = return
run (m >>= f) = run m >>= run . f
Instances of MonadUnliftIO
must also satisfy the following laws:
- Identity law
withRunInIO (\run -> run m) = m
- Inverse law
withRunInIO (\_ -> m) = liftIO m
As an example of an invalid instance, a naive implementation of
MonadUnliftIO (StateT s m)
might be
withRunInIO inner = StateT $ \s -> withRunInIO $ \run -> inner (run . flip evalStateT s)
This breaks the identity law because the inner run m
would throw away
any state changes in m
.
Since: unliftio-core-0.1.0.0
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift |
class Monad m => MonadIO (m :: Type -> Type) where #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
Instances
class Monad m => PrimMonad (m :: Type -> Type) #
Class of monads which can perform primitive state-transformer actions.
Instances
PrimMonad IO | |
PrimMonad (ST s) | |
PrimMonad (ST s) | |
PrimMonad m => PrimMonad (ListT m) | |
PrimMonad m => PrimMonad (MaybeT m) | |
(Monoid w, PrimMonad m) => PrimMonad (AccumT w m) | Since: primitive-0.6.3.0 |
(Error e, PrimMonad m) => PrimMonad (ErrorT e m) | |
PrimMonad m => PrimMonad (ExceptT e m) | |
PrimMonad m => PrimMonad (IdentityT m) | |
PrimMonad m => PrimMonad (ReaderT r m) | |
PrimMonad m => PrimMonad (SelectT r m) | |
PrimMonad m => PrimMonad (StateT s m) | |
PrimMonad m => PrimMonad (StateT s m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
PrimMonad m => PrimMonad (ContT r m) | Since: primitive-0.6.3.0 |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |