Create Data.NumIdr.Array.Order

This commit is contained in:
Kiana Sheibani 2022-05-11 23:38:49 -04:00
parent a19ccd59a1
commit 562d501f33
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 42 additions and 0 deletions
src/Data/NumIdr/Array

View file

@ -0,0 +1,30 @@
module Data.NumIdr.Array.Order
import Data.Vect
import Data.Permutation
%default total
export
Order : (rk : Nat) -> Type
Order = Permutation
export
COrder : {rk : Nat} -> Order rk
COrder = identity
export
FOrder : {rk : Nat} -> Order rk
FOrder = reversed
scanr : (el -> res -> res) -> res -> Vect len el -> Vect (S len) res
scanr _ q0 [] = [q0]
scanr f q0 (x::xs) = f x (head qs) :: qs
where qs : Vect len res
qs = scanr f q0 xs
export
calcStrides : Order rk -> Vect rk Nat -> Vect rk Nat
calcStrides ord v = permuteVect ord $ tail $ scanr (*) 1 v

View file

@ -0,0 +1,12 @@
module Data.NumIdr.Array.Utils
import Data.NumIdr.Array.Array
export
zeros : Num a => (s : Vect rk Nat) -> Array s a
zeros = constant 0
export
ones : Num a => (s : Vect rk Nat) -> Array s a
ones = constant 1