accelerate-1.2.0.1: An embedded language for accelerated array processing

Copyright [2009..2018] Manuel M T Chakravarty Gabriele Keller Trevor L. McDonell BSD3 Trevor L. McDonell experimental non-portable (GHC extensions) None Haskell2010

Data.Array.Accelerate.Unsafe

Contents

Description

Operations which may be unsafe. Use with care.

Since: accelerate-1.2.0.0

Synopsis

## Unsafe operations

undef :: Elt t => Exp t Source #

undef can be used anywhere a constant is expected, and indicates that the consumer of the value can receive an unspecified bit pattern.

This is useful because a store of an undefined value can be assumed to not have any effect; we can assume that the value is overwritten with bits that happen to match what was already there. However, a store to an undefined location could clobber arbitrary memory, therefore, its use in such a context would introduce undefined behaviour.

There are (at least) two cases where you may want to use this:

1. The permute function requires an array of default values, into which the new values are combined. However, if you are sure the default values are not used, and will (eventually) be completely overwritten, then filling an array with this value will give you a new uninitialised array.
2. In the definition of sum data types. See for example Data.Array.Accelerate.Data.Maybe and Data.Array.Accelerate.Data.Either.

Since: accelerate-1.2.0.0

coerce :: (Elt a, Elt b) => Exp a -> Exp b Source #

The function coerce allows you to convert a value between any two types whose underlying representations have the same bit size at each component.

For example:

coerce (x :: Exp Double)         :: Exp Word64
coerce (x :: Exp (Int64,Float))  :: Exp (Complex Float, Word32)

Furthermore, as we typically declare newtype wrappers similarly to:

type instance EltRepr (Sum a) = ((), EltRepr a)

This can be used instead of the newtype constructor, to go from the newtype's abstract type to the concrete type by dropping the extra () from the representation, and vice-versa.

You will get a runtime error if it fails to find a coercion between the two representations.

Since: accelerate-1.2.0.0