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
543fd126
Commit
543fd126
authored
Aug 02, 2023
by
Thorsten Kurth
Browse files
fixing precision
parent
855297ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
torch_harmonics/sht.py
torch_harmonics/sht.py
+20
-20
No files found.
torch_harmonics/sht.py
View file @
543fd126
...
...
@@ -120,8 +120,8 @@ class RealSHT(nn.Module):
xout
=
torch
.
zeros
(
out_shape
,
dtype
=
x
.
dtype
,
device
=
x
.
device
)
# contraction
xout
[...,
0
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
:
self
.
mmax
,
0
],
self
.
weights
)
xout
[...,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
:
self
.
mmax
,
1
],
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
.
to
(
x
.
dtype
)
)
x
=
torch
.
view_as_complex
(
xout
)
return
x
...
...
@@ -185,8 +185,8 @@ class InverseRealSHT(nn.Module):
# Evaluate associated Legendre functions on the output nodes
x
=
torch
.
view_as_real
(
x
)
rl
=
torch
.
einsum
(
'...lm, mlk->...km'
,
x
[...,
0
],
self
.
pct
)
im
=
torch
.
einsum
(
'...lm, mlk->...km'
,
x
[...,
1
],
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
.
to
(
x
.
dtype
)
)
xs
=
torch
.
stack
((
rl
,
im
),
-
1
)
# apply the inverse (real) FFT
...
...
@@ -282,20 +282,20 @@ class RealVectorSHT(nn.Module):
# contraction - spheroidal component
# real component
xout
[...,
0
,
:,
:,
0
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
0
])
\
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
1
])
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
]
.
to
(
x
.
dtype
)
)
# iamg component
xout
[...,
0
,
:,
:,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
0
])
\
+
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
1
])
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
]
.
to
(
x
.
dtype
)
)
# contraction - toroidal component
# real component
xout
[...,
1
,
:,
:,
0
]
=
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
1
])
\
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
0
])
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
]
.
to
(
x
.
dtype
)
)
# imag component
xout
[...,
1
,
:,
:,
1
]
=
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
0
,
:,
:
self
.
mmax
,
0
],
self
.
weights
[
1
])
\
-
torch
.
einsum
(
'...km,mlk->...lm'
,
x
[...,
1
,
:,
:
self
.
mmax
,
1
],
self
.
weights
[
0
])
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
]
.
to
(
x
.
dtype
)
)
return
torch
.
view_as_complex
(
xout
)
...
...
@@ -358,19 +358,19 @@ class InverseRealVectorSHT(nn.Module):
# contraction - spheroidal component
# real component
srl
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
0
],
self
.
dpct
[
0
])
\
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
1
],
self
.
dpct
[
1
])
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
]
.
to
(
x
.
dtype
)
)
# iamg component
sim
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
1
],
self
.
dpct
[
0
])
\
+
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
0
],
self
.
dpct
[
1
])
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
]
.
to
(
x
.
dtype
)
)
# contraction - toroidal component
# real component
trl
=
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
1
],
self
.
dpct
[
1
])
\
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
0
],
self
.
dpct
[
0
])
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
]
.
to
(
x
.
dtype
)
)
# imag component
tim
=
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
0
,
:,
:,
0
],
self
.
dpct
[
1
])
\
-
torch
.
einsum
(
'...lm,mlk->...km'
,
x
[...,
1
,
:,
:,
1
],
self
.
dpct
[
0
])
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
]
.
to
(
x
.
dtype
)
)
# reassemble
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