Add comments to everything
This commit is contained in:
parent
a88fc5d9c6
commit
a499d14e87
5 changed files with 119 additions and 35 deletions
|
|
@ -6,9 +6,21 @@ import Data.Permutation
|
|||
%default total
|
||||
|
||||
|
||||
||| An order is an abstract representation of the way in which array
|
||||
||| 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
|
||||
|
||||
||| 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
|
||||
|
||||
||| Fortran-like order. This order stores elements in a column-major
|
||||
||| fashion (the first axis is the least significant).
|
||||
FOrder : Order rk
|
||||
|
||||
|
||||
|
|
@ -24,7 +36,9 @@ scanr f q0 (x::xs) = f x (head qs) :: qs
|
|||
where qs : Vect len res
|
||||
qs = scanr f q0 xs
|
||||
|
||||
||| Calculate an array's strides given its order and shape.
|
||||
export
|
||||
calcStrides : Order rk -> Vect rk Nat -> Vect rk Nat
|
||||
calcStrides COrder v = tail $ scanr (*) 1 v
|
||||
calcStrides FOrder v = init $ scanl (*) 1 v
|
||||
calcStrides _ [] = []
|
||||
calcStrides COrder v@(_::_) = scanr (*) 1 $ tail v
|
||||
calcStrides FOrder v@(_::_) = scanl (*) 1 $ init v
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue