Rename unsafe and safe index in PrimArray interface
This commit is contained in:
parent
b0e4253b88
commit
a88fc5d9c6
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue