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

Support for nested functions #46

Closed
alecglen opened this issue Oct 7, 2022 · 5 comments · Fixed by #47
Closed

Support for nested functions #46

alecglen opened this issue Oct 7, 2022 · 5 comments · Fixed by #47
Milestone

Comments

@alecglen
Copy link

alecglen commented Oct 7, 2022

As an example use case, I have a function that takes in a dataset and returns a closure based on that dataset.

def gen_normalizer(df):

    def normalize_row_based_on_dataset(row):
        return (row - df.mean()) / df.std()
    
    return normalize_row_based_on_dataset

I would love to be able to apply the decorator to the nested function so that later in my experiment I can display a set of different Normalizers in LaTeX. However, currently adding the decorator to the nested function results in the following error:

File <unknown>:1
    @latexify.with_latex
    ^
IndentationError: unexpected indent
@odashi
Copy link
Collaborator

odashi commented Oct 7, 2022

Thanks for reporting the issue!

The cause of this is that all lines of the inner function have extra indentation. I think dedent-ing the obtained source before parsing may solve the problem.

@odashi odashi added this to the v0.2 milestone Oct 9, 2022
@odashi odashi closed this as completed in #47 Oct 9, 2022
@alecglen
Copy link
Author

Thank you for the quick turnaround! When do you expect to release v0.2?

@odashi
Copy link
Collaborator

odashi commented Oct 11, 2022

Yes, if you want to try it out soon, please install the trunk directly or apply the same changes.

@alecglen
Copy link
Author

Fair, thanks again!

As a followup, part of my goal in the example above was for the latex equation to display the literal values for df.mean() and df.std(). In hindsight, I see now why that doesn't work naturally and that it might not even be possible.

Figured it doesn't hurt to ask anyway, though... Is there any way to coerce latexify into computing certain values so their literal value shows in the final expression? E.g. getting 5 and 2 in this simplified example:

image

@odashi
Copy link
Collaborator

odashi commented Oct 14, 2022

@alecglen I will create another issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants