Remove believe_me calls blocking evaluation

This commit is contained in:
Kiana Sheibani 2024-04-28 00:30:52 -04:00
parent 76e4137d37
commit 963f27384f
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
5 changed files with 20 additions and 10 deletions

View file

@ -2,6 +2,7 @@ module Data.NumIdr
import public Data.Permutation
import Data.NumIdr.PrimArray
import public Data.NumIdr.Interfaces
import public Data.NumIdr.Array
import public Data.NumIdr.Scalar

View file

@ -168,7 +168,8 @@ diagonal {n} mat with (viewShape mat)
export
-- TODO: throw an actual proof in here to avoid the unsafety
minor : Fin (S m) -> Fin (S n) -> Matrix (S m) (S n) a -> Matrix m n a
minor i j mat = believe_me $ mat!!..[Filter (/=i), Filter (/=j)]
minor i j mat = replace {p = flip Array a} (believe_me $ Refl {x = ()})
$ mat!!..[Filter (/=i), Filter (/=j)]
filterInd : Num a => (Nat -> Nat -> Bool) -> Matrix m n a -> Matrix m n a
@ -568,7 +569,7 @@ solveLowerTri' {n} mat b with (viewShape b)
construct {i=S i} (b :: bs) =
let xs = construct bs
i' = assert_total $ case natToFin i n of Just i' => i'
in (b - sum (zipWith (*) xs (reverse $ toVect $ believe_me $
in (b - sum (zipWith (*) xs (reverse $ toVect $ replace {p = flip Array a} (believe_me $ Refl {x=()}) $
mat !!.. [One i', EndBound (weaken i')]))) / mat!#[i,i] :: xs
@ -581,7 +582,7 @@ solveUpperTri' {n} mat b with (viewShape b)
construct i (b :: bs) =
let xs = construct (S i) bs
i' = assert_total $ case natToFin i n of Just i' => i'
in (b - sum (zipWith (*) xs (toVect $ believe_me $
in (b - sum (zipWith (*) xs (toVect $ replace {p = flip Array a} (believe_me $ Refl {x=()}) $
mat !!.. [One i', StartBound (FS i')]))) / mat!#[i,i] :: xs

View file

@ -4,6 +4,7 @@ import Data.List
import Data.Vect
import Data.NumIdr.Array.Rep
import Data.NumIdr.Array.Coords
import Data.NumIdr.PrimArray.Linked
%default total
@ -21,8 +22,8 @@ export
indexRange : {s : _} -> (rs : CoordsRange s) -> PrimArrayDelayed s a -> PrimArrayDelayed (newShape rs) a
indexRange [] v = v
indexRange (r :: rs) v with (cRangeToList r)
_ | Left i = indexRange rs (\is' => v (believe_me i :: is'))
_ | Right is = \(i::is') => indexRange rs (\is'' => v (believe_me (Vect.index i (fromList is)) :: is'')) is'
_ | Left i = indexRange rs (\is' => v (assertFin i :: is'))
_ | Right is = \(i::is') => indexRange rs (\is'' => v (assertFin (Vect.index i (fromList is)) :: is'')) is'
export
indexSetRange : {s : _} -> (rs : CoordsRange s) -> PrimArrayDelayed (newShape rs) a

View file

@ -23,19 +23,25 @@ update : Coords s -> (a -> a) -> Vects s a -> Vects s a
update [] f v = f v
update (i :: is) f v = updateAt i (update is f) v
export %unsafe
assertFin : Nat -> Fin n
assertFin n = natToFinLt n @{believe_me Oh}
export
indexRange : {s : _} -> (rs : CoordsRange s) -> Vects s a -> Vects (newShape rs) a
indexRange [] v = v
indexRange (r :: rs) v with (cRangeToList r)
_ | Left i = indexRange rs (Vect.index (believe_me i) v)
_ | Right is = believe_me $ map (\i => indexRange rs (Vect.index (believe_me i) v)) is
_ | Left i = indexRange rs (Vect.index (assertFin i) v)
_ | Right is = assert_total $
case toVect _ (map (\i => indexRange rs (Vect.index (assertFin i) v)) is) of
Just v => v
export
indexSetRange : {s : _} -> (rs : CoordsRange s) -> Vects (newShape rs) a -> Vects s a -> Vects s a
indexSetRange {s=[]} [] rv _ = rv
indexSetRange {s=_::_} (r :: rs) rv v with (cRangeToList r)
_ | Left i = updateAt (believe_me i) (indexSetRange rs rv) v
_ | Right is = foldl (\v,i => updateAt (believe_me i) (indexSetRange rs (Vect.index (believe_me i) rv)) v) v is
_ | Left i = updateAt (assertFin i) (indexSetRange rs rv) v
_ | Right is = foldl (\v,i => updateAt (assertFin i) (indexSetRange rs (Vect.index (assertFin i) rv)) v) v is
export

View file

@ -40,7 +40,8 @@ vector v = rewrite sym (lengthCorrect v)
||| Convert a vector into a `Vect`.
export
toVect : Vector n a -> Vect n a
toVect v = believe_me $ Vect.fromList $ Prelude.toList v
toVect v = replace {p = flip Vect a} (believe_me $ Refl {x=()}) $
Vect.fromList $ Prelude.toList v
||| Return the `i`-th basis vector.
export