Skip to content

Commit

Permalink
Use defaultdict for _UID_PREFIXES
Browse files Browse the repository at this point in the history
The method get_uid on common.py first check if a prefix is in _UID_PREFIXED dict
and if it is not, a variable is added to the dict.

However, using a defaultdict, this check is no longer necessary.
  • Loading branch information
lucasmoura committed Jul 1, 2016
1 parent a1610eb commit 2a28d2e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions keras/backend/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import numpy as np

from collections import defaultdict

# the type of float to use throughout the session.
_FLOATX = 'float32'
_EPSILON = 10e-8
_UID_PREFIXES = {}
_UID_PREFIXES = defaultdict(int)
_IMAGE_DIM_ORDERING = 'th'


Expand Down Expand Up @@ -60,9 +62,5 @@ def set_image_dim_ordering(dim_ordering):


def get_uid(prefix=''):
if prefix not in _UID_PREFIXES:
_UID_PREFIXES[prefix] = 1
return 1
else:
_UID_PREFIXES[prefix] += 1
return _UID_PREFIXES[prefix]
_UID_PREFIXES[prefix] += 1
return _UID_PREFIXES[prefix]

0 comments on commit 2a28d2e

Please sign in to comment.