<s> from __future__ import absolute_import , print_function , division <EOL> import numpy <EOL> import theano <EOL> def test_detect_nan ( ) : <EOL> """<STR_LIT>""" <EOL> nan_detected = [ False ] <EOL> def detect_nan ( i , node , fn ) : <EOL> for output in fn . outputs : <EOL> if numpy . isnan ( output [ <NUM_LIT:0> ] ) . any ( ) : <EOL> print ( '<STR_LIT>' ) <EOL> theano . printing . debugprint ( node ) <EOL> print ( '<STR_LIT>' % [ input [ <NUM_LIT:0> ] for input in fn . inputs ] ) <EOL> print ( '<STR_LIT>' % [ output [ <NUM_LIT:0> ] for output in fn . outputs ] ) <EOL> nan_detected [ <NUM_LIT:0> ] = True <EOL> break <EOL> x = theano . tensor . dscalar ( '<STR_LIT:x>' ) <EOL> f = theano . function ( [ x ] , [ theano . tensor . log ( x ) * x ] , <EOL> mode = theano . compile . MonitorMode ( <EOL> post_func = detect_nan ) ) <EOL> f ( <NUM_LIT:0> ) <EOL> assert nan_detected [ <NUM_LIT:0> ] <EOL> def test_optimizer ( ) : <EOL> """<STR_LIT>""" <EOL> nan_detected = [ False ] <EOL> def detect_nan ( i , node , fn ) : <EOL> for output in fn . outputs : <EOL> if numpy . isnan ( output [ <NUM_LIT:0> ] ) . any ( ) : <EOL> print ( '<STR_LIT>' ) <EOL> theano . printing . debugprint ( node ) <EOL> print ( '<STR_LIT>' % [ input [ <NUM_LIT:0> ] for input in fn . inputs ] ) <EOL> print ( '<STR_LIT>' % [ output [ <NUM_LIT:0> ] for output in fn . outputs ] ) <EOL> nan_detected [ <NUM_LIT:0> ] = True <EOL> break <EOL> x = theano . tensor . dscalar ( '<STR_LIT:x>' ) <EOL> mode = theano . compile . MonitorMode ( post_func = detect_nan ) <EOL> mode = mode . excluding ( '<STR_LIT>' ) <EOL> f = theano . function ( [ x ] , [ theano . tensor . log ( x ) * x ] , <EOL> mode = mode ) <EOL> assert len ( f . maker . fgraph . apply_nodes ) == <NUM_LIT:2> <EOL> f ( <NUM_LIT:0> ) <EOL> assert nan_detected [ <NUM_LIT:0> ] <EOL> def test_not_inplace ( ) : <EOL> """<STR_LIT>""" <EOL> nan_detected = [ False ] <EOL> def detect_nan ( i , node , fn ) : <EOL> for output in fn . outputs : <EOL> if numpy . isnan ( output [ <NUM_LIT:0> ] ) . any ( ) : <EOL> print ( '<STR_LIT>' ) <EOL> theano . printing . debugprint ( node ) <EOL> print ( '<STR_LIT>' % [ input [ <NUM_LIT:0> ] for input in fn . inputs ] ) <EOL> print ( '<STR_LIT>' % [ output [ <NUM_LIT:0> ] for output in fn . outputs ] ) <EOL> nan_detected [ <NUM_LIT:0> ] = True <EOL> break <EOL> x = theano . tensor . vector ( '<STR_LIT:x>' ) <EOL> mode = theano . compile . MonitorMode ( post_func = detect_nan ) <EOL> mode = mode . excluding ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> o = theano . tensor . outer ( x , x ) <EOL> out = theano . tensor . log ( o ) * o <EOL> f = theano . function ( [ x ] , [ out ] , <EOL> mode = mode ) <EOL> assert len ( f . maker . fgraph . apply_nodes ) == <NUM_LIT:5> <EOL> assert not f . maker . fgraph . toposort ( ) [ - <NUM_LIT:1> ] . op . destroy_map <EOL> f ( [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> assert nan_detected [ <NUM_LIT:0> ] </s>
