Rename unsafe and safe index in PrimArray interface

This commit is contained in:
Kiana Sheibani 2022-05-13 08:33:03 -04:00
parent b0e4253b88
commit a88fc5d9c6
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 9 additions and 8 deletions

View file

@ -69,7 +69,7 @@ reshape s' = reshape' s' (orderOfShape s' COrder)
export
index : Coords s -> Array s a -> a
index is arr = unsafeIndex (computeLoc (getStrides arr) is) (getPrim arr)
index is arr = index (computeLoc (getStrides arr) is) (getPrim arr)
export
@ -80,3 +80,4 @@ export
main : IO ()
main = do
printLn $ index [0,1,0] test
printLn $ index [1,1,2] test

View file

@ -48,13 +48,13 @@ create size f = unsafePerformIO $ do
export
unsafeIndex : Nat -> PrimArray a -> a
unsafeIndex n arr = unsafePerformIO $ arrayDataGet n $ content arr
index : Nat -> PrimArray a -> a
index n arr = unsafePerformIO $ arrayDataGet n $ content arr
export
index : Nat -> PrimArray a -> Maybe a
index n arr = if n < length arr
then Just $ unsafeIndex n arr
safeIndex : Nat -> PrimArray a -> Maybe a
safeIndex n arr = if n < length arr
then Just $ index n arr
else Nothing
@ -64,7 +64,7 @@ toList arr = iter (length arr) []
where
iter : Nat -> List a -> List a
iter Z acc = acc
iter (S n) acc = let el = unsafeIndex n arr
iter (S n) acc = let el = index n arr
in iter n (el :: acc)
export
@ -78,5 +78,5 @@ fromList xs = create (length xs)
export
map : (a -> b) -> PrimArray a -> PrimArray b
map f arr = create (length arr) (\n => f $ unsafeIndex n arr)
map f arr = create (length arr) (\n => f $ index n arr)