https://github.com/cheind/torch-spherical-harmonics

Real Spherical Harmonics for PyTorch

https://github.com/cheind/torch-spherical-harmonics

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary

Keywords

pytorch spherical-harmonics symbolic
Last synced: 9 months ago · JSON representation

Repository

Real Spherical Harmonics for PyTorch

Basic Info
  • Host: GitHub
  • Owner: cheind
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 2.82 MB
Statistics
  • Stars: 22
  • Watchers: 2
  • Forks: 2
  • Open Issues: 1
  • Releases: 0
Topics
pytorch spherical-harmonics symbolic
Created over 3 years ago · Last pushed over 3 years ago
Metadata Files
Readme License

README.md

torch-spherical-harmonics

Real spherical harmonics (RSH) in Cartesian form for PyTorch. The resulting source code is auto-generated by converting optimized symbolic RSH expressions to PyTorch.

The following plot shows the first real spherical harmonics $Y_{nm}$ of degree $n < 6$ and order $-n \le m \le n$ as a function of polar coordinates $\theta \in [0,\pi]$ and $\phi \in [0,2\pi]$.

Properties

The RSH functions provided in this package are ortho-normalized over the surface of the unit sphere. That is

$$ \int\limits0^\pi\int\limits0^{2\pi}Y{nm}(\mathbf r(\theta,\phi))Y{n'm'}(\mathbf r(\theta,\phi)) \left\lVert \frac{\partial\mathbf{r}}{\partial\theta}\times\frac{\partial\mathbf{r}}{\partial\phi} \right\rVert \thinspace d \phi \thinspace d \theta = \delta{nn'}\delta{mm'}, $$

with

$$ \mathbf r(\theta,\phi) = \sin\theta\cos\phi\mathbf{\hat i} + \sin\theta\sin\phi\mathbf{\hat j} + \cos\theta\mathbf{\hat k}, $$

and

$$ \left\lVert \frac{\partial\mathbf{r}}{\partial\theta} \times \frac{\partial\mathbf{r}}{\partial\phi} \right\lVert = \sin\theta. $$

Note that due to some rendering issue, you might not see the double vertical bars around the cross product.

Usage

To compute all $Y_{nm}$ values up to degree 3 use:

```python

import torch from torchsh import rshcart3

xyz = ... # tensor (N,...,3) of unit-sphere points ynm = rshcart3(xyz) # tensor (N,...,16) of Ynm values # with Ynm at index n*(n+1) + m ```

This relies on pre-generated RSH functions, which torchsh contains up to degree 8. They all follow the same naming convention rsh_cart_{degree}.

If you do not want to add a new library dependency, you may just as well just include torchsh/rsh.py in your project, which requires only torch to be installed.

Code Generation

We use sympy to generate RSH expressions in Cartesian form reyling on the Herglotzian definition. These expressions are simplified and transformed into Python/PyTorch functions using a code template and the string engine mako. In the tests we use sympy.Znm to verify our numerical results.

We initially intended to use sympy.Znm directly for code generation, by substituting polar coordinate definitions with respective Cartesian ones, but found that substitution did not work all of the times. This is the reason we switched to a different generating definition.

Code can be generated via

$ python -m torchsh.symbolic.codegen --help

which requires all dev-requirements.txt to be installed. To run the unit tests call

$ pytest

References

The basic idea for using sympy to generate code for RSH functions is taken from https://nvlabs.github.io/instant-ngp, where it is used to generate Cuda code for forward and backward passes.

Owner

  • Name: Christoph Heindl
  • Login: cheind
  • Kind: user
  • Location: Austrian area

I am a computer scientist working at the interface of perception, robotics and deep learning.

GitHub Events

Total
  • Watch event: 3
Last Year
  • Watch event: 3

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 58
  • Total Committers: 2
  • Avg Commits per committer: 29.0
  • Development Distribution Score (DDS): 0.362
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Christoph Heindl c****d@p****t 37
Christoph Heindl c****l@g****m 21
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • theAdityaRamesh (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

dev-requirements.in pypi
  • black * development
  • flake8 * development
  • mako * development
  • matplotlib * development
  • numpy * development
  • pytest * development
  • sympy * development
dev-requirements.txt pypi
  • attrs ==22.1.0 development
  • black ==22.10.0 development
  • click ==8.1.3 development
  • colorama ==0.4.6 development
  • contourpy ==1.0.6 development
  • cycler ==0.11.0 development
  • exceptiongroup ==1.0.0 development
  • flake8 ==5.0.4 development
  • fonttools ==4.38.0 development
  • iniconfig ==1.1.1 development
  • kiwisolver ==1.4.4 development
  • mako ==1.2.3 development
  • markupsafe ==2.1.1 development
  • matplotlib ==3.6.2 development
  • mccabe ==0.7.0 development
  • mpmath ==1.2.1 development
  • mypy-extensions ==0.4.3 development
  • numpy ==1.23.4 development
  • packaging ==21.3 development
  • pathspec ==0.10.1 development
  • pillow ==9.3.0 development
  • platformdirs ==2.5.2 development
  • pluggy ==1.0.0 development
  • pycodestyle ==2.9.1 development
  • pyflakes ==2.5.0 development
  • pyparsing ==3.0.9 development
  • pytest ==7.2.0 development
  • python-dateutil ==2.8.2 development
  • six ==1.16.0 development
  • sympy ==1.11.1 development
  • tomli ==2.0.1 development
  • torch ==1.12.1 development
  • typing-extensions ==4.4.0 development
requirements.in pypi
  • torch ==1.12.1
requirements.txt pypi
  • torch ==1.12.1
  • typing-extensions ==4.4.0