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.Array.Unsafe

  • 2 types
  • 56 values
  • Packagemassiv-1.0.5.0
  • Exports98
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePush.hs

Creation

2 declarations
valueunsafeMakeLoadArray
  1. :: Index ix
  2. => Comp

    Computation strategy to use. Directly affects the scheduler that gets created for the loading function.

  3. -> Sz ix

    Size of the array

  4. -> Maybe e

    An element to use for initialization of the mutable array that will be created in the future

  5. -> (forall s. Scheduler s () -> Ix1 -> (Ix1 -> e -> ST s ()) -> ST s ())

    This function accepts:

    • A scheduler that can be used for parallelization of loading

    • Linear index at which this load array will start (an offset that should be added to the linear writng function)

    • Linear element writing function

  6. -> Array DL ix e
#

Specify how an array can be loaded/computed through creation of a DL array. Unlike makeLoadArrayS or makeLoadArray this function is unsafe, since there is no guarantee that all elements will be initialized and the supplied element writing function does not perform any bounds checking.

Indexing

6 declarations
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.

Constructors

  • SafeSz ix

    Safe size constructor. It is unsafe to use it without making sure that it does not contain negative components. Use Sz pattern instead.

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

Constructors

Instances7Eq, Ord, Show, NFData, Random, Uniform, …
methodunsafeIndex :: Index ix => Array r ix e -> ix -> e
#

Lookup element in the array. No bounds check is performed and access of arbitrary memory is possible when invalid index is supplied.

methodunsafePrefIndex :: Index ix => Array r ix e -> PrefIndex ix e
#

Alternative indexing function that can choose an index that is most efficient for underlying representation

methodunsafeLinearIndex :: Index ix => Array r ix e -> Int -> e
#

Lookup element in the array using flat index in a row-major fashion. No bounds check is performed

Manipulations

5 declarations
methodunsafeResize
  1. :: (Index ix, Index ix')
  2. => Sz ix'
  3. -> Array r ix e
  4. -> Array r ix' e
#

O(1) - Change the size of an array. Total number of elements should be the same, but it is not validated.

valueunsafeTransform
  1. :: (Index ix', Source r' e', Index ix)
  2. => Sz ix' -> (Sz ix, a)
  3. -> a -> (ix' -> e') -> ix -> e
  4. -> Array r' ix' e'
  5. -> Array D ix e
#

Same Data.Array.transform', except no bounds checking is performed, thus making it faster, but unsafe.

Slicing

4 declarations

Mutable interface

12 declarations
valueunsafeLoadIntoS
  1. :: (Load r ix e, Manifest r' e, MonadPrim s m)
  2. => MVector s r' e
  3. -> Array r ix e
  4. -> m (MArray s r' ix e)
#

Load into a supplied mutable vector sequentially. Returned array is not necesserally the same vector as the one that was supplied. It will be the same only if it had enough space to load all the elements in.

Read

Write

Modify

Swap

Range modification

Resizing

methodunsafeLinearGrow
  1. :: (Index ix, PrimMonad m)
  2. => MArray (PrimState m) r ix e
  3. -> Sz ix
  4. -> m (MArray (PrimState m) r ix e)
#

Linearly increase the size of an array. Total number of elements should be larger or equal. There is no guarantee that the original array is left unchanged, so it should no longer be used.

Pointer access

8 declarations
valueunsafeWithPtr :: MonadUnliftIO m => Array S ix e -> (Ptr e -> m b) -> m b
#

A pointer to the beginning of the storable array. It is unsafe since, if mutated, it can break referential transparency.

Atomic Operations

Other operations

valuecoerceBoxedArray :: Array BL ix e -> Array B ix e
#

O(1) - Cast a boxed lazy array. It is unsafe because it can violate the invariant that all elements of B array are in WHNF.

valuecoerceNormalBoxedArray :: Array BL ix e -> Array N ix e
#

O(1) - Cast a boxed lazy array. It is unsafe because it can violate the invariant that all elements of N array are in NF.

valueunsafeFromListN :: Sz1 -> [e] -> Vector DS e
#

O(n) - Convert a list of a known length to a delayed stream vector.

Unsafe - This function is unsafe because it will allocate enough space in memory for n elements ahead of time, regardless of the actual size of the list. Supplying n that is too big will result in an asynchronous Control.Exception.Base.HeapOverflow exception.

valueunsafeUnfoldrN
  1. :: Sz1

    n - maximum number of elements that the vector will have

  2. -> (s -> Maybe (e, s))

    Unfolding function. Stops when Nothing is returned or maximum number of elements is reached.

  3. -> s

    Inititial element.

  4. -> Vector DS e
#

O(n) - Right unfolding function with at most n number of elements.

Unsafe - This function is unsafe because it will allocate enough space in memory for n elements ahead of time, regardless of when unfolding function returns a Nothing. Supplying n that is too big will result in an asynchronous Control.Exception.Base.HeapOverflow exception.

valueunsafeUnfoldrNM
  1. :: Monad m
  2. => Sz1
  3. -> s -> m (Maybe (e, s))
  4. -> s
  5. -> m (Vector DS e)
#

O(n) - Same as unsafeUnfoldrN, but with monadic generating function.

Unsafe - This function is unsafe because it will allocate enough space in memory for n elements ahead of time, regardless of when unfolding function returns a Nothing. Supplying n that is too big will result in an asynchronous Control.Exception.Base.HeapOverflow exception.

valuemakeUnsafeStencil
  1. :: Index ix
  2. => Sz ix

    Size of the stencil

  3. -> ix

    Center of the stencil

  4. -> (ix -> (ix -> e) -> a)

    Stencil function.

  5. -> Stencil ix e a
#

Similar to makeStencil, but there are no guarantees that the stencil will not read out of bounds memory. This stencil is also a bit more powerful in sense it gets an extra peice of information, namely the exact index for the element it is constructing.

valueunsafeTransformStencil
  1. :: (Sz ix' -> Sz ix)

    Forward modifier for the size

  2. -> (ix' -> ix)

    Forward index modifier

  3. -> (((ix' -> e) -> (ix' -> e) -> ix' -> a) -> (ix -> e) -> (ix -> e) -> ix -> a)

    Inverse stencil function modifier

  4. -> Stencil ix' e a

    Original stencil.

  5. -> Stencil ix e a
#

Perform an arbitrary transformation of a stencil. This stencil modifier can be used for example to turn a vector stencil into a matrix stencil implement, or transpose a matrix stencil. It is really easy to get this wrong, so be extremely careful.

Examples

Convert a 1D stencil into a row or column 2D stencil:

Example8 expressions
import Data.Massiv.Arrayimport Data.Massiv.Array.Unsafelet arr = compute $ iterateN 3 succ 0 :: Array P Ix2 IntarrArray P Seq (Sz (3 :. 3))  [ [ 1, 2, 3 ]  , [ 4, 5, 6 ]  , [ 7, 8, 9 ]  ]let rowStencil = unsafeTransformStencil (\(Sz n) -> Sz (1 :. n)) (0 :.) $ \ f uget getVal (i :. j) -> f (uget  . (i :.)) (getVal . (i :.)) japplyStencil noPadding (rowStencil (sumStencil (Sz1 3))) arrArray DW Seq (Sz (3 :. 1))  [ [ 6 ]  , [ 15 ]  , [ 24 ]  ]let columnStencil = unsafeTransformStencil (\(Sz n) -> Sz (n :. 1)) (:. 0) $ \ f uget getVal (i :. j) -> f (uget . (:. j)) (getVal . (:. j)) iapplyStencil noPadding (columnStencil (sumStencil (Sz1 3))) arrArray DW Seq (Sz (1 :. 3))  [ [ 12, 15, 18 ]  ]

Constructors

19 declarations
data familydata family Array r ix e
#

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.

Instances84Monad, Functor, Applicative, Foldable, Traversable, IsList, …
  • Monad (Array DS Ix1)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • Functor (Array DI ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • Functor (Array D ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull
  • Functor (Array DS Ix1)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • Functor (Array DW ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed
  • Index ix => Functor (Array DL ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Push
  • Index ix => Functor (Array B ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • Index ix => Functor (Array BL ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • Applicative (Array DS Ix1)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • Index ix => Applicative (Array DI ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • Index ix => Applicative (Array D ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull
  • Foldable (Array DS Ix1)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • Index ix => Foldable (Array DI ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • Index ix => Foldable (Array D ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull

    Row-major sequential folding over a Delayed array.

  • Index ix => Foldable (Array B ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed

    Row-major sequential folding over a Boxed array.

  • Index ix => Foldable (Array BL ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed

    Row-major sequential folding over a Boxed array.

  • Index ix => Traversable (Array B ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • Index ix => Traversable (Array BL ix)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • IsList (Array DS Ix1 e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • Coercible (Elt ix e) (ListItem ix e) => IsList (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Core.List
  • (NFData e, IsList (Array L ix e), Ragged L ix e) => IsList (Array BN ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Storable e, IsList (Array L ix e), Ragged L ix e) => IsList (Array S ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • (IsList (Array L ix e), Ragged L ix e) => IsList (Array B ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (IsList (Array L ix e), Ragged L ix e) => IsList (Array BL ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Prim e, IsList (Array L ix e), Ragged L ix e) => IsList (Array P ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • (Unbox e, IsList (Array L ix e), Ragged L ix e) => IsList (Array U ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • (Eq e, Index ix) => Eq (Array DI ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • (Eq e, Index ix) => Eq (Array D ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull
  • (Storable e, Eq e, Index ix) => Eq (Array S ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • (Index ix, NFData e, Eq e) => Eq (Array BN ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Index ix, Eq e) => Eq (Array B ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Index ix, Eq e) => Eq (Array BL ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Prim e, Eq e, Index ix) => Eq (Array P ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • (Unbox e, Eq e, Index ix) => Eq (Array U ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • (Ord e, Index ix) => Ord (Array DI ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • (Ord e, Index ix) => Ord (Array D ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull
  • (Storable e, Ord e, Index ix) => Ord (Array S ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • (Index ix, NFData e, Ord e) => Ord (Array BN ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Index ix, Ord e) => Ord (Array B ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Index ix, Ord e) => Ord (Array BL ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Prim e, Ord e, Index ix) => Ord (Array P ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • (Unbox e, Ord e, Index ix) => Ord (Array U ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • Show e => Show (Array DS Ix1 e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed · orphan
  • (Ragged L ix e, Show e) => Show (Array DI ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • (Ragged L ix e, Show e) => Show (Array D ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull
  • (Ragged L ix e, Show e) => Show (Array DL ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed · orphan
  • (Ragged L ix e, Show e) => Show (Array B ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Ragged L ix e, Show e) => Show (Array BL ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Ragged L ix e, Show e) => Show (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Core.List
  • (Ragged L ix e, Show e, NFData e) => Show (Array BN ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Ragged L ix e, Show e, Storable e) => Show (Array S ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • (Ragged L ix e, Show e, Prim e) => Show (Array P ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • (Ragged L ix e, Show e, Unbox e) => Show (Array U ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • (Ragged L ix e, Load DW ix e, Show e) => Show (Array DW ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed
  • Semigroup (Array DL Ix1 e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Push
  • Semigroup (Array DS Ix1 e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • Monoid (Array DL Ix1 e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Push
  • Monoid (Array DS Ix1 e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • NFData (Array BN ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed

    O(1) - BN is already in normal form

  • NFData ix => NFData (Array S ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • NFData ix => NFData (Array U ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • Index ix => NFData (Array P ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • (Index ix, NFData e) => NFData (Array B ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • (Index ix, NFData e) => NFData (Array BL ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • type Item (Array DS Ix1 e) = eDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • type Item (Array B ix e) = Item (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • type Item (Array BL ix e) = Item (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • type Item (Array BN ix e) = Item (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • type Item (Array P ix e) = Item (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • type Item (Array S ix e) = Item (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • type Item (Array U ix e) = Item (Array L ix e)Defined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • type Item (Array L ix e) = ListItem ix eDefined in massiv-1.0.5.0 · Data.Massiv.Core.List
  • data Array DIDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Interleaved
  • data Array DDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Pull
  • data Array DLDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Push
  • data Array DS Ix1Defined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Stream
  • data Array DWDefined in massiv-1.0.5.0 · Data.Massiv.Array.Delayed.Windowed
  • data Array BDefined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • data Array BLDefined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • data Array BNDefined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Boxed
  • data Array PDefined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Primitive
  • data Array SDefined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Storable
  • data Array UDefined in massiv-1.0.5.0 · Data.Massiv.Array.Manifest.Unboxed
  • data Array LDefined in massiv-1.0.5.0 · Data.Massiv.Core.List
constructorDLArray
#

Fields

  • dlComp :: !Comp
  • dlSize :: !Sz ix
  • dlLoad :: Loader e
constructorDSArray
#

Fields

  • dsArray :: Steps Id e
data familydata family MArray s r ix e
#

Mutable version of a Manifest Array. The extra type argument s is for the state token used by IO and ST.

Instances9NFData, MArray, …