Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pipelines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
bob
bob.pipelines
Commits
a31bbd39
Commit
a31bbd39
authored
5 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Make a sampleset work transparently with list of DelayedSamples
parent
7bf65c2b
No related branches found
No related tags found
1 merge request
!31
Make a sampleset work transparently with list of DelayedSamples
Pipeline
#39886
passed
5 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/pipelines/sample.py
+10
-0
10 additions, 0 deletions
bob/pipelines/sample.py
bob/pipelines/tests/test_samples.py
+20
-1
20 additions, 1 deletion
bob/pipelines/tests/test_samples.py
with
30 additions
and
1 deletion
bob/pipelines/sample.py
+
10
−
0
View file @
a31bbd39
...
...
@@ -99,19 +99,29 @@ class SampleSet(MutableSequence, _ReprMixin):
_copy_attributes
(
self
,
parent
.
__dict__
)
_copy_attributes
(
self
,
kwargs
)
def
_load
(
self
):
if
isinstance
(
self
.
samples
,
DelayedSample
):
self
.
samples
=
self
.
samples
.
data
def
__len__
(
self
):
self
.
_load
()
return
len
(
self
.
samples
)
def
__getitem__
(
self
,
item
):
self
.
_load
()
return
self
.
samples
.
__getitem__
(
item
)
def
__setitem__
(
self
,
key
,
item
):
self
.
_load
()
return
self
.
samples
.
__setitem__
(
key
,
item
)
def
__delitem__
(
self
,
item
):
self
.
_load
()
return
self
.
samples
.
__delitem__
(
item
)
def
insert
(
self
,
index
,
item
):
self
.
_load
()
# if not item in self.samples:
self
.
samples
.
insert
(
index
,
item
)
...
...
This diff is collapsed.
Click to expand it.
bob/pipelines/tests/test_samples.py
+
20
−
1
View file @
a31bbd39
...
...
@@ -2,7 +2,10 @@ import bob.pipelines as mario
import
numpy
import
copy
import
pickle
import
tempfile
import
functools
import
os
def
test_sampleset_collection
():
...
...
@@ -28,3 +31,19 @@ def test_sampleset_collection():
# Testing iterator
for
i
in
sampleset
:
assert
isinstance
(
i
,
mario
.
Sample
)
def
_load
(
path
):
return
pickle
.
loads
(
open
(
path
,
"
rb
"
).
read
())
# Testing delayed sample in the sampleset
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
samples
=
[
mario
.
Sample
(
data
,
key
=
str
(
i
))
for
i
,
data
in
enumerate
(
X
)]
filename
=
os
.
path
.
join
(
dir_name
,
"
samples.pkl
"
)
with
open
(
filename
,
"
wb
"
)
as
f
:
f
.
write
(
pickle
.
dumps
(
samples
))
sampleset
=
mario
.
SampleSet
(
mario
.
DelayedSample
(
functools
.
partial
(
_load
,
filename
)),
key
=
1
)
assert
len
(
sampleset
)
==
n_samples
\ No newline at end of file
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