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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.pipelines
Merge requests
!46
move vstack_features to bob.io.base
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
move vstack_features to bob.io.base
remove-vstack-features
into
master
Overview
0
Commits
1
Pipelines
1
Changes
3
Merged
move vstack_features to bob.io.base
Amir MOHAMMADI
requested to merge
remove-vstack-features
into
master
Nov 13, 2020
Overview
0
Commits
1
Pipelines
1
Changes
3
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
6858dff8
1 commit,
Nov 13, 2020
3 files
+
1
−
266
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
bob/pipelines/tests/test_utils.py
+
0
−
120
View file @ 6858dff8
Edit in single-file editor
Open in Web IDE
Show full file
import
os
from
tempfile
import
NamedTemporaryFile
import
nose
import
numpy
as
np
import
bob.pipelines
as
mario
def
test_io_vstack
():
paths
=
[
1
,
2
,
3
,
4
,
5
]
def
asser_
(
actual
,
desired
,
dtype
=
None
):
np
.
testing
.
assert_allclose
(
actual
,
desired
)
if
dtype
is
not
None
:
assert
actual
.
dtype
==
dtype
,
(
actual
.
dtype
,
dtype
)
def
oracle
(
reader
,
paths
):
return
np
.
vstack
([
reader
(
p
)
for
p
in
paths
])
def
reader_same_size_C
(
path
):
return
np
.
arange
(
10
).
reshape
(
5
,
2
)
+
path
def
reader_different_size_C
(
path
):
return
np
.
arange
(
2
*
path
).
reshape
(
path
,
2
)
+
path
def
reader_same_size_F
(
path
):
return
np
.
asfortranarray
(
np
.
arange
(
10
).
reshape
(
5
,
2
))
+
path
def
reader_different_size_F
(
path
):
return
np
.
asfortranarray
(
np
.
arange
(
2
*
path
).
reshape
(
path
,
2
))
+
path
def
reader_same_size_C2
(
path
):
return
np
.
arange
(
30
).
reshape
(
5
,
2
,
3
)
+
path
def
reader_different_size_C2
(
path
):
return
np
.
arange
(
6
*
path
).
reshape
(
path
,
2
,
3
)
+
path
def
reader_same_size_F2
(
path
):
return
np
.
asfortranarray
(
np
.
arange
(
30
).
reshape
(
5
,
2
,
3
))
+
path
def
reader_different_size_F2
(
path
):
return
np
.
asfortranarray
(
np
.
arange
(
6
*
path
).
reshape
(
path
,
2
,
3
))
+
path
def
reader_wrong_size
(
path
):
return
np
.
arange
(
2
*
path
).
reshape
(
2
,
path
)
+
path
dtype
=
"
float32
"
# when same_size is False
for
reader
in
[
reader_different_size_C
,
reader_different_size_F
,
reader_same_size_C
,
reader_same_size_F
,
reader_different_size_C2
,
reader_different_size_F2
,
reader_same_size_C2
,
reader_same_size_F2
,
]:
asser_
(
mario
.
utils
.
vstack_features
(
reader
,
paths
),
oracle
(
reader
,
paths
))
asser_
(
mario
.
utils
.
vstack_features
(
reader
,
paths
,
dtype
=
dtype
),
oracle
(
reader
,
paths
),
dtype
,
)
# when same_size is True
for
reader
in
[
reader_same_size_C
,
reader_same_size_F
,
reader_same_size_C2
,
reader_same_size_F2
,
]:
asser_
(
mario
.
utils
.
vstack_features
(
reader
,
paths
,
True
),
oracle
(
reader
,
paths
))
asser_
(
mario
.
utils
.
vstack_features
(
reader
,
paths
,
True
,
dtype
=
dtype
),
oracle
(
reader
,
paths
),
dtype
,
)
with
nose
.
tools
.
assert_raises
(
AssertionError
):
mario
.
utils
.
vstack_features
(
reader_wrong_size
,
paths
)
# test actual files
suffix
=
"
.npy
"
with
NamedTemporaryFile
(
suffix
=
suffix
)
as
f1
,
NamedTemporaryFile
(
suffix
=
suffix
)
as
f2
,
NamedTemporaryFile
(
suffix
=
suffix
)
as
f3
:
paths
=
[
f1
.
name
,
f2
.
name
,
f3
.
name
]
# try different readers:
for
reader
in
[
reader_different_size_C
,
reader_different_size_F
,
reader_same_size_C
,
reader_same_size_F
,
reader_different_size_C2
,
reader_different_size_F2
,
reader_same_size_C2
,
reader_same_size_F2
,
]:
# save some data in files
for
i
,
path
in
enumerate
(
paths
):
np
.
save
(
path
,
reader
(
i
+
1
),
allow_pickle
=
False
)
# test when all data is present
reference
=
oracle
(
np
.
load
,
paths
)
asser_
(
mario
.
utils
.
vstack_features
(
np
.
load
,
paths
),
reference
)
asser_
(
mario
.
utils
.
vstack_features
(
np
.
load
,
paths
,
dtype
=
dtype
),
reference
,
dtype
,
)
try
:
os
.
remove
(
paths
[
0
])
# Check if RuntimeError is raised when one of the files is missing
with
nose
.
tools
.
assert_raises
(
FileNotFoundError
):
mario
.
utils
.
vstack_features
(
np
.
load
,
paths
)
finally
:
# create the file back so NamedTemporaryFile does not complain
np
.
save
(
paths
[
0
],
reader
(
i
+
1
))
def
test_isinstance_nested
():
class
A
:
pass
Loading