Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is archived. Its data is
read-only
.
Show more breadcrumbs
Quantum Tinkerer
adaptive
Commits
16666020
Commit
16666020
authored
Sep 6, 2017
by
Bas Nijholt
Browse files
Options
Downloads
Patches
Plain Diff
add contextmanager
parent
c0ff642c
No related branches found
No related tags found
1 merge request
!7
implement 2D learner
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
adaptive/learner.py
+20
-13
20 additions, 13 deletions
adaptive/learner.py
with
20 additions
and
13 deletions
adaptive/learner.py
+
20
−
13
View file @
16666020
# -*- coding: utf-8 -*-
import
abc
from
contextlib
import
contextmanager
from
copy
import
deepcopy
as
copy
import
functools
import
heapq
...
...
@@ -833,16 +834,22 @@ class Learner2D(BaseLearner):
z
=
ip
(
x
[:,
None
],
y
[
None
,
:])
return
hv
.
Image
(
z
)
def
save_state
(
self
):
self
.
_values_copy
=
self
.
_values
.
copy
()
self
.
_points_copy
=
self
.
_points
.
copy
()
self
.
_interp_copy
=
copy
(
self
.
_interp
)
self
.
_stack_copy
=
copy
(
self
.
_stack
)
self
.
n_copy
=
self
.
n
def
reset_state
(
self
):
self
.
_values
=
self
.
_values_copy
.
copy
()
self
.
_points
=
self
.
_points_copy
.
copy
()
self
.
_interp
=
copy
(
self
.
_interp_copy
)
self
.
_stack
=
copy
(
self
.
_stack_copy
)
self
.
n
=
self
.
n_copy
def
__getstate__
(
self
):
return
(
self
.
_values
.
copy
(),
self
.
_points
.
copy
(),
copy
(
self
.
_interp
),
copy
(
self
.
_stack
),
self
.
n
)
def
__setstate__
(
self
,
state
):
self
.
_values
,
self
.
_points
,
self
.
_interp
,
self
.
_stack
,
self
.
n
=
state
@contextmanager
def
restore
(
*
learners
):
states
=
[
learner
.
__getstate__
()
for
learner
in
learners
]
try
:
yield
finally
:
for
state
,
learner
in
zip
(
states
,
learners
):
learner
.
__setstate__
(
state
)
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