def constant_grad(expr):
 grad = {}
 for var in expr.variables():
  rows = (var.size[0] * var.size[1])
  cols = (expr.size[0] * expr.size[1])
  if ((rows, cols) == (1, 1)):
   grad[var] = 0.0
  else:
   grad[var] = sp.csc_matrix((rows, cols), dtype='float64')
 return grad

def constant_grad ( expr ) : grad = { } for var in expr . variables ( ) : rows = ( var . size [ 0 ] * var . size [ 1 ] ) cols = ( expr . size [ 0 ] * expr . size [ 1 ] ) if ( ( rows , cols ) == ( 1 , 1 ) ) : grad [ var ] = 0.0 else : grad [ var ] = sp . csc_matrix ( ( rows , cols ) , dtype = 'float64' ) return grad
returns the gradient of constant terms in an expression .