Skip to content

Chebyshev polynomial of the second kind #78293

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

Closed
wants to merge 11 commits into from

Conversation

0x00b1
Copy link
Contributor

@0x00b1 0x00b1 commented May 25, 2022

Adds:

chebyshev_polynomial_u(input, n, *, out=None) -> Tensor

Chebyshev polynomial of the second kind $U_{n}(\text{input})$.

If $n = 0$, $1$ is returned. If $n = 1$, $2 \times \text{input}$ is returned. If $n < 6$ or $|\text{input}| > 1$ the recursion:

$$T_{n + 1}(\text{input}) = 2 \times \text{input} \times T_{n}(\text{input}) - T_{n - 1}(\text{input})$$

is evaluated. Otherwise, the explicit trigonometric formula:

$$\frac{\text{sin}((n + 1) \times \text{arccos}(\text{input}))}{\text{sin}(\text{arccos}(\text{input}))}$$

is evaluated.

Derivatives

Recommended first derivative formula with respect to $\text{input}$:

$$\frac{(-1 - n)\times U_{-1 + n}(\text{input}) + n \times \text{input} \times U_{n}(x)}{-1 + \text{input}^{2}}.$$

Recommended $k$-derivative formula with respect to $\text{n}$:

$$\frac{\text{arccos}(\text{input})^{k} \times \text{sin}(\frac{k \times \pi}{2} + (1 + n) \times \text{arccos}(\text{input}))}{\sqrt{1 - \text{input}^{2}}}.$$

Example

x = torch.linspace(-1.0, 1.0, 256)

matplotlib.pyplot.plot(x, torch.special.chebyshev_polynomial_u(x, 10))

image

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented May 25, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

As of commit d04bd3c (more details on the Dr. CI page):

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@0x00b1 0x00b1 marked this pull request as ready for review May 25, 2022 19:44
Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See a few inline nits, but looks good once tests are fixed!

@suo
Copy link
Member

suo commented May 25, 2022

heads up: prefer not to add ciflow/all, as it runs things that we are generally quite capacity constrained on. If you want to get signal on things that will be the cause of reverts, ciflow/trunk is sufficient

@0x00b1
Copy link
Contributor Author

0x00b1 commented May 25, 2022

Thanks @suo! I apologize for wasting resources. I will use trunk in the future.

@0x00b1 0x00b1 added ciflow/trunk Trigger trunk jobs on your pull request and removed ciflow/all labels May 25, 2022
@0x00b1
Copy link
Contributor Author

0x00b1 commented May 26, 2022

@suo Should I be concerned about these failures? They don't appear to be relevant to this pull request.

@0x00b1 0x00b1 force-pushed the chebyshev-polynomial-u branch from 7f1c459 to c6693e9 Compare May 26, 2022 21:39
@0x00b1 0x00b1 force-pushed the chebyshev-polynomial-u branch from fcf3fe8 to d04bd3c Compare May 27, 2022 14:18
@0x00b1
Copy link
Contributor Author

0x00b1 commented May 27, 2022

@pytorchbot merge this please!

@github-actions
Copy link
Contributor

Hey @0x00b1.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit that referenced this pull request May 31, 2022
Summary:
Adds:

```Python
chebyshev_polynomial_u(input, n, *, out=None) -> Tensor
```

Chebyshev polynomial of the second kind $U_{n}(\text{input})$.

If $n = 0$, $1$ is returned. If $n = 1$, $2 \times \text{input}$ is returned. If $n < 6$ or $|\text{input}| > 1$ the recursion:

$$T_{n + 1}(\text{input}) = 2 \times \text{input} \times T_{n}(\text{input}) - T_{n - 1}(\text{input})$$

is evaluated. Otherwise, the explicit trigonometric formula:

$$\frac{\text{sin}((n + 1) \times \text{arccos}(\text{input}))}{\text{sin}(\text{arccos}(\text{input}))}$$

is evaluated.

## Derivatives

Recommended first derivative formula with respect to $\text{input}$:

$$\frac{(-1 - n)\times U_{-1 + n}(\text{input}) + n \times \text{input} \times U_{n}(x)}{-1 + \text{input}^{2}}.$$

Recommended $k$-derivative formula with respect to $\text{n}$:

$$\frac{\text{arccos}(\text{input})^{k} \times \text{sin}(\frac{k \times \pi}{2} + (1 + n) \times \text{arccos}(\text{input}))}{\sqrt{1 - \text{input}^{2}}}.$$

## Example

```Python
x = torch.linspace(-1.0, 1.0, 256)

matplotlib.pyplot.plot(x, torch.special.chebyshev_polynomial_u(x, 10))
```

![image](https://user-images.githubusercontent.com/315821/170352780-12af63d3-ce31-4948-8b68-8ecc37c71ac5.png)

Pull Request resolved: #78293
Approved by: https://github.com/mruberry

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/40a6cc6cc640e6914b8160aea1399e4bb530213a

Reviewed By: seemethere

Differential Revision: D36783570

Pulled By: 0x00b1

fbshipit-source-id: d00ee06dadc0039166cc183768725833bbfb71e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants