def _single_learnable_state(state, state_id=0, learnable=True):
 unpacked_state = tf.unpack(state)
 assert_rows_equal = [tf.assert_equal(s, unpacked_state[0]) for s in unpacked_state]
 with tf.control_dependencies(assert_rows_equal):
  if (not learnable):
   return state
  else:
   state_shape = state.get_shape()
   state_shape.assert_is_fully_defined()
   state_shape_list = state_shape.as_list()
   (batch_size, trailing_shape) = (state_shape_list[0], state_shape_list[1:])
   initial_value = tf.reshape(unpacked_state[0], ([1] + trailing_shape))
   initial_state_variable = tf.get_variable(('initial_state_%d' % state_id), dtype=initial_value.dtype, initializer=initial_value)
   trailing_size_repeat = ([1] * len(trailing_shape))
   return tf.tile(initial_state_variable, tf.constant(([batch_size] + trailing_size_repeat)))

def _single_learnable_state ( state , state_id = 0 , learnable = True ) : unpacked_state = tf . unpack ( state ) assert_rows_equal = [ tf . assert_equal ( s , unpacked_state [ 0 ] ) for s in unpacked_state ] with tf . control_dependencies ( assert_rows_equal ) : if ( not learnable ) : return state else : state_shape = state . get_shape ( ) state_shape . assert_is_fully_defined ( ) state_shape_list = state_shape . as_list ( ) ( batch_size , trailing_shape ) = ( state_shape_list [ 0 ] , state_shape_list [ 1 : ] ) initial_value = tf . reshape ( unpacked_state [ 0 ] , ( [ 1 ] + trailing_shape ) ) initial_state_variable = tf . get_variable ( ( 'initial_state_%d' % state_id ) , dtype = initial_value . dtype , initializer = initial_value ) trailing_size_repeat = ( [ 1 ] * len ( trailing_shape ) ) return tf . tile ( initial_state_variable , tf . constant ( ( [ batch_size ] + trailing_size_repeat ) ) )
returns an initial state .