shady-gen-0.5.1: Functional GPU programming - DSEL & compiler

Stability experimental conal@conal.net

Description

Experiment in length-typed vectors

Synopsis

# Type-level numbers

data Z Source

Type-level representation of zero

Instances

 IsNat Z (IsNat n, IsScalar a, Show a) => IfB BoolE (VecE n a) (Show a, IsScalar a) => FromE (ComplexE a) (Show a, IsScalar a) => ToE (ComplexE a)

data S n Source

Type-level representation of successor

Instances

 (IsNat n, IsScalar a, Show a) => IfB BoolE (VecE n a) IsNat n => IsNat (S n) (Show a, IsScalar a) => FromE (ComplexE a) (Show a, IsScalar a) => ToE (ComplexE a)

type family a :+: b Source

Sum of type-level numbers

type ZeroT = ZSource

# Typed natural numbers

data Nat whereSource

Constructors

 Zero :: Nat Z Succ :: IsNat n => Nat n -> Nat (S n)

Instances

 Show (Nat n)

withIsNat :: (IsNat n => Nat n -> a) -> Nat n -> aSource

natSucc :: Nat n -> Nat (S n)Source

natIsNat :: Nat n -> IsNat n => Nat nSource

natToZ :: Nat n -> IntegerSource

Interpret a `Nat` as an `Integer`

natEq :: Nat m -> Nat n -> Maybe (m :=: n)Source

Equality test

natAdd :: Nat m -> Nat n -> Nat (m :+: n)Source

Sum of naturals

data m :<: n Source

Proof that `m < n`

data Index lim Source

A number under the given limit, with proof

Constructors

 forall n . IsNat n => Index (n :<: lim) (Nat n)

Instances

 Eq (Index lim)

succI :: Index m -> Index (S m)Source

index2 :: Index (S (S (S n)))Source

index3 :: Index (S (S (S (S n))))Source

# Vectors

data Vec whereSource

Vectors with type-determined length, having empty vector (`ZVec`) and vector cons ('(:<)').

Constructors

 ZVec :: Vec Z a :< :: a -> Vec n a -> Vec (S n) a

Instances

 (IsNat n, IsScalar a, Show a) => IfB BoolE (VecE n a) (IsNat n, IsScalar b, Floating b) => Floating (E (Vec n b)) (IsNat n, IsScalar b, Fractional b) => Fractional (E (Vec n b)) (IsNat n, IsScalar b, Integral b) => Integral (E (Vec n b)) Functor (Vec n) (IsNat n, IsScalar a, Num a) => Num (E (Vec n a)) (IsNat n, IsScalar a, Ord a, Show a) => Ord (E (Vec n a)) (IsNat n, IsScalar a, Ord a, Num a) => Real (E (Vec n a)) (IsNat n, IsScalar b, RealFrac b) => RealFrac (E (Vec n b)) IsNat n => Applicative (Vec n) Foldable (Vec n) (IsNat n, IsScalar a, Num a) => VectorSpace (E (Vec n a)) IsNat n => InnerSpace (E (Vec n R)) (IsNat n, IsScalar a, Num a) => AdditiveGroup (E (Vec n a)) (IsNat n, IsScalar a, FMod a) => FMod (E (Vec n a)) (IsNat n, IsScalar a, FMod a, RealFrac a) => Frac (E (Vec n a)) (Show a, IsScalar a) => FromE (ComplexE a) (Show a, IsScalar a) => ToE (ComplexE a) (IsNat n, IsScalar applicative_arg, Enum applicative_arg) => Enum (Vec n applicative_arg) Eq a => Eq (Vec n a) (IsNat n, IsScalar applicative_arg, Floating applicative_arg) => Floating (Vec n applicative_arg) (IsNat n, IsScalar applicative_arg, Fractional applicative_arg) => Fractional (Vec n applicative_arg) (IsNat n, IsScalar applicative_arg, Integral applicative_arg) => Integral (Vec n applicative_arg) (IsNat n, IsScalar applicative_arg, Num applicative_arg) => Num (Vec n applicative_arg) Ord a => Ord (Vec n a) (IsNat n, IsScalar applicative_arg, Num applicative_arg, Ord applicative_arg) => Real (Vec n applicative_arg) (IsNat n, IsScalar applicative_arg, RealFloat applicative_arg) => RealFloat (Vec n applicative_arg) (IsNat n, IsScalar applicative_arg, RealFrac applicative_arg) => RealFrac (Vec n applicative_arg) (IsNat n, IsScalar a, Show a) => Show (Vec n a) IsNat n => Boolean (VecE n Bool) (IsNat n, Storable a) => Storable (Vec n a) (IsNat n, Num a) => VectorSpace (Vec n a) (IsNat n, Num a) => InnerSpace (Vec n a) (IsNat n, Num a) => AdditiveGroup (Vec n a) (IsNat n, IsScalar a, Pretty a) => Pretty (Vec n a) (IsNat n, IsScalar a, FMod a) => FMod (Vec n a) (IsNat n, IsScalar a, Pretty a) => PrettyPrec (Vec n a) (IsNat n, IsScalar a, Show a) => HasExpr (Vec n a) (IsNat n, IsScalar a) => HasType (Vec n a) (IsNat n, IsScalar a, Eq a, Show a) => EqB (VecE n Bool) (VecE n a) (IsNat n, IsScalar a, Ord a, Show a) => OrdB (VecE n Bool) (VecE n a)

class IsNat n whereSource

`n` a vector length.

Methods

nat :: Nat nSource

pureV :: a -> Vec n aSource

elemsV :: [a] -> Vec n aSource

peekV :: Storable a => Ptr a -> IO (Vec n a)Source

pokeV :: Storable a => Ptr a -> Sink (Vec n a)Source

Instances

 IsNat Z IsNat n => IsNat (S n)

(<+>) :: Vec m a -> Vec n a -> Vec (m :+: n) aSource

Concatenation of vectors

indices :: Nat n -> Vec n (Index n)Source

Indices under `n`: `index0` :< `index1` :< ...

vElems :: Vec n a -> [a]Source

Enumerate the elements of a vector. See also `elemsV` vElems :: Vec n a -> [a] vElems ZVec = [] vElems (a :< as) = a : vElems as

vec1 :: a -> One aSource

vec2 :: a -> a -> Two aSource

vec3 :: a -> a -> a -> Three aSource

vec4 :: a -> a -> a -> a -> Four aSource

un1 :: One a -> aSource

Extract element

un2 :: Two a -> (a, a)Source

Extract elements

un3 :: Three a -> (a, a, a)Source

Extract elements

un4 :: Four a -> (a, a, a, a)Source

Extract elements

get0 :: Vec (S n) a -> One aSource

get1 :: Vec (S (S n)) a -> One aSource

get2 :: Vec (S (S (S n))) a -> One aSource

get3 :: Vec (S (S (S (S n)))) a -> One aSource

get :: Index n -> Vec n a -> One aSource

General indexing, taking a proof that the index is within bounds.

swizzle :: Vec n (Index m) -> Vec m a -> Vec n aSource

Swizzling. Extract multiple elements simultaneously.