The Wayback Machine - https://web.archive.org/web/20201102135425/https://github.com/BayesWitnesses/m2cgen/issues/110
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to save generated code into file #110

Open
StrikerRUS opened this issue Oct 18, 2019 · 8 comments
Open

add option to save generated code into file #110

StrikerRUS opened this issue Oct 18, 2019 · 8 comments

Comments

@StrikerRUS
Copy link
Member

@StrikerRUS StrikerRUS commented Oct 18, 2019

I'm sorry if I missed this functionality, but CLI version hasn't it for sure (I saw the related code only in generate_code_examples.py). I guess it will be very useful to eliminate copy-paste phase, especially for large models.

Of course, piping is a solution, but not for development in Jupyter Notebook, for example.

@izeigerman
Copy link
Member

@izeigerman izeigerman commented Oct 18, 2019

Hey @StrikerRUS, thanks for reporting this. Can m2cgen be used as a library in a Jupyter Notebook scenario?

@StrikerRUS
Copy link
Member Author

@StrikerRUS StrikerRUS commented Oct 18, 2019

@izeigerman Why not?.. I just used it so for preparing #109.

@izeigerman
Copy link
Member

@izeigerman izeigerman commented Oct 21, 2019

Yeah, I'm just trying to understand whether piping is sufficient after all or not.

@eafpres
Copy link

@eafpres eafpres commented Jan 17, 2020

Just a comment; I started working on this today and the docs could be upgraded to clarify that CLI use can use piping to save to a file. I "might" try to tackle this as I would like to get my feet wet on contributing to OSS.

@izeigerman
Copy link
Member

@izeigerman izeigerman commented Jan 17, 2020

@eafpres Do you mean docs of the CLI tool itself or the README? We do mention this in the latter: https://github.com/BayesWitnesses/m2cgen#cli . In any case please feel free to submit a PR. Contributions are welcome!

@eafpres
Copy link

@eafpres eafpres commented Jan 17, 2020

@izeigerman Initially I was going to propose a change to the readme. Piping works fine on the CLI so I don't see an urgent need to explicitly add the functionality to that tool. Long-term maybe.

@wbadry
Copy link

@wbadry wbadry commented Jul 18, 2020

Hello,
Is there any example showing how to save the model to a specific path?. This would be very helpful as I try several models to run in the background and would appreciate if models can be saved in a folder after each iteration.

bitmoji

@izeigerman
Copy link
Member

@izeigerman izeigerman commented Jul 20, 2020

Hey @wbadry!

If you're using m2cgen in CLI you can just redirect its stdout into the file. Eg:

$ m2cgen <path_to_model> --language c > <path_to_output_file>

Alternatively if you're using the Python API:

import m2cgen as m2c

generated_code = m2c.export_to_c(...)
with open('<path_to_output_file', 'w') as fd:
    fd.write(generated_code)

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.