forM package:massiv

Same as mapM except with arguments flipped.
Just like mapM_, except with flipped arguments.

Examples

Here is a common way of iterating N times using a for loop in an imperative language with mutation being an obvious side effect:
>>> import Data.Massiv.Array as A

>>> import Data.IORef

>>> ref <- newIORef 0 :: IO (IORef Int)

>>> A.forM_ (range Seq (Ix1 0) 1000) $ \ i -> modifyIORef' ref (+i)

>>> readIORef ref
499500
Same as forM, except with an index aware action.
Just like imapM_, except with flipped arguments.
General array transformation
Same as transform', but operates on two arrays
Same as transformM, but operates on two arrays
General array transformation, that forces computation and produces a manifest array.
Generate a random array where all elements are sampled from a uniform distribution.
Same as uniformArray, but will generate values in a supplied range.
O(n) - Compute all elements of a boxed array to NF (normal form)
O(n) - Wrap a boxed array and evaluate all elements to a Normal Form (NF).
O(n) - Wrap mutable boxed array and evaluate all elements to NF.
O(1) - Converts array from N to B representation.
O(1) - Unwrap a fully evaluated boxed array. This will discard any possible slicing that has been applied to the array.
O(1) - Unwrap a fully evaluated mutable boxed array. This will discard any possible slicing that has been applied to the array.
Same transform', except no bounds checking is performed, thus making it faster, but unsafe.
Same transform2', except no bounds checking is performed, thus making it faster, but unsafe.
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:
>>> import Data.Massiv.Array

>>> import Data.Massiv.Array.Unsafe

>>> let arr = compute $ iterateN 3 succ 0 :: Array P Ix2 Int

>>> arr
Array 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 :.)) j

>>> applyStencil noPadding (rowStencil (sumStencil (Sz1 3))) arr
Array 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)) i

>>> applyStencil noPadding (columnStencil (sumStencil (Sz1 3))) arr
Array DW Seq (Sz (1 :. 3))
[ [ 12, 15, 18 ]
]
Same as smapM, but with arguments flipped.

Examples

Same as smapM_, but with arguments flipped.

Examples

Same as simapM, but with arguments flipped.

Examples

Same as simapM_, but with arguments flipped.

Examples