mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-19 01:01:59 +03:00
[ cleanup ] move auxiliary function to where block
This commit is contained in:
parent
03484f2dfa
commit
291d60da08
@ -99,13 +99,6 @@ namespace Vector1
|
|||||||
maxIndex1 : Vector1 a -> Nat
|
maxIndex1 : Vector1 a -> Nat
|
||||||
maxIndex1 ((i, x) ::: xs) = maybe i fst (last' xs)
|
maxIndex1 ((i, x) ::: xs) = maybe i fst (last' xs)
|
||||||
|
|
||||||
vectorFromList : List a -> Vector a
|
|
||||||
vectorFromList = go Z
|
|
||||||
where
|
|
||||||
go : Nat -> List a -> Vector a
|
|
||||||
go i [] = []
|
|
||||||
go i (x :: xs) = (i, x) :: go (S i) xs
|
|
||||||
|
|
||||||
||| A sparse matrix is a sparse vector of (non-empty) sparse vectors.
|
||| A sparse matrix is a sparse vector of (non-empty) sparse vectors.
|
||||||
public export
|
public export
|
||||||
Matrix : Type -> Type
|
Matrix : Type -> Type
|
||||||
@ -113,7 +106,15 @@ Matrix a = Vector (Vector1 a)
|
|||||||
|
|
||||||
export
|
export
|
||||||
fromListList : (Eq a, Semiring a) => List (List a) -> Matrix a
|
fromListList : (Eq a, Semiring a) => List (List a) -> Matrix a
|
||||||
fromListList = mapMaybe (\(i, xs) => map (i,) (fromList1 xs)) . vectorFromList
|
fromListList = mapMaybe (\(i, xs) => map (i,) (fromList1 xs)) . withIndex
|
||||||
|
where
|
||||||
|
-- may contain empty lists
|
||||||
|
withIndex : List (List a) -> List (Nat, List a)
|
||||||
|
withIndex = go Z
|
||||||
|
where
|
||||||
|
go : Nat -> List (List a) -> List (Nat, List a)
|
||||||
|
go i [] = []
|
||||||
|
go i (x :: xs) = (i, x) :: go (S i) xs
|
||||||
|
|
||||||
export
|
export
|
||||||
transpose : Matrix a -> Matrix a
|
transpose : Matrix a -> Matrix a
|
||||||
|
Loading…
Reference in New Issue
Block a user