Add Show instance for NP

This commit is contained in:
Kiana Sheibani 2022-08-04 15:08:17 -04:00
parent 6cdb22a6ed
commit 1ebf0dcbe9
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 24 additions and 10 deletions

View file

@ -276,10 +276,9 @@ indexSet is = indexUpdate is . const
||| coordinates are out of bounds.
export
indexNB : Vect rk Nat -> Array {rk} s a -> Maybe a
indexNB is arr with (viewShape arr)
_ | Shape s = if concat @{All} $ zipWith (<) is s
then Just $ index (getLocation' (strides arr) is) (getPrim arr)
else Nothing
indexNB is arr = if and $ map delay $ zipWith (<) is (shape arr)
then Just $ index (getLocation' (strides arr) is) (getPrim arr)
else Nothing
||| Index the array using the given coordinates, returning `Nothing` if the
||| coordinates are out of bounds.
@ -391,6 +390,14 @@ resizeLTE : (s' : Vect rk Nat) -> (0 ok : NP Prelude.id (zipWith LTE s' s)) =>
resizeLTE s' arr = resize s' (believe_me ()) arr
||| List all of the values in an array in row-major order.
export
elements : Array {rk} s a -> Vect (product s) a
elements (MkArray _ sts sh p) =
let elems = map (flip index p . getLocation' sts) (getAllCoords' sh)
in assert_total $ case toVect (product sh) elems of Just v => v
||| List all of the values in an array along with their coordinates.
export
enumerateNB : Array {rk} s a -> List (Vect rk Nat, a)