blarney-0.1.0.0
Copyright(c) Alexandre Joannou 2019-2021
LicenseMIT
Maintaineralexandre.joannou@gmail.com
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageGHC2021

Blarney.Vector

Description

A blarney module for handling vectors

Synopsis

Vec

data Vec (n :: Nat) a Source #

Vec type

Constructors

Vec 

Fields

Instances

Instances details
Functor (Vec n) # 
Instance details

Defined in Blarney.Vector

Methods

fmap :: (a -> b) -> Vec n a -> Vec n b #

(<$) :: a -> Vec n b -> Vec n a #

Generic (Vec n a) # 
Instance details

Defined in Blarney.Vector

Associated Types

type Rep (Vec n a) :: Type -> Type #

Methods

from :: Vec n a -> Rep (Vec n a) x #

to :: Rep (Vec n a) x -> Vec n a #

(KnownNat n, Bits a) => Bits (Vec n a) # 
Instance details

Defined in Blarney.Vector

Associated Types

type SizeOf (Vec n a) :: Nat Source #

Methods

sizeOf :: Vec n a -> Int Source #

pack :: Vec n a -> Bit (SizeOf (Vec n a)) Source #

unpack :: Bit (SizeOf (Vec n a)) -> Vec n a Source #

nameBits :: String -> Vec n a -> Vec n a Source #

FShow a => FShow (Vec n a) # 
Instance details

Defined in Blarney.Vector

Methods

fshow :: Vec n a -> Format Source #

fshowList :: [Vec n a] -> Format Source #

(KnownNat n, Interface a) => Interface (Vec n a) # 
Instance details

Defined in Blarney.Vector

Methods

toIfc :: Vec n a -> (IfcTerm, IfcType) Source #

fromIfc :: IfcTerm -> Vec n a Source #

Lookup (Vec m a) Integer a #

Index a vector using an Integer

Instance details

Defined in Blarney.Vector

Methods

(!) :: Vec m a -> Integer -> a Source #

Lookup (Vec m a) Int a #

Index a vector using an Int

Instance details

Defined in Blarney.Vector

Methods

(!) :: Vec m a -> Int -> a Source #

(Interface a, KnownNat n) => Lookup (Vec m a) (Bit n) a #

Index a vector using a bit vector

Instance details

Defined in Blarney.Vector

Methods

(!) :: Vec m a -> Bit n -> a Source #

type Rep (Vec n a) # 
Instance details

Defined in Blarney.Vector

type Rep (Vec n a) = D1 ('MetaData "Vec" "Blarney.Vector" "blarney-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Vec" 'PrefixI 'True) (S1 ('MetaSel ('Just "toList") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])))
type SizeOf (Vec n a) # 
Instance details

Defined in Blarney.Vector

type SizeOf (Vec n a) = n * SizeOf a

Vec constructors

newVec :: forall n a. KnownNat n => Vec n a Source #

Generate a Vec of size n initialized with undefined in each element

genVec :: forall n. KnownNat n => Vec n Integer Source #

Generate a Vec of size n initialized with integers from '0' to 'n-1'

fromList :: forall n a. KnownNat n => [a] -> Vec n a Source #

Convert a list to a vector, after size check

replicate :: forall n a. KnownNat n => a -> Vec n a Source #

Generate a Vec with each element initialized to the given value

replicateM :: forall n a m. (Monad m, KnownNat n) => m a -> m (Vec n a) Source #

genWith :: forall n a. KnownNat n => (Integer -> a) -> Vec n a Source #

Generate a Vec from the given function f applied to integers from '0' to 'n-1'

genWithM :: forall n a m. (Monad m, KnownNat n) => (Integer -> m a) -> m (Vec n a) Source #

cons :: a -> Vec n a -> Vec (n + 1) a Source #

Construct a new Vec from a new element and an exisiting Vec. The new element is the head of the new Vec.

nil :: Vec 0 a Source #

The "nil" Vec

append :: Vec n a -> Vec m a -> Vec (n + m) a Source #

Append the second Vec to the first Vec

concat :: Vec m (Vec n a) -> Vec (m * n) a Source #

Concatenate a Vec of Vecs into one flattened Vec

select :: forall i n a. (KnownNat i, (i + 1) <= n) => Vec n a -> a Source #

Select the element from a Vec at the given type-level index

split :: forall n n0 n1 a. (KnownNat n0, (n0 + n1) ~ n) => Vec n a -> (Vec n0 a, Vec n1 a) Source #

Return a pair of Vec, the first element being the Vec of length n0 prefix of the given Vec of length n, and the second element being the 'Vec of length n1 suffix of the given Vec of length n

update :: Vec n a -> Int -> a -> Vec n a Source #

Generate a new Vec from the given Vec with the element at index idx updated

head :: 1 <= n => Vec n a -> a Source #

Return the head element of the given Vec (element at index 0)

last :: 1 <= n => Vec n a -> a Source #

Return the last element of the given Vec (element at last index)

tail :: Vec (n + 1) a -> Vec n a Source #

Return the given Vec with its head element removed

init :: Vec (n + 1) a -> Vec n a Source #

Return the given Vec with its last element removed

take :: forall n m a. (KnownNat m, m <= n) => Vec n a -> Vec m a Source #

Return the Vec composed of the first m elements of the given Vec

takeTail :: forall n m a. (KnownNat m, m <= n) => Vec n a -> Vec m a Source #

Return the Vec composed of the last m elements of the given Vec

drop :: forall i n a. (KnownNat i, i <= n) => Vec n a -> Vec (n - i) a Source #

Drop the first i elements of the given Vec

takeAt :: forall n m a. (KnownNat n, KnownNat m, m <= n) => Int -> Vec n a -> Vec m a Source #

Return the Vec composed of the m elements of the given Vec starting at index idx

rotateL :: Vec n a -> Vec n a Source #

Return a Vec image of the given Vec with its elements rotated left by one, with the head element becoming the last element

rotateR :: Vec n a -> Vec n a Source #

Return a Vec image of the given Vec with its elements rotated right by one, with the last element becoming the head element

rotateLBy :: Bits a => Bit m -> Vec n a -> Vec n a Source #

Return a Vec image of the given Vec with its elements rotated left by i, with the first i elements becoming the last i elements

rotateRBy :: Bits a => Bit m -> Vec n a -> Vec n a Source #

Return a Vec image of the given Vec with its elements rotated right by i, with the last i elements becoming the first i elements

reverse :: Vec n a -> Vec n a Source #

Reverse the given Vec

elem :: Cmp a => a -> Vec n a -> Bit 1 Source #

Check that the given value is and element of the given Vec

any :: (a -> Bit 1) -> Vec n a -> Bit 1 Source #

Check that the given predicate holds for any element of the given Vec

all :: (a -> Bit 1) -> Vec n a -> Bit 1 Source #

Check that the given predicate holds for all element of the given Vec

or :: Vec n (Bit 1) -> Bit 1 Source #

Reduces a Vec of 'Bit 1' by "or-ing" its elements

and :: Vec n (Bit 1) -> Bit 1 Source #

Reduces a Vec of 'Bit 1' by "and-ing" its elements

countElem :: (Cmp a, 1 <= n, _) => a -> Vec n a -> Bit (Log2Ceil n + 1) Source #

Return the number of elements of Vec which are equal to the given value

countIf :: (1 <= n, _) => (a -> Bit 1) -> Vec n a -> Bit (Log2Ceil n + 1) Source #

Return the number of elements of Vec for which the given predicate holds

find :: Bits a => (a -> Bit 1) -> Vec n a -> Option a Source #

Return a some Option with the first element in the given Vec that satisfies the given predicate, or none if no such element is found

zip :: Vec n a -> Vec n b -> Vec n (a, b) Source #

Return a Vec of pairs of elements at the same index in both given Vecs

zip3 :: Vec n a -> Vec n b -> Vec n c -> Vec n (a, b, c) Source #

Return a Vec of tuple-3 of elements at the same index in the given Vecs

zip4 :: Vec n a -> Vec n b -> Vec n c -> Vec n d -> Vec n (a, b, c, d) Source #

Return a Vec of tuple-4 of elements at the same index in the given Vecs

unzip :: Vec n (a, b) -> (Vec n a, Vec n b) Source #

Return a pair of Vec from a given Vec of pairs

vectorise :: ([a] -> [b]) -> Vec n a -> Vec n b Source #

Appy list function to elements of vector

map :: (a -> b) -> Vec n a -> Vec n b Source #

Map a function over the given Vec

mapM :: Monad m => (a -> m b) -> Vec n a -> m (Vec n b) Source #

mapM_ :: Monad m => (a -> m b) -> Vec n a -> m () Source #

zipWith :: (a -> b -> c) -> Vec n a -> Vec n b -> Vec n c Source #

Return a Vec, result of mapping a function over the two input Vecs

zipWithM :: Monad m => (a -> b -> m c) -> Vec n a -> Vec n b -> m (Vec n c) Source #

zipWithM_ :: Monad m => (a -> b -> m c) -> Vec n a -> Vec n b -> m () Source #

zipWith3 :: (a -> b -> c -> d) -> Vec n a -> Vec n b -> Vec n c -> Vec n d Source #

Return a Vec, result of mapping a function over the three input Vecs

zipWith3M :: Monad m => (a -> b -> c -> m d) -> Vec n a -> Vec n b -> Vec n c -> m (Vec n d) Source #

zipAny :: Vec n a -> Vec m b -> Vec (Min n m) (a, b) Source #

Return a Vec of pairs of elements at the same index in both given Vecs with the resulting Vec being as long as the smaller input Vec

zipWithAny :: (a -> b -> c) -> Vec n a -> Vec m b -> Vec (Min n m) c Source #

Return a Vec, result of mapping a function over the two input Vecs, truncated to the length of the shortest one

zipWithAny3 :: (a -> b -> c -> d) -> Vec n0 a -> Vec n1 b -> Vec n2 c -> Vec (Min n0 (Min n1 n2)) d Source #

Return a Vec, result of mapping a function over the three input Vecs, truncated to the length of the shortest one

tree :: (a -> a -> a) -> a -> Vec n a -> a Source #

Tree reduction for vectors

tree1 :: (a -> a -> a) -> Vec n a -> a Source #

Tree reduction for nonempty vectors

foldr :: (a -> b -> b) -> b -> Vec n a -> b Source #

Reduce a Vec using the given function, starting with a provided seed and the last element of the Vec

foldl :: (b -> a -> b) -> b -> Vec n a -> b Source #

Reduce a Vec using the given function, starting with a provided seed and the first element of the Vec

foldr1 :: 1 <= n => (a -> a -> a) -> Vec n a -> a Source #

Reduce a Vec using the given function, starting with the last element of the Vec as the seed

foldl1 :: 1 <= n => (a -> a -> a) -> Vec n a -> a Source #

Reduce a Vec using the given function, starting with the first element of the Vec as the seed

scanr :: (a -> b -> b) -> b -> Vec n a -> Vec (n + 1) b Source #

Apply a function over a Vec starting with the given seed and the last element, yielding a Vec one element bigger than the provided one

sscanr :: (a -> b -> b) -> b -> Vec n a -> Vec (n + 1) b Source #

Apply a function over a Vec starting with the given seed and the last element, dropping the new last element (provided seed), effectively yielding a Vec of the same size as the provided one

scanl :: (b -> a -> b) -> b -> Vec n a -> Vec (n + 1) b Source #

Apply a function over a Vec starting with the given seed and the first element, yielding a Vec one element bigger than the provided one

sscanl :: (b -> a -> b) -> b -> Vec n a -> Vec (n + 1) b Source #

Apply a function over a Vec starting with the given seed and the first element, dropping the new first element (provided seed), effectively yielding a Vec of the same size as the provided one