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 SciPy integrate package #142

Open
J-Douglas opened this issue Dec 2, 2022 · 11 comments
Open

Support for SciPy integrate package #142

J-Douglas opened this issue Dec 2, 2022 · 11 comments
Assignees
Labels

Comments

@J-Douglas
Copy link
Contributor

Description

Adding support for the SciPy's integrate package would be useful. The quad, dblquad, and tplquad methods are used for single, double, and triple integrals respectively and they seem like a good starting point. You can read more about the methods here: https://docs.scipy.org/doc/scipy/tutorial/integrate.html. Not sure if there will need to be restrictions on these methods, but I appreciate any tips/suggestions for going about this.

Additional Flake8 Formatting Issue

I also ran the check.sh script before working on this feature and I noticed that the Flake8 formatting check was failing for long lines. Someone may have already fixed this but if they haven't, I can include the formatting corrections in with the SciPy work.

@odashi
Copy link
Collaborator

odashi commented Dec 2, 2022

I guessed we can support the most simplest case, i.e., self-contained formulas:

scipy.integrate.quad(lambda x: f(x), a, b)

into:

$$\int_{a}^{b} f(x) dx$$

If the first argument is a reference to another callable, we need additional treatment. E.g.,

def f(x):
    return g(x)
def myint():
    return quad(f, a, b)

It would be good if we get $\mathrm{myint}() = \int_{a}^{b} g(x) dx$, but I also guess we also need some general solution to integrate multiple functions. This feature could be discussed separately.

@odashi
Copy link
Collaborator

odashi commented Dec 2, 2022

As for flake8 failures, is it happening in the current main?

@J-Douglas
Copy link
Contributor Author

Yes, the failures are happening on the current main and I've pulled to verify that it is up to date. I'm getting E501 errors for lines being longer than 79 characters. Do you want to increase the maximum line length or just wrap the lines so they meet this requirement?

@odashi
Copy link
Collaborator

odashi commented Dec 2, 2022

Currently the length limit is set to 88:

max-line-length = 88

I think your runtime doesn't read pyproject.toml for some reason. Please check it.

@J-Douglas
Copy link
Contributor Author

You're right, thanks for clarifying! I'll investigate why pyproject.toml isn't being read

@ZibingZhang
Copy link
Contributor

I also get the issue where ./checks.sh updates some files, and I have to run python3 black src to fix it. I think something later in the script undos the work black does.

@odashi
Copy link
Collaborator

odashi commented Dec 3, 2022

black and isort updates the file unless the --check option, and this behavior is disabled in the current main. If you still get some errors, please make another issue for it. I'd like to focus on the SciPy feature in this issue.

@ZibingZhang
Copy link
Contributor

Probably would add under Special treatments for some functions, but would want to match integrate.quad, not just the function name? Matching quad seems too ambiguous.

It's also getting to the point where we have lots of "special treatments", so maybe it's time to make this into a config value? But I think it's important here to choose carefully the default values for this config value. It's important that for very commonly used functions, that the behavior is default to handle specially, but for functions like zeros maybe this should have to be user specified.

@odashi
Copy link
Collaborator

odashi commented Dec 11, 2022

Matching quad seems too ambiguous.

Yes I agreed that. I think this kind of feature should be provided as a plugin to avoid the confusion of the default behavior. One possible interface may be:

import latexify
from latexify.plugins.scipy import integrate

@latexify.function(plugins=[integrate])
def f(x):
    ...

Here latexify.plugins.scipy.integrate defines several expression rules that are applied additionally, e.g., quad to $\int$.

This design may be useful for any other kind of extensions IMO (and also provides a way to implement third-party extensions).

@ZibingZhang
Copy link
Contributor

This is a great idea. Since there's probably multiple packages that define integration methods, this would solve trying to figure out which format it's in.

Since we want this to support third-party extensions, it would mean that throughout the generation process, we need to check the integrations and let them hook into the process, right? Each integration would be fully self contained, and would need no additional code in the generation process to make them work.

@odashi
Copy link
Collaborator

odashi commented Dec 11, 2022

Let's go to the issue I created.

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

No branches or pull requests

3 participants