Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
AMBS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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
esde
machine-learning
AMBS
Commits
c62a4ec6
Commit
c62a4ec6
authored
4 years ago
by
Michael Langguth
Browse files
Options
Downloads
Patches
Plain Diff
Implement reduce_dict to general_utils.py.
Conflicts: video_prediction_tools/utils/general_utils.py
parent
4f5e3a32
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
video_prediction_tools/utils/general_utils.py
+25
-0
25 additions, 0 deletions
video_prediction_tools/utils/general_utils.py
with
25 additions
and
0 deletions
video_prediction_tools/utils/general_utils.py
+
25
−
0
View file @
c62a4ec6
...
@@ -152,6 +152,31 @@ def check_dir(path2dir: str, lcreate=False):
...
@@ -152,6 +152,31 @@ def check_dir(path2dir: str, lcreate=False):
raise
NotADirectoryError
(
"
%{0}: Directory
'
{1}
'
does not exist
"
.
format
(
method
,
path2dir
))
raise
NotADirectoryError
(
"
%{0}: Directory
'
{1}
'
does not exist
"
.
format
(
method
,
path2dir
))
def
reduce_dict
(
dict_in
:
dict
,
dict_ref
:
dict
):
"""
Returns reduced version of input directory with keys only that are also part in reference dictionary
:param dict_in: input dictionary
:param dict_ref: reference dictionary
:return: subset of input dictionary
"""
method
=
reduce_dict
.
__name__
# sanity checks
assert
isinstance
(
dict_in
,
dict
),
"
%{0}: dict_in must be a dictionary, but is of type {1}
"
\
.
format
(
method
,
type
(
dict_in
))
assert
isinstance
(
dict_ref
,
dict
),
"
%{0}: dict_ref must be a dictionary, but is of type {1}
"
\
.
format
(
method
,
type
(
dict_ref
))
if
set
(
dict_ref
.
keys
()).
issubset
(
set
(
dict_in
.
keys
())):
dict_in_subset
=
{
key
:
dict_in
[
key
]
for
key
in
dict_ref
}
else
:
print
(
"
Keys in dict_ref: {0}
"
.
format
(
"
,
"
.
join
(
dict_ref
.
keys
())))
print
(
"
Keys in dict_in: {0}
"
.
format
(
"
,
"
.
join
(
dict_in
.
keys
())))
raise
KeyError
(
"
%{0}: Could not find all required keys from dict_ref in dict_in.
"
.
format
(
method
))
return
dict_in_subset
def
provide_default
(
dict_in
,
keyname
,
default
=
None
,
required
=
False
):
def
provide_default
(
dict_in
,
keyname
,
default
=
None
,
required
=
False
):
"""
"""
Returns values of key from input dictionary or alternatively its default
Returns values of key from input dictionary or alternatively its default
...
...
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