def _check_density(density, n_features):
 if (density == 'auto'):
  density = (1 / np.sqrt(n_features))
 elif ((density <= 0) or (density > 1)):
  raise ValueError(('Expected density in range ]0, 1], got: %r' % density))
 return density

def _check_density ( density , n_features ) : if ( density == 'auto' ) : density = ( 1 / np . sqrt ( n_features ) ) elif ( ( density <= 0 ) or ( density > 1 ) ) : raise ValueError ( ( 'Expected density in range ]0, 1], got: %r' % density ) ) return density
factorize density check according to li et al .