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
4772fce8
Commit
4772fce8
authored
Jun 06, 2021
by
Martin Reinecke
Browse files
Merge branch 'fix_distances' into 'NIFTy_7'
Fix distances See merge request
!631
parents
4fdf19db
b1bd9aae
Pipeline
#102975
passed with stages
in 13 minutes and 44 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/domains/rg_space.py
View file @
4772fce8
...
...
@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-202
0
Max-Planck-Society
# Copyright(C) 2013-202
1
Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
...
...
@@ -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,29 @@ 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
:
self
.
_rdistances
=
tuple
(
1.
/
(
np
.
array
(
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
)
self
.
_hdistances
=
tuple
(
1.
/
(
np
.
array
(
self
.
shape
)
*
np
.
array
(
self
.
_rdistances
)))
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 +189,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 +219,4 @@ 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
return
self
.
_
hdistances
if
self
.
_harmonic
else
self
.
_r
distances
test/test_spaces/test_rg_space.py
View file @
4772fce8
...
...
@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-201
9
Max-Planck-Society
# Copyright(C) 2013-20
2
1 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
...
...
@@ -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