Skip to content

Commit

Permalink
Add a failed test that tries to implement filterPositive
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Apr 7, 2024
1 parent 01c1b4d commit 4b565ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HordeAd/Core/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ instance Boolean AstBool where
b ||* c = AstB2 OrOp b c


-- * Boolean definitions and instances
-- * Boolean definitions

class Boolean (BoolOf f) => IfF (f :: TensorType ty) where
ifF :: (GoodScalar r, HasSingletonDict y)
Expand Down
20 changes: 20 additions & 0 deletions test/simplified/TestAdaptorSimplified.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ testTrees =
, testCase "2emptyArgs0" testEmptyArgs0
, testCase "2emptyArgs1" testEmptyArgs1
, testCase "2emptyArgs4" testEmptyArgs4
, testCase "2filterPositiveFail" testFilterPositiveFail
, testCase "2blowupPP" fblowupPP
, testCase "2blowupLetPP" fblowupLetPP
, blowupTests
Expand Down Expand Up @@ -1884,6 +1885,25 @@ testEmptyArgs4 =
(\t -> rbuild [2, 5, 11, 0] (const $ emptyArgs t))
(Flip $ OR.fromList [1] [0.24]))

filterPositiveFail :: ADReady ranked
=> ranked Double 1 -> ranked Double 1
filterPositiveFail v =
let l = runravelToList v
-- l2 = filter (\x -> x >= 0) l
-- Could not deduce ‘Ord (ranked Double 0)’
-- l2 = filter (\x -> x >=. 0) l
-- Could not deduce ‘BoolOf ranked ~ Bool’
l2 = take 3 l -- the most I can do
in rfromList l2

testFilterPositiveFail :: Assertion
testFilterPositiveFail =
assertEqualUpToEpsilon' 1e-10
(OR.fromList [5] [1.0,1.0,1.0,0.0,0.0])
(rev' @Double @1
filterPositiveFail
(Flip $ OR.fromList [5] [0.24, 52, -0.5, 0.33, 0.1]))

-- Catastrophic loss of sharing prevented.
fblowup :: forall ranked r. (ADReady ranked, GoodScalar r, Differentiable r)
=> Int -> ranked r 1 -> ranked r 0
Expand Down

0 comments on commit 4b565ae

Please sign in to comment.