Skip to content

Commit

Permalink
add informative message to all raise errors (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinvtran authored Mar 20, 2017
1 parent 4395319 commit b96f2ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions edward/inferences/gan_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __init__(self, data, discriminator):
>>>
>>> inference = ed.GANInference({x: x_data}, discriminator)
"""
if discriminator is None:
raise NotImplementedError()
if not callable(discriminator):
raise TypeError("discriminator must be a callable function.")

self.discriminator = discriminator
super(GANInference, self).__init__(None, data)
Expand Down Expand Up @@ -175,7 +175,7 @@ def update(self, feed_dict=None, variables=None):
[self.train_d, self.increment_t, self.loss_d], feed_dict)
loss = 0.0
else:
raise NotImplementedError()
raise NotImplementedError("variables must be None, 'Gen', or 'Disc'.")

if self.debug:
sess.run(self.op_check)
Expand Down Expand Up @@ -225,6 +225,6 @@ def _build_optimizer(optimizer, global_step):
else:
raise ValueError('Optimizer class not found:', optimizer)
elif not isinstance(optimizer, tf.train.Optimizer):
raise TypeError()
raise TypeError("Optimizer must be a tf.train.Optimizer object.")

return optimizer, global_step
11 changes: 5 additions & 6 deletions edward/inferences/implicit_klqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from edward.inferences.gan_inference import GANInference
from edward.models import RandomVariable
from edward.util import copy, get_session
from edward.util import check_latent_vars, copy, get_session


class ImplicitKLqp(GANInference):
Expand Down Expand Up @@ -70,15 +70,14 @@ def __init__(self, latent_vars, data=None, discriminator=None,
its corresponding output, ``discriminator`` must output a
dictionary of same size and keys as ``scale``.
"""
if discriminator is None:
raise NotImplementedError()
if not callable(discriminator):
raise TypeError("discriminator must be a callable function.")

self.discriminator = discriminator
if global_vars is None:
global_vars = {}
elif not isinstance(latent_vars, dict):
raise TypeError()

self.discriminator = discriminator
check_latent_vars(global_vars)
self.global_vars = global_vars
# call grandparent's method; avoid parent (GANInference)
super(GANInference, self).__init__(latent_vars, data)
Expand Down
2 changes: 1 addition & 1 deletion edward/inferences/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def initialize(self, n_iter=1000, n_print=None, scale=None, logdir=None,
if scale is None:
scale = {}
elif not isinstance(scale, dict):
raise TypeError()
raise TypeError("scale must be a dict object.")

self.scale = scale

Expand Down
2 changes: 1 addition & 1 deletion edward/util/random_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def get_dims(x):
elif isinstance(x, RandomVariable):
return x.get_batch_shape().as_list()
else:
raise NotImplementedError()
raise TypeError("Input has invalid type: {}".format(type(x)))


def get_parents(x, collection=None):
Expand Down

0 comments on commit b96f2ab

Please sign in to comment.