<s> from __future__ import absolute_import , print_function , division <EOL> import numpy <EOL> import theano <EOL> from theano . compat import izip <EOL> from theano . gof . utils import hash_from_code <EOL> def hash_from_ndarray ( data ) : <EOL> """<STR_LIT>""" <EOL> if not data . flags [ "<STR_LIT>" ] : <EOL> data = numpy . ascontiguousarray ( data ) <EOL> return hash_from_code ( hash_from_code ( data ) + <EOL> hash_from_code ( str ( data . shape ) ) + <EOL> hash_from_code ( str ( data . strides ) ) + <EOL> hash_from_code ( str ( data . dtype ) ) ) <EOL> def shape_of_variables ( fgraph , input_shapes ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( fgraph , '<STR_LIT>' ) : <EOL> fgraph . attach_feature ( theano . tensor . opt . ShapeFeature ( ) ) <EOL> input_dims = [ dimension for inp in fgraph . inputs <EOL> for dimension in fgraph . shape_feature . shape_of [ inp ] ] <EOL> output_dims = [ dimension for shape in fgraph . shape_feature . shape_of . values ( ) <EOL> for dimension in shape ] <EOL> compute_shapes = theano . function ( input_dims , output_dims ) <EOL> if any ( [ i not in fgraph . inputs for i in input_shapes . keys ( ) ] ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> numeric_input_dims = [ dim for inp in fgraph . inputs <EOL> for dim in input_shapes [ inp ] ] <EOL> numeric_output_dims = compute_shapes ( * numeric_input_dims ) <EOL> sym_to_num_dict = dict ( izip ( output_dims , numeric_output_dims ) ) <EOL> l = { } <EOL> for var in fgraph . shape_feature . shape_of : <EOL> l [ var ] = tuple ( sym_to_num_dict [ sym ] <EOL> for sym in fgraph . shape_feature . shape_of [ var ] ) <EOL> return l </s>
