Created
March 8, 2012 06:28
-
-
Save utunga/1999180 to your computer and use it in GitHub Desktop.
test for on_unused_input flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import theano | |
import theano.tensor as T | |
a = T.vector(name='a') | |
b = T.vector(name='b') | |
x = T.vector(name='x') | |
x = a*2 | |
try: | |
f = theano.function((a,b), outputs=x) | |
except ValueError as ex: | |
expected_error = \ | |
"theano.function was asked to create a function computing outputs given " + \ | |
"certain inputs, but one of the provided input variables is not part of the " + \ | |
"computational graph needed to compute the outputs: b.\n" + \ | |
"To make this error into a warning, you can pass the parameter "+ \ | |
"on_unused_input='warn' to theano.function. To disable it completely, "+ \ | |
"use on_unused_input='ignore'." | |
assert(str(ex)==expected_error) | |
# 'ignore' works fine .. | |
f = theano.function((a,b), outputs=x, on_unused_input='ignore') | |
# 'warn' not so much | |
f = theano.function((a,b), outputs=x, on_unused_input='warn') | |
# gives this output: | |
# Traceback (most recent call last): | |
# File "test_on_unused_input.py", line 25, in <module> | |
# f = theano.function((a,b), outputs=x, on_unused_input='warn') | |
# File "/Users/utunga/dev/Theano/theano/compile/function.py", line 119, in function | |
# profile=profile) | |
# File "/Users/utunga/dev/Theano/theano/compile/pfunc.py", line 469, in pfunc | |
# on_unused_input=on_unused_input) | |
# File "/Users/utunga/dev/Theano/theano/compile/function_module.py", line 1345, in orig_function | |
# on_unused_input=on_unused_input).create( | |
# File "/Users/utunga/dev/Theano/theano/compile/function_module.py", line 1016, in __init__ | |
# self._check_unused_inputs(inputs, outputs, on_unused_input) | |
# File "/Users/utunga/dev/Theano/theano/compile/function_module.py", line 1111, in _check_unused_inputs | |
# warnings.warn(msg % (i.variable, warn_msg), stacklevel=5) | |
# NameError: global name 'warnings' is not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment