Remove rank-index on Order type

This commit is contained in:
Kiana Sheibani 2022-05-16 08:56:45 -04:00
parent a499d14e87
commit 76e16574f1
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 30 additions and 63 deletions

View file

@ -1,7 +1,6 @@
module Data.NumIdr.Array.Order
import Data.Vect
import Data.Permutation
%default total
@ -10,24 +9,16 @@ import Data.Permutation
||| elements are stored in memory. Orders are used to calculate strides,
||| which provide a method of converting an array coordinate into a linear
||| memory location.
|||
||| @ rk The rank of the array this order applies to
public export
data Order : (rk : Nat) -> Type where
data Order : Type where
||| C-like order, or contiguous order. This order stores elements in a
||| row-major fashion (the last axis is the least significant).
COrder : Order rk
COrder : Order
||| Fortran-like order. This order stores elements in a column-major
||| fashion (the first axis is the least significant).
FOrder : Order rk
export
orderOfShape : (0 s : Vect rk Nat) -> Order (length s) -> Order rk
orderOfShape s ord = rewrite sym (lengthCorrect s) in ord
FOrder : Order
scanr : (el -> res -> res) -> res -> Vect len el -> Vect (S len) res
@ -38,7 +29,7 @@ scanr f q0 (x::xs) = f x (head qs) :: qs
||| Calculate an array's strides given its order and shape.
export
calcStrides : Order rk -> Vect rk Nat -> Vect rk Nat
calcStrides : Order -> Vect rk Nat -> Vect rk Nat
calcStrides _ [] = []
calcStrides COrder v@(_::_) = scanr (*) 1 $ tail v
calcStrides FOrder v@(_::_) = scanl (*) 1 $ init v