def as_sparse_variable(x, name=None):
 if isinstance(x, gof.Apply):
  if (len(x.outputs) != 1):
   raise ValueError('It is ambiguous which output of a multi-output Op has to be fetched.', x)
  else:
   x = x.outputs[0]
 if isinstance(x, gof.Variable):
  if (not isinstance(x.type, SparseType)):
   raise TypeError('Variable type field must be a SparseType.', x, x.type)
  return x
 try:
  return constant(x, name=name)
 except TypeError:
  raise TypeError(('Cannot convert %s to SparseType' % x), type(x))

def as_sparse_variable ( x , name = None ) : if isinstance ( x , gof . Apply ) : if ( len ( x . outputs ) != 1 ) : raise ValueError ( 'It is ambiguous which output of a multi-output Op has to be fetched.' , x ) else : x = x . outputs [ 0 ] if isinstance ( x , gof . Variable ) : if ( not isinstance ( x . type , SparseType ) ) : raise TypeError ( 'Variable type field must be a SparseType.' , x , x . type ) return x try : return constant ( x , name = name ) except TypeError : raise TypeError ( ( 'Cannot convert %s to SparseType' % x ) , type ( x ) )
wrapper around sparsevariable constructor to construct a variable with a sparse matrix with the same dtype and format .