<s> from __future__ import absolute_import , print_function , division <EOL> import traceback <EOL> import numpy <EOL> from six import integer_types <EOL> import theano . tensor . basic <EOL> from theano . tensor . basic import TensorType , _tensor_py_operators <EOL> from theano . compile import shared_constructor , SharedVariable <EOL> def load_shared_variable ( val ) : <EOL> """<STR_LIT>""" <EOL> return tensor_constructor ( val ) <EOL> class TensorSharedVariable ( _tensor_py_operators , SharedVariable ) : <EOL> pass <EOL> @ shared_constructor <EOL> def tensor_constructor ( value , name = None , strict = False , allow_downcast = None , <EOL> borrow = False , broadcastable = None , target = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if target != '<STR_LIT>' : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if not isinstance ( value , numpy . ndarray ) : <EOL> raise TypeError ( ) <EOL> if broadcastable is None : <EOL> broadcastable = ( False , ) * len ( value . shape ) <EOL> type = TensorType ( value . dtype , broadcastable = broadcastable ) <EOL> return TensorSharedVariable ( type = type , <EOL> value = numpy . array ( value , copy = ( not borrow ) ) , <EOL> name = name , <EOL> strict = strict , <EOL> allow_downcast = allow_downcast ) <EOL> class ScalarSharedVariable ( _tensor_py_operators , SharedVariable ) : <EOL> pass <EOL> @ shared_constructor <EOL> def scalar_constructor ( value , name = None , strict = False , allow_downcast = None , <EOL> borrow = False , target = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if target != '<STR_LIT>' : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if not isinstance ( value , ( numpy . number , float , integer_types , complex ) ) : <EOL> raise TypeError ( ) <EOL> try : <EOL> dtype = value . dtype <EOL> except Exception : <EOL> dtype = numpy . asarray ( value ) . dtype <EOL> dtype = str ( dtype ) <EOL> value = theano . _asarray ( value , dtype = dtype ) <EOL> tensor_type = TensorType ( dtype = str ( value . dtype ) , broadcastable = [ ] ) <EOL> try : <EOL> rval = ScalarSharedVariable ( type = tensor_type , <EOL> value = numpy . array ( value , copy = True ) , <EOL> name = name , <EOL> strict = strict , <EOL> allow_downcast = allow_downcast ) <EOL> return rval <EOL> except Exception : <EOL> traceback . print_exc ( ) <EOL> raise </s>
