MilesCranmer commited on
Commit
5f27a84
1 Parent(s): 73fb236

Clean up data passing to Julia

Browse files
Files changed (2) hide show
  1. pysr/sr.py +13 -9
  2. setup.py +1 -1
pysr/sr.py CHANGED
@@ -260,6 +260,9 @@ def pysr(X=None, y=None, weights=None,
260
  hyperparam_filename = tmpdir / f'hyperparams.jl'
261
  dataset_filename = tmpdir / f'dataset.jl'
262
  runfile_filename = tmpdir / f'runfile.jl'
 
 
 
263
 
264
  def_hyperparams = ""
265
 
@@ -392,19 +395,20 @@ end"""
392
 
393
  def_hyperparams += op_runner
394
 
395
- if X.shape[1] == 1:
396
- X_str = 'transpose([' + str(X.tolist()).replace(']', '').replace(',', '').replace('[', '') + '])'
397
- else:
398
- X_str = str(X.tolist()).replace('],', '];').replace(',', '')
399
- y_str = str(y.tolist())
 
400
 
401
- def_datasets = """const X = convert(Array{Float32, 2}, """f"{X_str})""""
402
- const y = convert(Array{Float32, 1}, """f"{y_str})"
 
403
 
404
  if weights is not None:
405
- weight_str = str(weights.tolist())
406
  def_datasets += """
407
- const weights = convert(Array{Float32, 1}, """f"{weight_str})"
408
 
409
  if use_custom_variable_names:
410
  def_hyperparams += f"""
 
260
  hyperparam_filename = tmpdir / f'hyperparams.jl'
261
  dataset_filename = tmpdir / f'dataset.jl'
262
  runfile_filename = tmpdir / f'runfile.jl'
263
+ X_filename = tmpdir / "X.csv"
264
+ y_filename = tmpdir / "y.csv"
265
+ weights_filename = tmpdir / "weights.csv"
266
 
267
  def_hyperparams = ""
268
 
 
395
 
396
  def_hyperparams += op_runner
397
 
398
+ def_datasets = """using DelimitedFiles"""
399
+
400
+ np.savetxt(X_filename, X, delimiter=',')
401
+ np.savetxt(y_filename, y, delimiter=',')
402
+ if weights is not None:
403
+ np.savetxt(weights_filename, weights, delimiter=',')
404
 
405
+ def_datasets += f"""
406
+ const X = readdlm("{_escape_filename(X_filename)}", ',', Float32, '\\n')
407
+ const y = readdlm("{_escape_filename(y_filename)}", ',', Float32, '\\n')"""
408
 
409
  if weights is not None:
 
410
  def_datasets += """
411
+ const weights = readdlm("{_escape_filename(weights_filename)}", ',', Float32, '\\n')"""
412
 
413
  if use_custom_variable_names:
414
  def_hyperparams += f"""
setup.py CHANGED
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
 
6
  setuptools.setup(
7
  name="pysr", # Replace with your own username
8
- version="0.3.34",
9
  author="Miles Cranmer",
10
  author_email="miles.cranmer@gmail.com",
11
  description="Simple and efficient symbolic regression",
 
5
 
6
  setuptools.setup(
7
  name="pysr", # Replace with your own username
8
+ version="0.3.35",
9
  author="Miles Cranmer",
10
  author_email="miles.cranmer@gmail.com",
11
  description="Simple and efficient symbolic regression",