MilesCranmer commited on
Commit
32f7c64
1 Parent(s): c1c031f

Improve readability for user-defined operator code

Browse files
Files changed (1) hide show
  1. pysr/sr.py +10 -10
pysr/sr.py CHANGED
@@ -236,16 +236,16 @@ def pysr(X=None, y=None, weights=None,
236
  for op_list in [binary_operators, unary_operators]:
237
  for i in range(len(op_list)):
238
  op = op_list[i]
239
- if '(' not in op:
240
- continue
241
-
242
- def_hyperparams += op + "\n"
243
- # Cut off from the first non-alphanumeric char:
244
- first_non_char = [
245
- j for j in range(len(op))
246
- if not (op[j].isalpha() or op[j].isdigit())][0]
247
- function_name = op[:first_non_char]
248
- op_list[i] = function_name
249
 
250
  def_hyperparams += f"""include("{pkg_directory}/operators.jl")
251
  const binops = {'[' + ', '.join(binary_operators) + ']'}
 
236
  for op_list in [binary_operators, unary_operators]:
237
  for i in range(len(op_list)):
238
  op = op_list[i]
239
+ is_user_defined_operator = '(' in op
240
+
241
+ if is_user_defined_operator:
242
+ def_hyperparams += op + "\n"
243
+ # Cut off from the first non-alphanumeric char:
244
+ first_non_char = [
245
+ j for j in range(len(op))
246
+ if not (op[j].isalpha() or op[j].isdigit())][0]
247
+ function_name = op[:first_non_char]
248
+ op_list[i] = function_name
249
 
250
  def_hyperparams += f"""include("{pkg_directory}/operators.jl")
251
  const binops = {'[' + ', '.join(binary_operators) + ']'}