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
a0d1fbca
Unverified
Commit
a0d1fbca
authored
Aug 02, 2023
by
Thorsten Kurth
Committed by
GitHub
Aug 02, 2023
Browse files
Merge pull request #6 from azrael417/tkurth/precision-fix
Fixing precision mismatch error in weight contractions
parents
855297ae
562dac19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
21 deletions
+21
-21
torch_harmonics/__init__.py
torch_harmonics/__init__.py
+1
-1
torch_harmonics/sht.py
torch_harmonics/sht.py
+20
-20
No files found.
torch_harmonics/__init__.py
View file @
a0d1fbca
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
__version__
=
'0.6.
1
'
__version__
=
'0.6.
2
'
from
.sht
import
RealSHT
,
InverseRealSHT
,
RealVectorSHT
,
InverseRealVectorSHT
from
.sht
import
RealSHT
,
InverseRealSHT
,
RealVectorSHT
,
InverseRealVectorSHT
from
.
import
quadrature
from
.
import
quadrature
...
...
torch_harmonics/sht.py
View file @
a0d1fbca
...
@@ -120,8 +120,8 @@ class RealSHT(nn.Module):
...
@@ -120,8 +120,8 @@ class RealSHT(nn.Module):
xout
=
torch
.
zeros
(
out_shape
,
dtype
=
x
.
dtype
,
device
=
x
.
device
)
xout
=
torch
.
zeros
(
out_shape
,
dtype
=
x
.
dtype
,
device
=
x
.
device
)
# contraction
# contraction
xout
[...,
0
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
:
self
.
mmax
,
0
],
self
.
weights
)
xout
[...,
0
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
:
self
.
mmax
,
0
],
self
.
weights
.
to
(
x
.
dtype
)
)
xout
[...,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
:
self
.
mmax
,
1
],
self
.
weights
)
xout
[...,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
:
self
.
mmax
,
1
],
self
.
weights
.
to
(
x
.
dtype
)
)
x
=
torch
.
view_as_complex
(
xout
)
x
=
torch
.
view_as_complex
(
xout
)
return
x
return
x
...
@@ -185,8 +185,8 @@ class InverseRealSHT(nn.Module):
...
@@ -185,8 +185,8 @@ class InverseRealSHT(nn.Module):
# Evaluate associated Legendre functions on the output nodes
# Evaluate associated Legendre functions on the output nodes
x
=
torch
.
view_as_real
(
x
)
x
=
torch
.
view_as_real
(
x
)
rl
=
torch
.
einsum
(
'...lm, mlk->...km'
,
x
[...,
0
],
self
.
pct
)
rl
=
torch
.
einsum
(
'...lm, mlk->...km'
,
x
[...,
0
],
self
.
pct
.
to
(
x
.
dtype
)
)
im
=
torch
.
einsum
(
'...lm, mlk->...km'
,
x
[...,
1
],
self
.
pct
)
im
=
torch
.
einsum
(
'...lm, mlk->...km'
,
x
[...,
1
],
self
.
pct
.
to
(
x
.
dtype
)
)
xs
=
torch
.
stack
((
rl
,
im
),
-
1
)
xs
=
torch
.
stack
((
rl
,
im
),
-
1
)
# apply the inverse (real) FFT
# apply the inverse (real) FFT
...
@@ -282,20 +282,20 @@ class RealVectorSHT(nn.Module):
...
@@ -282,20 +282,20 @@ class RealVectorSHT(nn.Module):
# contraction - spheroidal component
# contraction - spheroidal component
# real component
# real component
xout
[...,
0
,
:,
:,
0
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
0
])
\
xout
[...,
0
,
:,
:,
0
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
0
]
.
to
(
x
.
dtype
)
)
\
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
1
])
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
1
]
.
to
(
x
.
dtype
)
)
# iamg component
# iamg component
xout
[...,
0
,
:,
:,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
0
])
\
xout
[...,
0
,
:,
:,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
0
]
.
to
(
x
.
dtype
)
)
\
+
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
1
])
+
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
1
]
.
to
(
x
.
dtype
)
)
# contraction - toroidal component
# contraction - toroidal component
# real component
# real component
xout
[...,
1
,
:,
:,
0
]
=
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
1
])
\
xout
[...,
1
,
:,
:,
0
]
=
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
1
]
.
to
(
x
.
dtype
)
)
\
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
0
])
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
0
]
.
to
(
x
.
dtype
)
)
# imag component
# imag component
xout
[...,
1
,
:,
:,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
1
])
\
xout
[...,
1
,
:,
:,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
1
]
.
to
(
x
.
dtype
)
)
\
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
0
])
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
0
]
.
to
(
x
.
dtype
)
)
return
torch
.
view_as_complex
(
xout
)
return
torch
.
view_as_complex
(
xout
)
...
@@ -358,19 +358,19 @@ class InverseRealVectorSHT(nn.Module):
...
@@ -358,19 +358,19 @@ class InverseRealVectorSHT(nn.Module):
# contraction - spheroidal component
# contraction - spheroidal component
# real component
# real component
srl
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
0
],
self
.
dpct
[
0
])
\
srl
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
0
],
self
.
dpct
[
0
]
.
to
(
x
.
dtype
)
)
\
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
1
],
self
.
dpct
[
1
])
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
1
],
self
.
dpct
[
1
]
.
to
(
x
.
dtype
)
)
# iamg component
# iamg component
sim
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
1
],
self
.
dpct
[
0
])
\
sim
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
1
],
self
.
dpct
[
0
]
.
to
(
x
.
dtype
)
)
\
+
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
0
],
self
.
dpct
[
1
])
+
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
0
],
self
.
dpct
[
1
]
.
to
(
x
.
dtype
)
)
# contraction - toroidal component
# contraction - toroidal component
# real component
# real component
trl
=
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
1
],
self
.
dpct
[
1
])
\
trl
=
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
1
],
self
.
dpct
[
1
]
.
to
(
x
.
dtype
)
)
\
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
0
],
self
.
dpct
[
0
])
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
0
],
self
.
dpct
[
0
]
.
to
(
x
.
dtype
)
)
# imag component
# imag component
tim
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
0
],
self
.
dpct
[
1
])
\
tim
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
0
],
self
.
dpct
[
1
]
.
to
(
x
.
dtype
)
)
\
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
1
],
self
.
dpct
[
0
])
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
1
],
self
.
dpct
[
0
]
.
to
(
x
.
dtype
)
)
# reassemble
# reassemble
s
=
torch
.
stack
((
srl
,
sim
),
-
1
)
s
=
torch
.
stack
((
srl
,
sim
),
-
1
)
...
...
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