Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-harmonics
Commits
742499ae
Commit
742499ae
authored
Jun 30, 2025
by
apaaris
Committed by
Boris Bonev
Jul 21, 2025
Browse files
Improved docstrings in quadrature
parent
c4995635
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
1 deletion
+115
-1
torch_harmonics/quadrature.py
torch_harmonics/quadrature.py
+115
-1
No files found.
torch_harmonics/quadrature.py
View file @
742499ae
...
@@ -85,6 +85,16 @@ def _precompute_grid(n: int, grid: Optional[str]="equidistant", a: Optional[floa
...
@@ -85,6 +85,16 @@ def _precompute_grid(n: int, grid: Optional[str]="equidistant", a: Optional[floa
def
_precompute_longitudes
(
nlon
:
int
):
def
_precompute_longitudes
(
nlon
:
int
):
r
"""
r
"""
Convenience routine to precompute longitudes
Convenience routine to precompute longitudes
Parameters
-----------
nlon: int
Number of longitude points
Returns
-------
lons: torch.Tensor
Tensor of longitude points
"""
"""
lons
=
torch
.
linspace
(
0
,
2
*
math
.
pi
,
nlon
+
1
,
dtype
=
torch
.
float64
,
requires_grad
=
False
)[:
-
1
]
lons
=
torch
.
linspace
(
0
,
2
*
math
.
pi
,
nlon
+
1
,
dtype
=
torch
.
float64
,
requires_grad
=
False
)[:
-
1
]
...
@@ -95,6 +105,20 @@ def _precompute_longitudes(nlon: int):
...
@@ -95,6 +105,20 @@ def _precompute_longitudes(nlon: int):
def
_precompute_latitudes
(
nlat
:
int
,
grid
:
Optional
[
str
]
=
"equiangular"
)
->
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
def
_precompute_latitudes
(
nlat
:
int
,
grid
:
Optional
[
str
]
=
"equiangular"
)
->
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
r
"""
r
"""
Convenience routine to precompute latitudes
Convenience routine to precompute latitudes
Parameters
-----------
nlat: int
Number of latitude points
grid: Optional[str]
Grid type ("equiangular", "legendre-gauss", "lobatto", "equidistant"), by default "equiangular"
Returns
-------
lats: torch.Tensor
Tensor of latitude points
wlg: torch.Tensor
Tensor of quadrature weights
"""
"""
# compute coordinates in the cosine theta domain
# compute coordinates in the cosine theta domain
...
@@ -112,6 +136,24 @@ def trapezoidal_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]=1.0,
...
@@ -112,6 +136,24 @@ def trapezoidal_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]=1.0,
r
"""
r
"""
Helper routine which returns equidistant nodes with trapezoidal weights
Helper routine which returns equidistant nodes with trapezoidal weights
on the interval [a, b]
on the interval [a, b]
Parameters
-----------
n: int
Number of quadrature nodes
a: Optional[float]
Lower bound of the interval
b: Optional[float]
Upper bound of the interval
periodic: Optional[bool]
Whether the grid is periodic
Returns
-------
xlg: torch.Tensor
Tensor of quadrature nodes
wlg: torch.Tensor
Tensor of quadrature weights
"""
"""
xlg
=
torch
.
as_tensor
(
np
.
linspace
(
a
,
b
,
n
,
endpoint
=
periodic
))
xlg
=
torch
.
as_tensor
(
np
.
linspace
(
a
,
b
,
n
,
endpoint
=
periodic
))
...
@@ -128,6 +170,22 @@ def legendre_gauss_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]=1
...
@@ -128,6 +170,22 @@ def legendre_gauss_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]=1
r
"""
r
"""
Helper routine which returns the Legendre-Gauss nodes and weights
Helper routine which returns the Legendre-Gauss nodes and weights
on the interval [a, b]
on the interval [a, b]
Parameters
-----------
n: int
Number of quadrature nodes
a: Optional[float]
Lower bound of the interval
b: Optional[float]
Upper bound of the interval
Returns
-------
xlg: torch.Tensor
Tensor of quadrature nodes
wlg: torch.Tensor
Tensor of quadrature weights
"""
"""
xlg
,
wlg
=
np
.
polynomial
.
legendre
.
leggauss
(
n
)
xlg
,
wlg
=
np
.
polynomial
.
legendre
.
leggauss
(
n
)
...
@@ -144,6 +202,27 @@ def lobatto_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]=1.0,
...
@@ -144,6 +202,27 @@ def lobatto_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]=1.0,
r
"""
r
"""
Helper routine which returns the Legendre-Gauss-Lobatto nodes and weights
Helper routine which returns the Legendre-Gauss-Lobatto nodes and weights
on the interval [a, b]
on the interval [a, b]
Parameters
-----------
n: int
Number of quadrature nodes
a: Optional[float]
Lower bound of the interval
b: Optional[float]
Upper bound of the interval
tol: Optional[float]
Tolerance for the iteration
maxiter: Optional[int]
Maximum number of iterations
Returns
-------
tlg: torch.Tensor
Tensor of quadrature nodes
wlg: torch.Tensor
Tensor of quadrature weights
"""
"""
wlg
=
torch
.
zeros
((
n
,),
dtype
=
torch
.
float64
,
requires_grad
=
False
)
wlg
=
torch
.
zeros
((
n
,),
dtype
=
torch
.
float64
,
requires_grad
=
False
)
...
@@ -187,6 +266,24 @@ def clenshaw_curtiss_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]
...
@@ -187,6 +266,24 @@ def clenshaw_curtiss_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]
Computation of the Clenshaw-Curtis quadrature nodes and weights.
Computation of the Clenshaw-Curtis quadrature nodes and weights.
This implementation follows
This implementation follows
Parameters
-----------
n: int
Number of quadrature nodes
a: Optional[float]
Lower bound of the interval
b: Optional[float]
Upper bound of the interval
Returns
-------
tcc: torch.Tensor
Tensor of quadrature nodes
wcc: torch.Tensor
Tensor of quadrature weights
References
----------
[1] Joerg Waldvogel, Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules; BIT Numerical Mathematics, Vol. 43, No. 1, pp. 001–018.
[1] Joerg Waldvogel, Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules; BIT Numerical Mathematics, Vol. 43, No. 1, pp. 001–018.
"""
"""
...
@@ -224,8 +321,25 @@ def clenshaw_curtiss_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]
...
@@ -224,8 +321,25 @@ def clenshaw_curtiss_weights(n: int, a: Optional[float]=-1.0, b: Optional[float]
def
fejer2_weights
(
n
:
int
,
a
:
Optional
[
float
]
=-
1.0
,
b
:
Optional
[
float
]
=
1.0
)
->
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
def
fejer2_weights
(
n
:
int
,
a
:
Optional
[
float
]
=-
1.0
,
b
:
Optional
[
float
]
=
1.0
)
->
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
r
"""
r
"""
Computation of the Fejer quadrature nodes and weights.
Computation of the Fejer quadrature nodes and weights.
This implementation follows
Parameters
-----------
n: int
Number of quadrature nodes
a: Optional[float]
Lower bound of the interval
b: Optional[float]
Upper bound of the interval
Returns
-------
tcc: torch.Tensor
Tensor of quadrature nodes
wcc: torch.Tensor
Tensor of quadrature weights
References
----------
[1] Joerg Waldvogel, Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules; BIT Numerical Mathematics, Vol. 43, No. 1, pp. 001–018.
[1] Joerg Waldvogel, Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules; BIT Numerical Mathematics, Vol. 43, No. 1, pp. 001–018.
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment