Add Show instance for NP
This commit is contained in:
parent
6cdb22a6ed
commit
1ebf0dcbe9
|
@ -13,8 +13,17 @@ data NP : (f : k -> Type) -> (ts : Vect n k) -> Type where
|
||||||
|
|
||||||
public export
|
public export
|
||||||
(all : NP (Eq . f) ts) => Eq (NP f ts) where
|
(all : NP (Eq . f) ts) => Eq (NP f ts) where
|
||||||
(==) {all = []} [] [] = True
|
(==) {all=[]} [] [] = True
|
||||||
(==) {all = _ :: _} (x :: xs) (y :: ys) = (x == y) && (xs == ys)
|
(==) {all=_::_} (x :: xs) (y :: ys) = (x == y) && (xs == ys)
|
||||||
|
|
||||||
|
public export
|
||||||
|
(all : NP (Show . f) ts) => Show (NP f ts) where
|
||||||
|
show xs = "[" ++ elems xs ++ "]"
|
||||||
|
where
|
||||||
|
elems : {0 f,ts : _} -> (all : NP (Show . f) ts) => NP f ts -> String
|
||||||
|
elems {all=[]} [] = ""
|
||||||
|
elems {all=[_]} [x] = show x
|
||||||
|
elems {all=_::_} (x :: xs) = show x ++ ", " ++ elems xs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -276,10 +276,9 @@ indexSet is = indexUpdate is . const
|
||||||
||| coordinates are out of bounds.
|
||| coordinates are out of bounds.
|
||||||
export
|
export
|
||||||
indexNB : Vect rk Nat -> Array {rk} s a -> Maybe a
|
indexNB : Vect rk Nat -> Array {rk} s a -> Maybe a
|
||||||
indexNB is arr with (viewShape arr)
|
indexNB is arr = if and $ map delay $ zipWith (<) is (shape arr)
|
||||||
_ | Shape s = if concat @{All} $ zipWith (<) is s
|
then Just $ index (getLocation' (strides arr) is) (getPrim arr)
|
||||||
then Just $ index (getLocation' (strides arr) is) (getPrim arr)
|
else Nothing
|
||||||
else Nothing
|
|
||||||
|
|
||||||
||| Index the array using the given coordinates, returning `Nothing` if the
|
||| Index the array using the given coordinates, returning `Nothing` if the
|
||||||
||| coordinates are out of bounds.
|
||| 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
|
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.
|
||| List all of the values in an array along with their coordinates.
|
||||||
export
|
export
|
||||||
enumerateNB : Array {rk} s a -> List (Vect rk Nat, a)
|
enumerateNB : Array {rk} s a -> List (Vect rk Nat, a)
|
||||||
|
|
|
@ -103,8 +103,8 @@ namespace CoordsRange
|
||||||
getNewPos : {s : _} -> (rs : CoordsRange {rk} s) -> Vect rk Nat -> Vect (newRank rs) Nat
|
getNewPos : {s : _} -> (rs : CoordsRange {rk} s) -> Vect rk Nat -> Vect (newRank rs) Nat
|
||||||
getNewPos [] [] = []
|
getNewPos [] [] = []
|
||||||
getNewPos (r :: rs) (i :: is) with (cRangeToBounds r)
|
getNewPos (r :: rs) (i :: is) with (cRangeToBounds r)
|
||||||
getNewPos (r :: rs) (i :: is) | Left _ = getNewPos rs is
|
_ | Left _ = getNewPos rs is
|
||||||
getNewPos (r :: rs) (i :: is) | Right (x, _) = minus i x :: getNewPos rs is
|
_ | Right (x, _) = minus i x :: getNewPos rs is
|
||||||
|
|
||||||
export
|
export
|
||||||
getCoordsList : {s : Vect rk Nat} -> (rs : CoordsRange s) -> List (Vect rk Nat, Vect (newRank rs) Nat)
|
getCoordsList : {s : Vect rk Nat} -> (rs : CoordsRange s) -> List (Vect rk Nat, Vect (newRank rs) Nat)
|
||||||
|
|
|
@ -11,11 +11,9 @@ import Data.Vect
|
||||||
||| memory location.
|
||| memory location.
|
||||||
public export
|
public export
|
||||||
data Order : Type where
|
data Order : Type where
|
||||||
|
|
||||||
||| C-like order, or contiguous order. This order stores elements in a
|
||| C-like order, or contiguous order. This order stores elements in a
|
||||||
||| row-major fashion (the last axis is the least significant).
|
||| row-major fashion (the last axis is the least significant).
|
||||||
COrder : Order
|
COrder : Order
|
||||||
|
|
||||||
||| Fortran-like order. This order stores elements in a column-major
|
||| Fortran-like order. This order stores elements in a column-major
|
||||||
||| fashion (the first axis is the least significant).
|
||| fashion (the first axis is the least significant).
|
||||||
FOrder : Order
|
FOrder : Order
|
||||||
|
|
Loading…
Reference in a new issue