Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rtree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
chrg
rtree
Commits
37eb0c64
Commit
37eb0c64
authored
1 year ago
by
chrg
Browse files
Options
Downloads
Patches
Plain Diff
Add fibonacci mode
parent
a5fdcebd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rtree-c/bin/Main.hs
+17
-6
17 additions, 6 deletions
rtree-c/bin/Main.hs
rtree/src/Control/Monad/IRTree.hs
+41
-0
41 additions, 0 deletions
rtree/src/Control/Monad/IRTree.hs
rtree/test/src/Control/Monad/IRTreeSpec.hs
+11
-8
11 additions, 8 deletions
rtree/test/src/Control/Monad/IRTreeSpec.hs
with
69 additions
and
14 deletions
rtree-c/bin/Main.hs
+
17
−
6
View file @
37eb0c64
...
...
@@ -49,13 +49,20 @@ process sev p ma = do
s
=
withFrozenCallStack
callStack
msg
t
=
Colog
.
logMsg
(
Msg
sev
s
(
t
<>
p
))
data
Mode
=
Lin
|
Exp
|
Fib
deriving
(
Show
,
Read
,
Eq
,
Ord
,
Enum
)
run
::
(
HasCallStack
)
=>
Parser
(
IO
()
)
run
=
do
exp
mode
<-
flag
False
True
$
mode
<-
option
auto
$
fold
[
long
"exp"
,
help
"run in exponential mode"
[
long
"mode"
,
help
"search mode (Lin, Exp, Fib)"
,
value
"Lin"
]
checkmode
<-
...
...
@@ -206,12 +213,16 @@ run = do
l
<-
c
&
fix
\
rec
prevc
->
do
mc'
<-
(
if
expmode
then
IRTree
.
reduceExp
else
IRTree
.
reduce
)
(
case
mode
of
Lin
->
IRTree
.
reduce
Exp
->
IRTree
.
reduceExp
Fib
->
IRTree
.
reduceFib
)
(
check'
file
)
(
ReduceC
.
defaultReduceC
prevc
)
case
mc'
of
Just
c'
->
if
fixpoint
&&
c'
/=
c
if
fixpoint
&&
(
c'
$>
()
)
/=
(
prevc
$>
()
)
then
do
logInfo
"Running again until fixpoint"
rec
c'
...
...
This diff is collapsed.
Click to expand it.
rtree/src/Control/Monad/IRTree.hs
+
41
−
0
View file @
37eb0c64
...
...
@@ -12,12 +12,14 @@ module Control.Monad.IRTree (
probe
,
reduce
,
reduceExp
,
reduceFib
,
-- * IRTreeT
IRTreeT
,
probeT
,
extractT
,
reduceT
,
reduceFibT
,
reduceExpT
,
-- * Re-exports
...
...
@@ -105,6 +107,14 @@ reduceExp
reduceExp
=
reduceExpT
(
pure
.
runIdentity
)
{-# INLINE reduceExp #-}
reduceFib
::
(
Monad
m
)
=>
([(
Bool
,
l
)]
->
i
->
m
Bool
)
->
IRTree
l
i
->
m
(
Maybe
i
)
reduceFib
=
reduceFibT
(
pure
.
runIdentity
)
{-# INLINE reduceFib #-}
-- | Interpreted reduction with an m base monad, and running in expoential mode.
reduceExpT
::
(
Monad
m
,
Functor
t
)
...
...
@@ -135,3 +145,34 @@ reduceExpT lift_ p rt = do
n'
->
go
(
n'
-
1
)
sq
else
pure
i
{-# INLINE reduceExpT #-}
-- | Interpreted reduction with an m base monad, and running in fibonacci mode.
reduceFibT
::
(
Monad
m
,
Functor
t
)
=>
(
forall
a
.
t
a
->
m
a
)
-- ^ a lift of monad m into t (normally @id@ or @lift@)
->
([(
Bool
,
l
)]
->
i
->
m
Bool
)
->
IRTreeT
l
t
i
->
m
(
Maybe
i
)
reduceFibT
lift_
p
rt
=
do
(
i
,
l
)
<-
lift_
(
probeT
rt
""
)
t
<-
p
l
i
if
t
then
Just
<$>
go
1
1
Seq
.
empty
else
pure
Nothing
where
go
n
m
sq
=
do
let
depth
=
m
let
sq'
=
sq
<>
Seq
.
replicate
depth
True
let
pth'
=
fromChoiceList
(
toList
sq'
)
(
i
,
l
)
<-
lift_
(
probeT
rt
pth'
)
if
length
l
>=
numberOfChoices
pth'
-
depth
+
1
then
do
t
<-
p
l
i
if
t
then
go
m
(
n
+
m
)
sq'
else
case
m
of
1
->
go
1
1
(
sq
Seq
.|>
False
)
m'
->
go
(
m'
-
n
)
n
sq
else
pure
i
{-# INLINE reduceFibT #-}
This diff is collapsed.
Click to expand it.
rtree/test/src/Control/Monad/IRTreeSpec.hs
+
11
−
8
View file @
37eb0c64
...
...
@@ -35,11 +35,11 @@ spec = describe "examples" do
let
re
=
runReaderT
(
Expr
.
rExpr
e
)
Map
.
empty
--
let
--
predicate :: Expr -> IO Bool
--
predicate = pure . contains isOpr
let
predicate
::
Expr
->
IO
Bool
predicate
=
pure
.
contains
isOpr
--
rex <- runIO $ RTree.reduce predicate re
rex
<-
runIO
$
RTree
.
reduce
predicate
re
-- onGlitterWith
-- ("test/expected/" <> str <> "-red")
...
...
@@ -52,10 +52,13 @@ spec = describe "examples" do
-- it "should produce the same results as the RTree" \mex -> do
-- rex `shouldBe` mex
-- it "should find an opr exponentially" do
-- (mex, result) <- runWriterT (IRTree.reduceExp (debugPredicate showString (prettyExprS 0) predicate) me)
-- rex `shouldBe` mex
-- pure $ glitter ("test/expected/" <> str <> "-red-exp") (appEndo result "")
it
"should find an opr exponentially"
do
(
mex
,
_
)
<-
runWriterT
(
IRTree
.
reduceExp
(
debugPredicate
showString
(
prettyExprS
0
)
predicate
)
me
)
rex
`
shouldBe
`
mex
it
"should find an opr fibonacci"
do
(
mex
,
_
)
<-
runWriterT
(
IRTree
.
reduceFib
(
debugPredicate
showString
(
prettyExprS
0
)
predicate
)
me
)
rex
`
shouldBe
`
mex
it
"should reduce like iinputs"
do
forM_
(
RTree
.
iinputs
re
)
\
(
ii
,
e'
)
->
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment