Rename *Maybe functions to *NB
This commit is contained in:
parent
b0d48eaf00
commit
015b7f8cb1
|
@ -245,23 +245,23 @@ indexSet is = indexUpdate is . const
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
indexMaybe : Vect rk Nat -> Array {rk} s a -> Maybe a
|
indexNB : Vect rk Nat -> Array {rk} s a -> Maybe a
|
||||||
indexMaybe is arr with (viewShape arr)
|
indexNB is arr with (viewShape arr)
|
||||||
_ | Shape s = if concat @{All} $ zipWith (<) s (shape arr)
|
_ | Shape s = if concat @{All} $ zipWith (<) s (shape arr)
|
||||||
then Just $ index (getLocation' (strides arr) is) (getPrim arr)
|
then Just $ index (getLocation' (strides arr) is) (getPrim arr)
|
||||||
else Nothing
|
else Nothing
|
||||||
|
|
||||||
export
|
export
|
||||||
(!?) : Array {rk} s a -> Vect rk Nat -> Maybe a
|
(!?) : Array {rk} s a -> Vect rk Nat -> Maybe a
|
||||||
(!?) = flip indexMaybe
|
(!?) = flip indexNB
|
||||||
|
|
||||||
export
|
export
|
||||||
indexUpdateMaybe : Vect rk Nat -> (a -> a) -> Array {rk} s a -> Array s a
|
indexUpdateNB : Vect rk Nat -> (a -> a) -> Array {rk} s a -> Array s a
|
||||||
indexUpdateMaybe is f (MkArray ord sts s arr) = MkArray ord sts s (updateAt (getLocation' sts is) f arr)
|
indexUpdateNB is f (MkArray ord sts s arr) = MkArray ord sts s (updateAt (getLocation' sts is) f arr)
|
||||||
|
|
||||||
export
|
export
|
||||||
indexSetMaybe : Vect rk Nat -> a -> Array {rk} s a -> Array s a
|
indexSetNB : Vect rk Nat -> a -> Array {rk} s a -> Array s a
|
||||||
indexSetMaybe is = indexUpdateMaybe is . const
|
indexSetNB is = indexUpdateNB is . const
|
||||||
|
|
||||||
|
|
||||||
||| Index the array using the given `CoordsRange` object.
|
||| Index the array using the given `CoordsRange` object.
|
||||||
|
@ -320,7 +320,7 @@ reorder ord' arr with (viewShape arr)
|
||||||
|
|
||||||
export
|
export
|
||||||
resize : (s' : Vect rk Nat) -> a -> Array {rk} s a -> Array s' a
|
resize : (s' : Vect rk Nat) -> a -> Array {rk} s a -> Array s' a
|
||||||
resize s' x arr = fromFunction' s' (getOrder arr) (fromMaybe x . (arr !?) . toNats)
|
resize s' x arr = fromFunction' s' (getOrder arr) (fromMaybe x . (arr !?) . toNB)
|
||||||
|
|
||||||
export
|
export
|
||||||
enumerate' : Array {rk} s a -> List (Vect rk Nat, a)
|
enumerate' : Array {rk} s a -> List (Vect rk Nat, a)
|
||||||
|
@ -342,8 +342,8 @@ concat axis a b = let sA = shape a
|
||||||
dB = index axis sB
|
dB = index axis sB
|
||||||
s = replaceAt axis (dA + dB) sA
|
s = replaceAt axis (dA + dB) sA
|
||||||
sts = calcStrides COrder s
|
sts = calcStrides COrder s
|
||||||
ins = map (mapFst $ getLocation' sts . toNats) (enumerate a)
|
ins = map (mapFst $ getLocation' sts . toNB) (enumerate a)
|
||||||
++ map (mapFst $ getLocation' sts . updateAt axis (+dA) . toNats) (enumerate b)
|
++ map (mapFst $ getLocation' sts . updateAt axis (+dA) . toNB) (enumerate b)
|
||||||
-- TODO: prove that the type-level shape and `s` are equivalent
|
-- TODO: prove that the type-level shape and `s` are equivalent
|
||||||
in believe_me $ MkArray COrder sts s (unsafeFromIns (product s) ins)
|
in believe_me $ MkArray COrder sts s (unsafeFromIns (product s) ins)
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ namespace Coords
|
||||||
|
|
||||||
||| Forget the shape of the array by converting each index to type `Nat`.
|
||| Forget the shape of the array by converting each index to type `Nat`.
|
||||||
export
|
export
|
||||||
toNats : Coords {rk} s -> Vect rk Nat
|
toNB : Coords {rk} s -> Vect rk Nat
|
||||||
toNats [] = []
|
toNB [] = []
|
||||||
toNats (i :: is) = finToNat i :: toNats is
|
toNB (i :: is) = finToNat i :: toNB is
|
||||||
|
|
||||||
|
|
||||||
public export
|
public export
|
||||||
|
@ -51,7 +51,7 @@ namespace Coords
|
||||||
||| given its coordinate and the strides of the array.
|
||| given its coordinate and the strides of the array.
|
||||||
export
|
export
|
||||||
getLocation : Vect rk Nat -> Coords {rk} s -> Nat
|
getLocation : Vect rk Nat -> Coords {rk} s -> Nat
|
||||||
getLocation sts is = getLocation' sts (toNats is)
|
getLocation sts is = getLocation' sts (toNB is)
|
||||||
|
|
||||||
|
|
||||||
namespace CoordsRange
|
namespace CoordsRange
|
||||||
|
|
|
@ -77,8 +77,8 @@ index : Fin m -> Fin n -> Matrix m n a -> a
|
||||||
index m n = index [m,n]
|
index m n = index [m,n]
|
||||||
|
|
||||||
export
|
export
|
||||||
indexMaybe : Nat -> Nat -> Matrix m n a -> Maybe a
|
indexNB : Nat -> Nat -> Matrix m n a -> Maybe a
|
||||||
indexMaybe m n = indexMaybe [m,n]
|
indexNB m n = indexNB [m,n]
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
|
@ -66,12 +66,12 @@ export
|
||||||
(!!) = flip index
|
(!!) = flip index
|
||||||
|
|
||||||
export
|
export
|
||||||
indexMaybe : Nat -> Vector n a -> Maybe a
|
indexNB : Nat -> Vector n a -> Maybe a
|
||||||
indexMaybe n = Array.indexMaybe [n]
|
indexNB n = Array.indexNB [n]
|
||||||
|
|
||||||
export
|
export
|
||||||
(!?) : Vector n a -> Nat -> Maybe a
|
(!?) : Vector n a -> Nat -> Maybe a
|
||||||
(!?) = flip indexMaybe
|
(!?) = flip indexNB
|
||||||
|
|
||||||
|
|
||||||
-- Named projections
|
-- Named projections
|
||||||
|
|
Loading…
Reference in a new issue