HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

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
datadata Ix0
#

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.

Instances4Eq, Ord, Show, NFData
  • Eq Ix0Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Ord Ix0Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Show Ix0Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • NFData Ix0Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
typetype Ix1 = Int
#

A type synonym for 1-dimensional index, i.e. Int.

Example1 expression
5 :: Ix15
patternpattern Ix1 :: Int -> Ix1
#

This is a very handy pattern synonym to indicate that any arbitrary Integral literal is an Int, e.g. a 1-dimensional index: (Ix1 5) == (5 :: Int)

Example2 expressions
Ix1 55:t Ix1 5Ix1 5 :: Ix1
datadata Ix2
#

2-dimensional index. This is also a base index for higher dimensions.

Constructors

Instances22Bounded, Eq, Num, Ord, Show, Ix, …
  • Bounded Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Eq Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Num Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Ord Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Show Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Ix Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • NFData Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Random Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Uniform Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • UniformRange Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Unbox Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix

    Unboxing of a Ix2.

  • Index Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • MVector MVector Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Vector Vector Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Shape L Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.List
  • Load DW Ix2 eDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed
  • Ragged L Ix2 eDefined in massiv-1.0.5.0 · Data.Massiv.Core.List
  • StrideLoad DW Ix2 eDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed
  • data MVector s Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • data Vector Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • type Dimensions Ix2 = 2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • type Lower Ix2 = Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
patternpattern Ix2 :: Int -> Int -> Ix2
#

2-dimensional index constructor. Useful when infix notation is inconvenient. (Ix2 i j) == (i :. j)

datadata IxN (n :: Nat)
#

n-dimensional index. Needs a base case, which is the Ix2.

Constructors

Instances26Shape, Load, Ragged, StrideLoad, Bounded, Eq, …
patternpattern Ix3 :: Int -> Int -> Int -> Ix3
#

3-dimensional index constructor. (Ix3 i j k) == (i :> j :. k)

patternpattern Ix4 :: Int -> Int -> Int -> Int -> Ix4
#

4-dimensional index constructor. (Ix4 i j k l) == (i :> j :> k :. l)

patternpattern Ix5 :: Int -> Int -> Int -> Int -> Int -> Ix5
#

5-dimensional index constructor. (Ix5 i j k l m) == (i :> j :> k :> l :. m)

typetype Ix3 = IxN 3
#

3-dimensional type synonym. Useful as a alternative to enabling DataKinds and using type level Nats.

typetype Ix4 = IxN 4
#

4-dimensional type synonym.

typetype Ix5 = IxN 5
#

5-dimensional type synonym.

familytype family Ix (n :: Nat) where
#

Defines n-dimensional index by relating a general IxN with few base cases.

Equations

Size

typetype Sz1 = Sz Ix1
#

1-dimensional type synonym for size.

typetype Sz2 = Sz Ix2
#

2-dimensional size type synonym.

typetype Sz3 = Sz Ix3
#

3-dimensional size type synonym.

typetype Sz4 = Sz Ix4
#

4-dimensional size type synonym.

typetype Sz5 = Sz Ix5
#

5-dimensional size type synonym.

newtypenewtype Sz ix
#

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
Example2 expressions
import Data.Massiv.ArraySz (1 :> 2 :. 3)Sz (1 :> 2 :. 3)

Sz has a Num instance, which is very convenient:

Example1 expression
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.

Example1 expression
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.Internal

    Calling negate is an error.

  • Ord ix => Ord (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Index ix => Show (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • NFData 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.Internal
  • UniformRange ix => UniformRange (Sz ix)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
patternpattern Sz :: Index ix => ix -> Sz ix
#

A safe bidirectional pattern synonym for Sz construction that will make sure that none of the size elements are negative.

patternpattern Sz1 :: Ix1 -> Sz Ix1
#

1-dimensional size constructor. Especially useful with literals: (Sz1 5) == Sz (5 :: Int).

patternpattern Sz2 :: Int -> Int -> Sz Ix2
#

2-dimensional size constructor. (Sz2 i j) == Sz (i :. j)

patternpattern Sz3 :: Int -> Int -> Int -> Sz Ix3
#

3-dimensional size constructor. (Sz3 i j k) == Sz (i :> j :. k)

patternpattern Sz4 :: Int -> Int -> Int -> Int -> Sz Ix4
#

4-dimensional size constructor. (Sz4 i j k l) == Sz (i :> j :> k :. l)

patternpattern Sz5 :: Int -> Int -> Int -> Int -> Int -> Sz Ix5
#

5-dimensional size constructor. (Sz5 i j k l m) == Sz (i :> j :> k :> l :. m)

valueunSz :: Sz ix -> ix
#

Function for unwrapping Sz.

Example
Example2 expressions
import Data.Massiv.Core.IndexunSz $ Sz3 1 2 31 :> 2 :. 3
valuezeroSz :: Index ix => Sz ix
#

An empty size with all elements in size equal to 0.

Example
Example2 expressions
import Data.Massiv.Core.IndexzeroSz :: Sz5Sz (0 :> 0 :> 0 :> 0 :. 0)
valueoneSz :: Index ix => Sz ix
#

A singleton size with all elements in size equal to 1.

Example
Example2 expressions
import Data.Massiv.Core.IndexoneSz :: Sz3Sz (1 :> 1 :. 1)
valueliftSz :: Index ix => (Int -> Int) -> Sz ix -> Sz ix
#

Same as liftIndex, but for Sz

Example
Example2 expressions
import Data.Massiv.Core.IndexliftSz succ (Sz2 2 3)Sz (3 :. 4)
valueliftSz2 :: Index ix => (Int -> Int -> Int) -> Sz ix -> Sz ix -> Sz ix
#

Same as liftIndex2, but for Sz

Example
Example2 expressions
import Data.Massiv.Core.IndexliftSz2 (-) (Sz2 2 3) (Sz2 3 1)Sz (0 :. 2)
valueconsSz :: Index ix => Sz Ix1 -> Sz (Lower ix) -> Sz ix
#

Same as consDim, but for Sz

Example
Example2 expressions
import Data.Massiv.Core.IndexconsSz (Sz1 1) (Sz2 2 3) :: Sz3Sz (1 :> 2 :. 3)
valueunconsSz :: Index ix => Sz ix -> (Sz Ix1, Sz (Lower ix))
#

Same as unconsDim, but for Sz

Example
Example2 expressions
import Data.Massiv.Core.IndexunconsSz $ Sz3 1 2 3(Sz1 1,Sz (2 :. 3))
valuesnocSz :: Index ix => Sz (Lower ix) -> Sz Ix1 -> Sz ix
#

Same as snocDim, but for Sz

Example
Example2 expressions
import Data.Massiv.Core.IndexsnocSz (Sz2 2 3) (Sz1 1) :: Sz3Sz (2 :> 3 :. 1)
valueunsnocSz :: Index ix => Sz ix -> (Sz (Lower ix), Sz Ix1)
#

Same as unsnocDim, but for Sz

Example
Example2 expressions
import Data.Massiv.Core.IndexunsnocSz $ Sz3 1 2 3(Sz (1 :. 2),Sz1 3)
valuesetSzM :: (MonadThrow m, Index ix) => Sz ix -> Dim -> Sz Int -> m (Sz ix)
#

Same as setDimM, but for Sz

Example
Example3 expressions
import Data.Massiv.Core.IndexsetSzM (Sz2 2 3) 2 (Sz1 1) :: IO Sz2Sz (1 :. 3)setSzM (Sz2 2 3) 3 (Sz1 1) :: IO Sz2*** Exception: IndexDimensionException: (Dim 3) for (2 :. 3)
valueinsertSzM
  1. :: (MonadThrow m, Index ix)
  2. => Sz (Lower ix)
  3. -> Dim
  4. -> Sz Int
  5. -> m (Sz ix)
#

Same as insertDimM, but for Sz

Example
Example3 expressions
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)
valuepullOutSzM
  1. :: (MonadThrow m, Index ix)
  2. => Sz ix
  3. -> Dim
  4. -> m (Sz Ix1, Sz (Lower ix))
#

Same as pullOutDim, but for Sz

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

Dimension

newtypenewtype Dim
#

A way to select Array dimension at a value level.

Constructors

Instances11Enum, Eq, Integral, Num, Ord, Real, …
  • Enum DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Eq DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Integral DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Num DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Ord DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Real DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Show DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • NFData DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Random DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Uniform DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • UniformRange DimDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal

Stride

newtypenewtype Stride ix
#

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:
  • Default and minimal stride of Stride (pureIndex 1) will have no affect and all elements will kept.

  • 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, …
patternpattern Stride :: Index ix => ix -> Stride ix
#

A safe bidirectional pattern synonym for Stride construction that will make sure stride elements are always positive.

Border

datadata Border e
#

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 e

    Fill in a constant element.

               outside |  Array  | outside
    (Fill 0) : 0 0 0 0 | 1 2 3 4 | 0 0 0 0
    
  • Wrap

    Wrap around from the opposite border of the array.

               outside |  Array  | outside
    Wrap :     1 2 3 4 | 1 2 3 4 | 1 2 3 4
    
  • Edge

    Replicate the element at the edge.

               outside |  Array  | outside
    Edge :     1 1 1 1 | 1 2 3 4 | 4 4 4 4
    
  • Reflect

    Mirror like reflection.

               outside |  Array  | outside
    Reflect :  4 3 2 1 | 1 2 3 4 | 4 3 2 1
    
  • Continue

    Also 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
  • Functor BorderDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index
  • Eq e => Eq (Border e)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index
  • Show e => Show (Border e)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index
  • NFData e => NFData (Border e)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index
valuehandleBorderIndex
  1. :: Index ix
  2. => Border e

    Broder resolution technique

  3. -> Sz ix

    Size

  4. -> (ix -> e)

    Index function that produces an element

  5. -> ix

    Index

  6. -> e
#

Apply a border resolution technique to an index

Examples
Example3 expressions
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

familytype family Lower ix
#

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.Internal
  • type Lower Ix2 = Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • type Lower Ix2T = Ix1TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • type Lower Ix3T = Ix2TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • type Lower Ix4T = Ix3TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • type Lower Ix5T = Ix4TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • type Lower (IxN n) = Ix (n - 1)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
classclass (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 where
#

This 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 :: Nat

    Type level information on how many dimensions this index has.

Methods

Instances8Index, …
  • Index Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Internal
  • Index Ix2Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • Index Ix2TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • Index Ix3TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • Index Ix4TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • Index Ix5TDefined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Tuple · orphan
  • Index (IxN 3)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
  • HighIxN n => Index (IxN n)Defined in massiv-1.0.5.0 · Data.Massiv.Core.Index.Ix
valuezeroIndex :: Index ix => ix
#

Index with all zeros

Examples
Example1 expression
zeroIndex :: Ix40 :> 0 :> 0 :. 0
valueisZeroSz :: Index ix => Sz ix -> Bool
#

Checks whether size can hold at least one element.

Examples
Example1 expression
isZeroSz (Sz3 1 0 2)True
valueisNotZeroSz :: Index ix => Sz ix -> Bool
#

Checks whether size can hold at least one element.

Examples
Example1 expression
isNotZeroSz (Sz3 1 0 2)False
valueheadDim :: Index ix => ix -> Int
#

Get the outmost dimension of the index.

Examples
Example1 expression
headDim (2 :> 3 :> 4 :. 5)2
valuetailDim :: Index ix => ix -> Lower ix
#

Drop the outmost dimension from the index

Examples
Example1 expression
tailDim (2 :> 3 :> 4 :. 5)3 :> 4 :. 5
valuelastDim :: Index ix => ix -> Int
#

Get the innermost dimension from the index

Examples
Example1 expression
lastDim (2 :> 3 :> 4 :. 5)5
valueinitDim :: Index ix => ix -> Lower ix
#

Drop the innermost dimension from the index

Examples
Example1 expression
initDim (2 :> 3 :> 4 :. 5)2 :> 3 :. 4
valuegetDim' :: (HasCallStack, Index ix) => ix -> Dim -> Int
#

Change the value from a specific dimension within the index. See getDimM for a safer version and getDimension for a type safe version.

Examples
Example1 expression
getDim' (2 :> 3 :> 4 :. 5) 33
valuesetDim' :: (HasCallStack, Index ix) => ix -> Dim -> Int -> ix
#

Change the value of a specific dimension within the index. See setDimM for a safer version and setDimension for a type safe version.

Examples
Example1 expression
setDim' (2 :> 3 :> 4 :. 5) 3 102 :> 10 :> 4 :. 5
valuedropDimM :: (MonadThrow m, Index ix) => ix -> Dim -> m (Lower ix)
#

Remove a dimension from the index.

Examples
Example2 expressions
dropDimM (2 :> 3 :> 4 :. 5) 3 :: Maybe Ix3Just (2 :> 4 :. 5)dropDimM (2 :> 3 :> 4 :. 5) 6 :: Maybe Ix3Nothing
valuedropDim' :: (HasCallStack, Index ix) => ix -> Dim -> Lower ix
#

Remove a dimension from the index.

Examples
Example1 expression
dropDim' (2 :> 3 :> 4 :. 5) 32 :> 4 :. 5
valueinsertDim' :: (HasCallStack, Index ix) => Lower ix -> Dim -> Int -> ix
#

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
Example1 expression
insertDim' (2 :> 3 :> 4 :. 5) 3 10 :: Ix52 :> 3 :> 10 :> 4 :. 5
valuefromDimension :: KnownNat n => Dimension n -> Dim
#

Get the value level Dim from the type level equivalent.

Examples
Example3 expressions
fromDimension Dim4(Dim 4):set -XDataKindsfromDimension (DimN :: Dimension 10)(Dim 10)
valuegetDimension :: IsIndexDimension ix n => ix -> Dimension n -> Int
#

Type safe way to extract value of index at a particular dimension.

Examples
Example1 expression
getDimension (2 :> 3 :> 4 :. 5) Dim24
valuesetDimension :: IsIndexDimension ix n => ix -> Dimension n -> Int -> ix
#

Type safe way to set value of index at a particular dimension.

Examples
Example1 expression
setDimension (2 :> 3 :> 4 :. 5) Dim4 1010 :> 3 :> 4 :. 5
valuemodifyDimension
  1. :: IsIndexDimension ix n
  2. => ix
  3. -> Dimension n
  4. -> Int -> Int
  5. -> (Int, ix)
#

Type safe way to set value of index at a particular dimension.

Examples
Example1 expression
modifyDimension (2 :> 3 :> 4 :. 5) Dim3 (+ 2)(3,2 :> 5 :> 4 :. 5)
valuedropDimension :: IsIndexDimension ix n => ix -> Dimension n -> Lower ix
#

Type safe way of dropping a particular dimension, thus lowering index dimensionality.

Examples
Example1 expression
dropDimension (2 :> 3 :> 4 :. 5) Dim22 :> 3 :. 5
valuepullOutDimension
  1. :: IsIndexDimension ix n
  2. => ix
  3. -> Dimension n
  4. -> (Int, Lower ix)
#

Type safe way of pulling out a particular dimension, thus lowering index dimensionality and returning the value at specified dimension.

Examples
Example1 expression
pullOutDimension (2 :> 3 :> 4 :. 5) Dim2(4,2 :> 3 :. 5)
valueinsertDimension
  1. :: IsIndexDimension ix n
  2. => Lower ix
  3. -> Dimension n
  4. -> Int
  5. -> ix
#

Type safe way of inserting a particular dimension, thus raising index dimensionality.

Examples
Example5 expressions
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 declarations
valueiter
  1. :: Index ix
  2. => ix

    Start index

  3. -> ix

    End index

  4. -> ix

    Increment

  5. -> (Int -> Int -> Bool)

    Continuation condition

  6. -> a

    Accumulator

  7. -> (ix -> a -> a)

    Iterating function

  8. -> a
#

Row-major iterator for the index. Same as iterM, but pure.

Examples
Example2 expressions
iter (Ix1 0) 1000 1 (<) 0 (+)499500iter (0 :. 0) (2 :. 3) oneIndex (<) 100 $ \ (i :. j) acc -> (acc + i) * (j + 1)3615
valueiterA_
  1. :: (Index ix, Applicative f)
  2. => ix

    Starting index

  3. -> ix

    Ending index (not included)

  4. -> ix

    Stepping index

  5. -> (Int -> Int -> Bool)

    Continuation function. Loop will stop on False

  6. -> (ix -> f a)

    Action applied to an index. Result is ignored.

  7. -> f ()
#

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.

valueiterM_
  1. :: (Index ix, Monad m)
  2. => ix
  3. -> ix
  4. -> ix
  5. -> Int -> Int -> Bool
  6. -> ix -> m a
  7. -> m ()
#

Deprecated. In favor of more lax iterA_

Same as iterM, but don't bother with accumulator and return value.

valueiterLinearM
  1. :: (Index ix, Monad m)
  2. => Sz ix

    Size

  3. -> Int

    Linear start (must be non-negative)

  4. -> Int

    Linear end (must be less than or equal to totalElem sz)

  5. -> Int

    Increment (must not be zero)

  6. -> (Int -> Int -> Bool)

    Continuation condition (continue if True)

  7. -> a

    Accumulator

  8. -> (Int -> ix -> a -> m a)
  9. -> m a
#

Iterate over N-dimensional space linearly from start to end in row-major fashion with an accumulator

Examples
Example2 expressions
sz = Sz2 3 4iterLinearM sz 0 3 1 (<) 100 $ \ k ix acc -> (acc + k) <$ print (fromLinearIndex sz k == ix)TrueTrueTrue103
valueiterLinearM_
  1. :: (Index ix, Monad m)
  2. => Sz ix

    Size

  3. -> Int

    Start (must be non-negative)

  4. -> Int

    End

  5. -> Int

    Increment (must not be zero)

  6. -> (Int -> Int -> Bool)

    Continuation condition (continue if True)

  7. -> (Int -> ix -> m ())

    Monadic action that takes index in both forms

  8. -> m ()
#

Same as iterLinearM, except without an accumulator.

Examples
Example2 expressions
sz = Sz2 3 4iterLinearM_ sz 0 3 1 (<) $ \ k ix -> print (toLinearIndex sz ix == k)TrueTrueTrue
valueiloopA_
  1. :: Applicative f
  2. => Int
  3. -> Int
  4. -> Int -> Bool
  5. -> Int -> Int
  6. -> Int -> Int -> f a
  7. -> f ()
#

Efficient monadic loop with extra linear index incremented by 1.

Example1 expression
iloopA_ 100 1 (< 10) (+ 2) (\i ix -> print (i, ix))(100,1)(101,3)(102,5)(103,7)(104,9)
valueiloopM
  1. :: Monad m
  2. => Int
  3. -> Int
  4. -> Int -> Bool
  5. -> Int -> Int
  6. -> a
  7. -> Int -> Int -> a -> m a
  8. -> m a
#

Efficient monadic loop with an accumulator and extra linear index incremented by 1.

Example1 expression
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)]
valueiterLinearAccST
  1. :: Int
  2. -> Scheduler s a
  3. -> Int
  4. -> Int

    Step. Must be non-zero

  5. -> Int
  6. -> a
  7. -> (a -> ST s (a, a))
  8. -> (Int -> a -> ST s a)
  9. -> ST s a
#

Linear iterator that supports multiplying factor and accumulator. Results of actions are stored in the scheduler.

valueloopA_
  1. :: Applicative f
  2. => Int
  3. -> Int -> Bool
  4. -> Int -> Int
  5. -> Int -> f a
  6. -> f ()
#

Efficient Applicative loop. Result of each iteration is discarded.

loopA_ initial cond incr f === loopA initial cond incr (pure ()) (\i -> id <$ f i)
valueloopDeepM
  1. :: Monad m
  2. => Int
  3. -> Int -> Bool
  4. -> Int -> Int
  5. -> a
  6. -> Int -> a -> m a
  7. -> m a
#

Similar to loopM, but way less efficient monadic loop with an accumulator that reverses the direction of action application. eg:

Example1 expression
loopDeepM 1 (< 20) (+ 2) [] (\i a -> Just (i:a))Just [1,3,5,7,9,11,13,15,17,19]

Equivalent to:

Example1 expression
loopM 19 (>= 1) (subtract 2) [] (\i a -> Just (i:a))Just [1,3,5,7,9,11,13,15,17,19]
valueloopM
  1. :: Monad m
  2. => Int
  3. -> Int -> Bool
  4. -> Int -> Int
  5. -> a
  6. -> Int -> a -> m a
  7. -> m a
#

Efficient monadic loop with an accumulator

Example1 expression
loopM 1 (< 20) (+ 2) [] (\i a -> Just (i:a))Just [19,17,15,13,11,9,7,5,3,1]
valuesplitLinearly
  1. :: Int

    Number of chunks

  2. -> Int

    Total length

  3. -> (Int -> Int -> a)

    Function that accepts a chunk length and slack start index

  4. -> a
#

Divide length in chunks and apply a function to the computed results

valuesplitWorkWithFactorST
  1. :: Int

    Multiplying 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.

  2. -> Scheduler s a
  3. -> Int

    Starting index

  4. -> Int

    Stepping value. Can be negative, but must not be zero.

  5. -> Int

    Total number of steps to be taken

  6. -> b

    Initial value for an accumulator

  7. -> (b -> ST s (b, b))

    An action to split accumulator for multiple threads

  8. -> (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

  9. -> 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

classclass Iterator it where
#

Methods

Instances3Iterator
newtypenewtype RowMajor
#

Default iterator that parallelizes work in linear chunks. Supplied factor will be used to schedule that many jobs per capability.

Instances1Iterator
newtypenewtype RowMajorUnbalanced
#

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
valuefromIx2 :: Ix2 -> Ix2T
#

Convert an Ix2 to Int tuple

Example
Example1 expression
fromIx2 (2 :. 3)(2,3)
valuefromIx3 :: Ix3 -> Ix3T
#

Convert an Ix3 to Int 3-tuple

Example
Example1 expression
fromIx3 (1 :>  2 :. 3)(1,2,3)
valuefromIx4 :: Ix4 -> Ix4T
#

Convert an Ix4 to Int 4-tuple

Example
Example1 expression
fromIx4 (1 :> 2 :> 3 :. 4)(1,2,3,4)
valuefromIx5 :: Ix5 -> Ix5T
#

Convert an Ix5 to Int 5-tuple

Example
Example1 expression
fromIx5 (1 :> 2 :> 3 :> 4 :. 5)(1,2,3,4,5)
valuetoIx2 :: Ix2T -> Ix2
#

Convert an Int tuple to Ix2

Example
Example1 expression
toIx2 (2, 3)2 :. 3
valuetoIx3 :: Ix3T -> Ix3
#

Convert a Int 3-tuple to Ix3

Example
Example1 expression
toIx3 (1, 2, 3)1 :> 2 :. 3
valuetoIx4 :: Ix4T -> Ix4
#

Convert a Int 4-tuple to Ix4

Example
Example1 expression
toIx4 (1, 2, 3, 4)1 :> 2 :> 3 :. 4
valuetoIx5 :: Ix5T -> Ix5
#

Convert a Int 5-tuple to Ix5

Example
Example1 expression
toIx5 (1, 2, 3, 4, 5)1 :> 2 :> 3 :> 4 :. 5
typetype Ix1T = Int
#

Another 1-dimensional index type synonym for Int, same as Ix1 and is here just for consistency.

Exceptions

6 declarations
datadata IndexException where
#

Exceptions that get thrown when there is a problem with an index, size or dimension.

Constructors

Instances4Eq, Show, Exception, NFData
datadata SizeException where
#

Exception that indicates an issue with an array size.

Constructors

Instances4Eq, Show, Exception, NFData
datadata ShapeException
#

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

Instances3Eq, Show, Exception
valueindexAssert :: String -> (a -> Sz ix) -> (a -> ix -> e) -> a -> ix -> e
#

This is used by the unsafe-checks cabal flag.

valueindexWith
  1. :: Index ix
  2. => String

    Source file name, eg. "srcDataMassivCoreIndex.hs"

  3. -> Int

    Line number in th source file, eg. 663

  4. -> String
  5. -> (arr -> Sz ix)

    Get size of the array

  6. -> (arr -> ix -> e)

    Indexing function

  7. -> arr

    Array

  8. -> ix

    Index

  9. -> e
#

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.