Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
f94e696d
Commit
f94e696d
authored
Jun 02, 2021
by
Martin Reinecke
Browse files
try to improve ditance handling
parent
c7bbcba3
Pipeline
#102731
passed with stages
in 13 minutes and 40 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/domains/rg_space.py
View file @
f94e696d
...
...
@@ -47,9 +47,9 @@ class RGSpace(StructuredDomain):
Topologically, a n-dimensional RGSpace is a n-Torus, i.e. it has periodic
boundary conditions.
"""
_needed_for_hash
=
[
"_distances"
,
"_shape"
,
"_harmonic"
]
_needed_for_hash
=
[
"_
r
distances"
,
"_shape"
,
"_harmonic"
]
def
__init__
(
self
,
shape
,
distances
=
None
,
harmonic
=
False
):
def
__init__
(
self
,
shape
,
distances
=
None
,
harmonic
=
False
,
_realdistances
=
None
):
self
.
_harmonic
=
bool
(
harmonic
)
if
np
.
isscalar
(
shape
):
shape
=
(
shape
,)
...
...
@@ -57,21 +57,30 @@ class RGSpace(StructuredDomain):
if
min
(
self
.
_shape
)
<
0
:
raise
ValueError
(
'Negative number of pixels encountered'
)
if
distances
is
None
:
if
self
.
harmonic
:
self
.
_distances
=
(
1.
,)
*
len
(
self
.
_shape
)
else
:
self
.
_distances
=
tuple
(
1.
/
s
for
s
in
self
.
_shape
)
elif
np
.
isscalar
(
distances
):
self
.
_distances
=
(
float
(
distances
),)
*
len
(
self
.
_shape
)
if
_realdistances
is
not
None
:
self
.
_rdistances
=
_realdistances
else
:
temp
=
np
.
empty
(
len
(
self
.
shape
),
dtype
=
np
.
float64
)
temp
[:]
=
distances
self
.
_distances
=
tuple
(
temp
)
if
min
(
self
.
_distances
)
<=
0
:
if
distances
is
None
:
if
self
.
_harmonic
:
self
.
_rdistances
=
tuple
(
1.
/
(
np
.
array
(
self
.
_shape
)))
else
:
self
.
_rdistances
=
tuple
(
1.
/
s
for
s
in
self
.
_shape
)
elif
np
.
isscalar
(
distances
):
if
self
.
harmonic
:
self
.
_rdistances
=
tuple
(
1.
/
(
np
.
array
(
self
.
_shape
)
*
float
(
distances
)))
else
:
self
.
_rdistances
=
(
float
(
distances
),)
*
len
(
self
.
_shape
)
else
:
temp
=
np
.
empty
(
len
(
self
.
shape
),
dtype
=
np
.
float64
)
temp
[:]
=
distances
if
self
.
_harmonic
:
temp
=
1.
/
(
np
.
array
(
self
.
_shape
)
*
temp
)
self
.
_rdistances
=
tuple
(
temp
)
if
min
(
self
.
_rdistances
)
<=
0
:
raise
ValueError
(
'Non-positive distances encountered'
)
self
.
_dvol
=
float
(
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_
distances
))
self
.
_dvol
=
float
(
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
distances
))
self
.
_size
=
int
(
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
_shape
))
def
__repr__
(
self
):
...
...
@@ -181,8 +190,7 @@ class RGSpace(StructuredDomain):
RGSpace
The partner domain
"""
distances
=
1.
/
(
np
.
array
(
self
.
shape
)
*
np
.
array
(
self
.
distances
))
return
RGSpace
(
self
.
shape
,
distances
,
not
self
.
harmonic
)
return
RGSpace
(
self
.
shape
,
None
,
not
self
.
harmonic
,
self
.
_rdistances
)
def
check_codomain
(
self
,
codomain
):
"""Raises `TypeError` if `codomain` is not a matching partner domain
...
...
@@ -212,4 +220,7 @@ class RGSpace(StructuredDomain):
The n-th entry of the tuple is the distance between neighboring
grid points along the n-th dimension.
"""
return
self
.
_distances
if
self
.
_harmonic
:
return
tuple
(
1.
/
(
np
.
array
(
self
.
shape
)
*
np
.
array
(
self
.
_rdistances
)))
else
:
return
self
.
_rdistances
test/test_spaces/test_rg_space.py
View file @
f94e696d
...
...
@@ -98,3 +98,9 @@ def test_k_length_array(shape, distances, expected):
def
test_dvol
(
shape
,
distances
,
harmonic
,
power
):
r
=
ift
.
RGSpace
(
shape
=
shape
,
distances
=
distances
,
harmonic
=
harmonic
)
assert_allclose
(
r
.
dvol
,
np
.
prod
(
r
.
distances
)
**
power
)
def
test_codomain
():
for
i
in
range
(
1
,
1000
):
r
=
ift
.
RGSpace
(
shape
=
(
i
,),
distances
=
(
1.
,),
harmonic
=
False
)
assert_equal
(
r
.
get_default_codomain
().
get_default_codomain
(),
r
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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