Zero-dimension, i.e. a scalar. Can't really be used directly as there is no instance of Index for it, and is included for completeness.
Modulemassiv-1.0.5.0Haskell2010
Data.Massiv.Core.Index
- 30 types
- 2 classes
- 94 values
- Packagemassiv-1.0.5.0
- Exports149
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceInternal.hs
A type synonym for 1-dimensional index, i.e. Int.
5 :: Ix15
Instances22Bounded, Eq, Num, Ord, Show, Ix, …
Bounded Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxEq Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxNum Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxOrd Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxShow Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxIx Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxNFData Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxRandom Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxUniform Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxUniformRange Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxUnbox Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxUnboxing of a Ix2.
Index Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxMVector MVector Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxVector Vector Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxShape L Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.ListLoad DW Ix2 eDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.WindowedRagged L Ix2 eDefined in massiv-1.0.5.0 · Data.Massiv.Core.ListStrideLoad DW Ix2 eDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windoweddata MVector s Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixdata Vector Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixtype Dimensions Ix2 =Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix2
type Lower Ix2 = Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
2-dimensional index constructor. Useful when infix notation is inconvenient. (Ix2 i j) == (i :. j)
Instances26Shape, Load, Ragged, StrideLoad, Bounded, Eq, …
Bounded Ix3Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxNum Ix3Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix(Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix3
<= n, Unbox (Ix (n -1
))) => MVector MVector (IxN n)(Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix3
<= n, Unbox (Ix (n -1
))) => Vector Vector (IxN n)(Shape L (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.List1
)), Index (IxN n)) => Shape L (IxN n)(Index (IxN n), Load DW (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed1
)) e) => Load DW (IxN n) e(Shape L (IxN n), Ragged L (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.List1
)) e, Coercible (Elt (Ix (n -1
)) e) (ListItem (Ix (n -1
)) e)) => Ragged L (IxN n) e(Index (IxN n), StrideLoad DW (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed1
)) e) => StrideLoad DW (IxN n) eHighIxN n => Bounded (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxEq (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => Eq (IxN n)HighIxN n => Num (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxOrd (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => Ord (IxN n)Show (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => Show (IxN n)Ix (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => Ix (IxN n)NFData (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxRandom (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => Random (IxN n)Uniform (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => Uniform (IxN n)UniformRange (Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)) => UniformRange (IxN n)(Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix3
<= n, Unbox (Ix (n -1
))) => Unbox (IxN n)Unboxing of a IxN.
Index (IxNDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix3
)HighIxN n => Index (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixdata MVector s (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixdata Vector (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixtype Dimensions Ix3 =Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix3
type Dimensions (IxN n) = nDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixtype Lower (IxN n) = Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)
3-dimensional index constructor. (Ix3 i j k) == (i :> j :. k)
4-dimensional index constructor. (Ix4 i j k l) == (i :> j :> k :. l)
5-dimensional index constructor. (Ix5 i j k l m) == (i :> j :> k :> l :. m)
type HighIxN (n :: Natural) = (4
<= n, KnownNat n, KnownNat (n - 1
), Index (IxN (n - 1
)), IxN (n - 1
) ~ Ix (n - 1
))Constraint synonym that encapsulates all constraints needed for dimension 4 and higher.
3-dimensional type synonym. Useful as a alternative to enabling DataKinds and using type
level Nats.
4-dimensional type synonym.
5-dimensional type synonym.
Size
1-dimensional type synonym for size.
2-dimensional size type synonym.
3-dimensional size type synonym.
4-dimensional size type synonym.
5-dimensional size type synonym.
Sz is the size of the array. It describes total number of elements along
each dimension in the array. It is a wrapper around an index of the same
dimension, however it provides type safety preventing mixup with
index. Moreover the Sz constructor and others such as
Sz1, Sz2, ... that
are specialized to specific dimensions, prevent creation of invalid sizes with
negative values by clamping them to zero.
Examples
import Data.Massiv.ArraySz (1 :> 2 :. 3)Sz (1 :> 2 :. 3)
Sz has a Num instance, which is very convenient:
Sz (1 :> 2 :. 3) + 5Sz (6 :> 7 :. 8)
However subtraction can sometimes lead to surprising behavior, because size is not allowed to take negative values it will be clamped at 0.
Sz (1 :> 2 :. 3) - 2Sz (0 :> 0 :. 1)
Warning: It is always wrong to negate a size, thus it will result in an
error. For that reason also watch out for partially applied (- sz), which is
deugared into negate sz. See more info about it in
#114.
Instances8Eq, Num, Ord, Show, NFData, Random, …
Eq ix => Eq (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal(Num ix, Index ix) => Num (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalCalling negate is an error.
Ord ix => Ord (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalIndex ix => Show (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalNFData ix => NFData (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal(UniformRange ix, Index ix) => Random (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal(UniformRange ix, Index ix) => Uniform (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalUniformRange ix => UniformRange (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
A safe bidirectional pattern synonym for Sz construction that will make sure that none of the size elements are negative.
1-dimensional size constructor. Especially useful with literals: (Sz1 5) == Sz (5 :: Int).
2-dimensional size constructor. (Sz2 i j) == Sz (i :. j)
3-dimensional size constructor. (Sz3 i j k) == Sz (i :> j :. k)
4-dimensional size constructor. (Sz4 i j k l) == Sz (i :> j :> k :. l)
5-dimensional size constructor. (Sz5 i j k l m) == Sz (i :> j :> k :> l :. m)
Function for unwrapping Sz.
Example
import Data.Massiv.Core.IndexunSz $ Sz3 1 2 31 :> 2 :. 3
An empty size with all elements in size equal to 0.
Example
import Data.Massiv.Core.IndexzeroSz :: Sz5Sz (0 :> 0 :> 0 :> 0 :. 0)
A singleton size with all elements in size equal to 1.
Example
import Data.Massiv.Core.IndexoneSz :: Sz3Sz (1 :> 1 :. 1)
Same as liftIndex2, but for Sz
Example
import Data.Massiv.Core.IndexliftSz2 (-) (Sz2 2 3) (Sz2 3 1)Sz (0 :. 2)
Same as insertDimM, but for Sz
Example
import Data.Massiv.Core.IndexinsertSzM (Sz2 2 3) 3 (Sz1 1) :: IO Sz3Sz (1 :> 2 :. 3)insertSzM (Sz2 2 3) 4 (Sz1 1) :: IO Sz3*** Exception: IndexDimensionException: (Dim 4) for (2 :. 3)
Same as pullOutDim, but for Sz
import Data.Massiv.Core.IndexpullOutSzM (Sz3 1 2 3) 3(Sz1 1,Sz (2 :. 3))pullOutSzM (Sz3 1 2 3) 0*** Exception: IndexDimensionException: (Dim 0) for (1 :> 2 :. 3)
Convert a size to a linear size.
Construct size from index while checking its correctness. Throws SizeNegativeException and SizeOverflowException.
Dimension
Instances11Enum, Eq, Integral, Num, Ord, Real, …
Enum DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalEq DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalIntegral DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalNum DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalOrd DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalReal DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalShow DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalNFData DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalRandom DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalUniform DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalUniformRange DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
Construct 1st dimension
Construct 2nd dimension
Construct 3rd dimension
Construct 4th dimension
Construct 5th dimension
A type level constraint that ensures index is indeed valid and that supplied dimension can be safely used with it.
Equations
IsDimValid ix n = ReportInvalidDim (Dimensions ix) n (1
<=? n) (n <=? Dimensions ix)
type family ReportInvalidDim (dims :: Nat) (n :: Nat) (isNotZero :: Bool) (isLess :: Bool) :: Bool whereEquations
ReportInvalidDim dims n 'True 'True = 'TrueReportInvalidDim dims n 'True 'False = TypeError (((('Text"Dimension "
':<>: 'ShowType n) ':<>: 'Text" is higher than "
) ':<>: 'Text"the maximum expected "
) ':<>: 'ShowType dims)ReportInvalidDim dims n 'False isLess = TypeError ('Text"Zero dimensional indices are not supported"
)
Stride
Stride provides a way to ignore elements of an array if an index is divisible by a
corresponding value in a stride. So, for a Stride (i :. j) only elements with indices will be
kept around:
( 0 :. 0) ( 0 :. j) ( 0 :. 2j) ( 0 :. 3j) ...
( i :. 0) ( i :. j) ( i :. 2j) ( i :. 3j) ...
(2i :. 0) (2i :. j) (2i :. 2j) (2i :. 3j) ...
...
Only positive strides make sense, so Stride pattern synonym constructor will prevent a user from creating a stride with negative or zero values, thus promoting safety of the library.
Examples:
If stride is
Stride 2, then every 2nd element (i.e. with index 1, 3, 5, ..) will be skipped and only elemnts with indices divisible by 2 will be kept around.In case of two dimensions, if what you want is to keep all rows divisible by 5, but keep every column intact then you'd use
Stride (5 :. 1).
Instances7Eq, Ord, Show, NFData, Random, Uniform, …
Eq ix => Eq (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.StrideOrd ix => Ord (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.StrideIndex ix => Show (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.StrideNFData ix => NFData (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Stride(UniformRange ix, Index ix) => Random (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Stride(UniformRange ix, Index ix) => Uniform (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.StrideUniformRange ix => UniformRange (Stride ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Stride
A safe bidirectional pattern synonym for Stride construction that will make sure stride elements are always positive.
Just a helper function for unwrapping Stride.
Compute linear index with stride using the original size and index
Adjust starting index according to the stride
Adjust size according to the stride.
A default stride of 1, where all elements are kept
Border
Approach to be used near the borders during various transformations. Whenever a function needs information not only about an element of interest, but also about it's neighbors, it will go out of bounds near the array edges, hence is this set of approaches that specify how to handle such situation.
Constructors
Fill eFill in a constant element.
outside | Array | outside (Fill 0) : 0 0 0 0 | 1 2 3 4 | 0 0 0 0WrapWrap around from the opposite border of the array.
outside | Array | outside Wrap : 1 2 3 4 | 1 2 3 4 | 1 2 3 4EdgeReplicate the element at the edge.
outside | Array | outside Edge : 1 1 1 1 | 1 2 3 4 | 4 4 4 4ReflectMirror like reflection.
outside | Array | outside Reflect : 4 3 2 1 | 1 2 3 4 | 4 3 2 1ContinueAlso mirror like reflection, but without repeating the edge element.
outside | Array | outside Continue : 1 4 3 2 | 1 2 3 4 | 3 2 1 4
Instances4Functor, Eq, Show, NFData
handleBorderIndex Apply a border resolution technique to an index
Examples
handleBorderIndex (Fill 100) (Sz (2 :. 3)) id (2 :. 3)100 :. 100handleBorderIndex Wrap (Sz (2 :. 3)) id (2 :. 3)0 :. 0handleBorderIndex Edge (Sz (2 :. 3)) id (2 :. 3)1 :. 2
Index functions
This type family will always point to a type for a dimension that is one lower than the type argument.
Instances7Lower, …
type Lower Int = Ix0Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internaltype Lower Ix2 = Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ixtype Lower Ix2T = Ix1TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphantype Lower Ix3T = Ix2TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphantype Lower Ix4T = Ix3TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphantype Lower Ix5T = Ix4TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphantype Lower (IxN n) = Ix (n -Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix1
)
class (Eq ix, Ord ix, Show ix, NFData ix, Typeable ix, Eq (Lower ix), Ord (Lower ix), Show (Lower ix), NFData (Lower ix), KnownNat (Dimensions ix)) => Index ix whereThis is bread and butter of multi-dimensional array indexing. It is unlikely that any of the functions in this class will be useful to a regular user, unless general algorithms are being implemented that do span multiple dimensions.
Associated types
type family Dimensions ix :: NatType level information on how many dimensions this index has.
Methods
dimensions :: proxy ix -> DimWhat is the dimensionality of this index.
totalElem :: Sz ix -> IntTotal number of elements in an array of this size.
consDim :: Int -> Lower ix -> ixPrepend a dimension to the index
unconsDim :: ix -> (Int, Lower ix)Take a dimension from the index from the outside
snocDim :: Lower ix -> Int -> ixApppend a dimension to the index
unsnocDim :: ix -> (Lower ix, Int)Take a dimension from the index from the inside
pullOutDimM :: MonadThrow m => ix -> Dim -> m (Int, Lower ix)Pull out value at specified dimension from the index, thus also lowering it dimensionality.
insertDimM :: MonadThrow m => Lower ix -> Dim -> Int -> m ixInsert a dimension into the index
getDimM :: MonadThrow m => ix -> Dim -> m IntExtract the value index has at specified dimension.
setDimM :: MonadThrow m => ix -> Dim -> Int -> m ixSet the value for an index at specified dimension.
modifyDimM :: MonadThrow m => ix -> Dim -> (Int -> Int) -> m (Int, ix)Update the value for an index at specified dimension and return the old value as well as the updated index.
pureIndex :: Int -> ixLift an Int to any index by replicating the value as many times as there are dimensions.
liftIndex2 :: (Int -> Int -> Int) -> ix -> ix -> ixZip together two indices with a function
liftIndex :: (Int -> Int) -> ix -> ixMap a function over an index
foldlIndex :: (a -> Int -> a) -> a -> ix -> aPerform a left fold over the index
isSafeIndex :: Sz ix -> ix -> BoolCheck whether index is positive and is within the size.
toLinearIndex :: Sz ix -> ix -> Ix1Convert linear index from size and index
toLinearIndexAcc :: Ix1 -> ix -> ix -> Ix1Convert linear index from size and index with an accumulator. Currently is useless and will likely be removed in future versions.
fromLinearIndex :: Sz ix -> Ix1 -> ixCompute an index from size and linear index
fromLinearIndexAcc :: ix -> Ix1 -> (Int, ix)Compute an index from size and linear index using an accumulator, thus trying to optimize for tail recursion while getting the index computed.
repairIndex :: Sz ix -> ix -> (Sz Int -> Int -> Int) -> (Sz Int -> Int -> Int) -> ixA way to make sure index is withing the bounds for the supplied size. Takes two functions that will be invoked whenever index (2nd arg) is outsize the supplied size (1st arg)
iterM :: Monad m => ix -> ix -> ix -> (Int -> Int -> Bool) -> a -> (ix -> a -> m a) -> m aThis function is what makes it possible to iterate over an array of any dimension.
iterRowMajorST :: Int -> Scheduler s a -> ix -> ix -> Sz ix -> a -> (a -> ST s (a, a)) -> (ix -> a -> ST s a) -> ST s aiterF :: ix -> ix -> ix -> (Int -> Int -> Bool) -> f a -> (ix -> f a -> f a) -> f aSimilar to iterM, but no restriction on a Monad.
iterF (-10) 20 4 (<) [] (:) :: [Int] [-10,-6,-2,2,6,10,14,18]
stepNextMF :: ix -> ix -> ix -> (Int -> Int -> Bool) -> (Maybe ix -> f a) -> f aA single step in iteration
iterTargetRowMajorA_ :: Applicative f => Int -> Int -> Sz ix -> ix -> ix -> (Ix1 -> ix -> f a) -> f ()iterTargetRowMajorAccM :: Monad m => Int -> Int -> Sz ix -> ix -> ix -> a -> (Ix1 -> ix -> a -> m a) -> m aiterTargetRowMajorAccST :: Int -> Int -> Scheduler s a -> Int -> Sz ix -> ix -> ix -> a -> (a -> ST s (a, a)) -> (Ix1 -> ix -> a -> ST s a) -> ST s aiterTargetRowMajorAccST_ :: Int -> Int -> Scheduler s () -> Int -> Sz ix -> ix -> ix -> a -> (a -> ST s (a, a)) -> (Ix1 -> ix -> a -> ST s a) -> ST s ()
Instances8Index, …
Index Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalIndex Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IxIndex Ix2TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphanIndex Ix3TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphanIndex Ix4TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphanIndex Ix5TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphanIndex (IxNDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix3
)HighIxN n => Index (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
Index with all zeros
Examples
zeroIndex :: Ix40 :> 0 :> 0 :. 0
Index with all ones
Checks whether size can hold at least one element.
Examples
isZeroSz (Sz3 1 0 2)True
Checks whether size can hold at least one element.
Examples
isNotZeroSz (Sz3 1 0 2)False
Get the outmost dimension of the index.
Examples
headDim (2 :> 3 :> 4 :. 5)2
Drop the outmost dimension from the index
Examples
tailDim (2 :> 3 :> 4 :. 5)3 :> 4 :. 5
Get the innermost dimension from the index
Examples
lastDim (2 :> 3 :> 4 :. 5)5
Drop the innermost dimension from the index
Examples
initDim (2 :> 3 :> 4 :. 5)2 :> 3 :. 4
Change the value from a specific dimension within the index. See getDimM for a safer version and getDimension for a type safe version.
Examples
getDim' (2 :> 3 :> 4 :. 5) 33
Change the value of a specific dimension within the index. See setDimM for a safer version and setDimension for a type safe version.
Examples
setDim' (2 :> 3 :> 4 :. 5) 3 102 :> 10 :> 4 :. 5
Update the value of a specific dimension within the index. See modifyDimM for a safer version and modifyDimension for a type safe version.
Examples
modifyDim' (2 :> 3 :> 4 :. 5) 2 (+ 10)(4,2 :> 3 :> 14 :. 5)
Remove a dimension from the index.
Examples
dropDimM (2 :> 3 :> 4 :. 5) 3 :: Maybe Ix3Just (2 :> 4 :. 5)dropDimM (2 :> 3 :> 4 :. 5) 6 :: Maybe Ix3Nothing
Remove a dimension from the index.
Examples
dropDim' (2 :> 3 :> 4 :. 5) 32 :> 4 :. 5
Lower the dimension of the index by pulling the specified dimension. See pullOutDimM for a safer version and pullOutDimension for a type safe version.
Examples
pullOutDim' (2 :> 3 :> 4 :. 5) 3(3,2 :> 4 :. 5)
Raise the dimension of the index by inserting one in the specified dimension. See insertDimM for a safer version and insertDimension for a type safe version.
Examples
insertDim' (2 :> 3 :> 4 :. 5) 3 10 :: Ix52 :> 3 :> 10 :> 4 :. 5
Get the value level Dim from the type level equivalent.
Examples
fromDimension Dim4(Dim 4):set -XDataKindsfromDimension (DimN :: Dimension 10)(Dim 10)
Type safe way to extract value of index at a particular dimension.
Examples
getDimension (2 :> 3 :> 4 :. 5) Dim24
Type safe way to set value of index at a particular dimension.
Examples
setDimension (2 :> 3 :> 4 :. 5) Dim4 1010 :> 3 :> 4 :. 5
Type safe way to set value of index at a particular dimension.
Examples
modifyDimension (2 :> 3 :> 4 :. 5) Dim3 (+ 2)(3,2 :> 5 :> 4 :. 5)
Type safe way of dropping a particular dimension, thus lowering index dimensionality.
Examples
dropDimension (2 :> 3 :> 4 :. 5) Dim22 :> 3 :. 5
Type safe way of pulling out a particular dimension, thus lowering index dimensionality and returning the value at specified dimension.
Examples
pullOutDimension (2 :> 3 :> 4 :. 5) Dim2(4,2 :> 3 :. 5)
Type safe way of inserting a particular dimension, thus raising index dimensionality.
Examples
insertDimension (2 :> 3 :> 4 :. 5) Dim5 10 :: Ix510 :> 2 :> 3 :> 4 :. 5insertDimension (2 :> 3 :> 4 :. 5) Dim4 10 :: Ix52 :> 10 :> 3 :> 4 :. 5insertDimension (2 :> 3 :> 4 :. 5) Dim3 10 :: Ix52 :> 3 :> 10 :> 4 :. 5insertDimension (2 :> 3 :> 4 :. 5) Dim2 10 :: Ix52 :> 3 :> 4 :> 10 :. 5insertDimension (2 :> 3 :> 4 :. 5) Dim1 10 :: Ix52 :> 3 :> 4 :> 5 :. 10
Iterators
60 declarationsiter Row-major iterator for the index. Same as iterM, but pure.
Examples
iter (Ix1 0) 1000 1 (<) 0 (+)499500iter (0 :. 0) (2 :. 3) oneIndex (<) 100 $ \ (i :. j) acc -> (acc + i) * (j + 1)3615
iterA_ Same as iterM, Iterate over a region with specific step, but using Applicative instead of a Monad and don't bother with accumulator or return value.
iterLinearM Iterate over N-dimensional space linearly from start to end in row-major fashion with an accumulator
Examples
sz = Sz2 3 4iterLinearM sz 0 3 1 (<) 100 $ \ k ix acc -> (acc + k) <$ print (fromLinearIndex sz k == ix)TrueTrueTrue103
iterLinearM_ Same as iterLinearM, except without an accumulator.
Examples
sz = Sz2 3 4iterLinearM_ sz 0 3 1 (<) $ \ k ix -> print (toLinearIndex sz ix == k)TrueTrueTrue
Efficient monadic loop with extra linear index incremented by 1.
iloopA_ 100 1 (< 10) (+ 2) (\i ix -> print (i, ix))(100,1)(101,3)(102,5)(103,7)(104,9)
Efficient monadic loop with an accumulator and extra linear index incremented by 1.
iloopM 100 1 (< 20) (+ 2) [] (\i ix a -> Just ((i, ix) : a))Just [(109,19),(108,17),(107,15),(106,13),(105,11),(104,9),(103,7),(102,5),(101,3),(100,1)]
iterLinearAccST Linear iterator that supports multiplying factor and accumulator. Results of actions are stored in the scheduler.
Linear iterator that supports multiplying factor and accumulator, but the results are discarded.
Linear iterator that supports multiplying factor
Efficient loop with an accumulator
Applicative loop. Use monadic loopM when possible, since it will be more efficient.
Efficient Applicative loop. Result of each iteration is discarded.
loopA_ initial cond incr f === loopA initial cond incr (pure ()) (\i -> id <$ f i)Similar to loopM, but way less efficient monadic loop with an accumulator that reverses the direction of action application. eg:
loopDeepM 1 (< 20) (+ 2) [] (\i a -> Just (i:a))Just [1,3,5,7,9,11,13,15,17,19]
Equivalent to:
loopM 19 (>= 1) (subtract 2) [] (\i a -> Just (i:a))Just [1,3,5,7,9,11,13,15,17,19]
Efficient monadic loop with an accumulator
loopM 1 (< 20) (+ 2) [] (\i a -> Just (i:a))Just [19,17,15,13,11,9,7,5,3,1]
Deprecated. In favor of loopA_
Efficient monadic loop. Result of each iteration is discarded.
Similar to loopM_ except the action accepts not only the value for current step, but also for the next one as well.
Similar to loopM_ except the action accepts not only the value for current step, but also for the next one as well.
Internal version of a scheduleWork that will be replaced by
scheduleWork_ by the compiler whenever action produces ()
splitLinearly Divide length in chunks and apply a function to the computed results
Iterator that expects an action that accepts starting linear index as well as the ending
Iterator that expects an action that accepts starting linear index as well as the ending
Iterator that can be used to split computation jobs
Iterator that can be used to split computation jobs
splitLinearlyWithStatefulM_ :: MonadUnliftIO m=> SchedulerWS ws ()-> IntTotal linear length
-> (Int -> ws -> m b)Element producing action
-> (Int -> b -> m c)Element storing action
-> m ()
Iterator that can be used to split computation jobs, while using a stateful scheduler.
Iterator that can be used to split computation amongst different workers. For monadic generator see splitLinearlyWithM_.
Helper for figuring out the chunk length and slack start
splitWorkWithFactorST :: IntMultiplying factor to be applied to number of workers for number of jobs to schedule. Higher the factor, more jobs will be scheduled. Only positive values are valid.
-> Scheduler s a-> IntStarting index
-> IntStepping value. Can be negative, but must not be zero.
-> IntTotal number of steps to be taken
-> bInitial value for an accumulator
-> (b -> ST s (b, b))An action to split accumulator for multiple threads
-> (Int -> Int -> Int -> Int -> b -> ST s a)A job to be scheduled. Accepts:
Chunk index start
Chunk length
Chunk start index adjusted for supplied start and stepping value
Chunk stop index adjusted for supplied start and stepping value
-> ST s b
This is a major helper function for fair splitting and parallelization of work with ability to use some arbitrary accumulator and splittable seed
Helper for adjusting stride of a chunk
Selects an optimal scheduler for the supplied strategy, but it works only in IO
Default row major iterator with multiplying factor set to 8.
Methods
iterTargetA_ :: (Index ix, Applicative f) => it -> Int -> Sz ix -> ix -> Stride ix -> (Ix1 -> ix -> f a) -> f ()Iterate over a target region using linear index with access to the source index, which adjusted according to the stride. Use iterTargetM if you need an accumulator.
iterTargetM :: (Index ix, Monad m) => it -> Ix1 -> Sz ix -> ix -> Stride ix -> a -> (Ix1 -> ix -> a -> m a) -> m aIterate over a target region using linear index with access to the source index, which adjusted according to the stride.
iterTargetWithStrideAccST :: Index ix => it -> Scheduler s a -> Ix1 -> Sz ix -> ix -> Stride ix -> a -> (a -> ST s (a, a)) -> (Ix1 -> ix -> a -> ST s a) -> ST s aiterTargetWithStrideAccST_ :: Index ix => it -> Scheduler s () -> Ix1 -> Sz ix -> ix -> Stride ix -> a -> (a -> ST s (a, a)) -> (Ix1 -> ix -> a -> ST s a) -> ST s ()iterFullM :: (Index ix, Monad m) => it -> ix -> Sz ix -> a -> (ix -> a -> m a) -> m aIterate over a region with a monadic action and accumulator.
iterFullA_ :: (Index ix, Applicative f) => it -> ix -> Sz ix -> (ix -> f a) -> f ()Iterate over a region with an applicative action ignoring the result.
iterFullAccST :: Index ix => it -> Scheduler s a -> ix -> Sz ix -> a -> (a -> ST s (a, a)) -> (ix -> a -> ST s a) -> ST s aIterate over a region in a ST monad with access to Scheduler.
iterTargetFullAccST :: Index ix => it -> Scheduler s a -> Ix1 -> Sz ix -> a -> (a -> ST s (a, a)) -> (Ix1 -> ix -> a -> ST s a) -> ST s aiterTargetFullAccST_ :: Index ix => it -> Scheduler s () -> Ix1 -> Sz ix -> a -> (a -> ST s (a, a)) -> (Ix1 -> ix -> a -> ST s a) -> ST s ()iterTargetFullST_ :: Index ix => it -> Scheduler s () -> Ix1 -> Sz ix -> (Ix1 -> ix -> ST s ()) -> ST s ()iterTargetWithStrideST_ :: Index ix => it -> Scheduler s () -> Ix1 -> Sz ix -> ix -> Stride ix -> (Ix1 -> ix -> ST s a) -> ST s ()Iterate over a target array with a stride without an accumulator
Instances3Iterator
Iterator RowMajorDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IteratorIterator RowMajorLinearDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.IteratorIterator RowMajorUnbalancedDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Iterator
Default iterator that parallelizes work in linear chunks. Supplied factor will be used to schedule that many jobs per capability.
Constructors
Instances1Iterator
Iterator RowMajorLinearDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Iterator
Parallelizing unbalanced computation (i.e. computing some elements of the array is much more expensive then the others) it can be benefitial to interleave iteration. Perfect example of this would be a ray tracer or the Mandelbrot set.
iteration without parallelization is equivalent to RowMajor
Instances1Iterator
Iterator RowMajorUnbalancedDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Iterator
2-dimensional index as tuple of Ints.
3-dimensional index as 3-tuple of Ints.
4-dimensional index as 4-tuple of Ints.
5-dimensional index as 5-tuple of Ints.
Exceptions
6 declarationsExceptions that get thrown when there is a problem with an index, size or dimension.
Constructors
IndexZeroException :: Index ix => !ix -> IndexExceptionIndex contains a zero value along one of the dimensions.
IndexDimensionException :: (NFData ix, Eq ix, Show ix, Typeable ix) => !ix -> !Dim -> IndexExceptionDimension is out of reach.
IndexOutOfBoundsException :: Index ix => !Sz ix -> !ix -> IndexExceptionIndex is out of bounds.
Instances4Eq, Show, Exception, NFData
Eq IndexExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalShow IndexExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalException IndexExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalNFData IndexExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
Exception that indicates an issue with an array size.
Constructors
SizeMismatchException :: Index ix => !Sz ix -> !Sz ix -> SizeExceptionTwo sizes are expected to be equal along some or all dimensions, but they are not.
SizeElementsMismatchException :: (Index ix, Index ix') => !Sz ix -> !Sz ix' -> SizeExceptionTotal number of elements does not match between the two sizes.
SizeSubregionException :: Index ix => !Sz ix -> !ix -> !Sz ix -> SizeExceptionDescribed subregion is too big for the specified size.
SizeEmptyException :: Index ix => !Sz ix -> SizeExceptionAn array with the size cannot contain any elements.
SizeOverflowException :: Index ix => !Sz ix -> SizeExceptionTotal number of elements is too large resulting in overflow.
SizeNegativeException :: Index ix => !Sz ix -> SizeExceptionAt least one dimensions contain a negative value.
Instances4Eq, Show, Exception, NFData
Eq SizeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalShow SizeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalException SizeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalNFData SizeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
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.
Constructors
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
ShapeNonEmptyExpected an empty size, but the shape was not empty.
Instances3Eq, Show, Exception
Eq ShapeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalShow ShapeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.InternalException ShapeExceptionDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
Throw SizeElementsMismatchException whenever number of elements in both sizes do not match.
This is used by the unsafe-checks cabal flag.
indexWith Deprecated. In favor of indexAssert that uses HasCallStack
This is used by INDEX_CHECK macro and thus used whenever the unsafe-checks cabal
flag is on.