Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neel Shah
NIFTy
Commits
4c2a4012
Commit
4c2a4012
authored
Sep 29, 2017
by
Martin Reinecke
Browse files
tweak DomainObject comparisons
parent
fd036abf
Changes
6
Hide whitespace changes
Inline
Side-by-side
nifty/domain_object.py
View file @
4c2a4012
...
@@ -43,8 +43,7 @@ class DomainObject(with_metaclass(
...
@@ -43,8 +43,7 @@ class DomainObject(with_metaclass(
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
# _global_id is used in the Versioning module from keepers
self
.
_needed_for_hash
=
[]
self
.
_ignore_for_hash
=
[
'_global_id'
]
@
abc
.
abstractmethod
@
abc
.
abstractmethod
def
__repr__
(
self
):
def
__repr__
(
self
):
...
@@ -53,11 +52,8 @@ class DomainObject(with_metaclass(
...
@@ -53,11 +52,8 @@ class DomainObject(with_metaclass(
def
__hash__
(
self
):
def
__hash__
(
self
):
# Extract the identifying parts from the vars(self) dict.
# Extract the identifying parts from the vars(self) dict.
result_hash
=
0
result_hash
=
0
for
key
in
sorted
(
vars
(
self
).
keys
()):
for
key
in
self
.
_needed_for_hash
:
item
=
vars
(
self
)[
key
]
result_hash
^=
hash
(
vars
(
self
)[
key
])
if
key
in
self
.
_ignore_for_hash
or
key
==
'_ignore_for_hash'
:
continue
result_hash
^=
item
.
__hash__
()
^
int
(
hash
(
key
)
//
117
)
return
result_hash
return
result_hash
def
__eq__
(
self
,
x
):
def
__eq__
(
self
,
x
):
...
@@ -74,18 +70,14 @@ class DomainObject(with_metaclass(
...
@@ -74,18 +70,14 @@ class DomainObject(with_metaclass(
True if `self` and x describe the same manifold.
True if `self` and x describe the same manifold.
"""
"""
if
self
is
x
:
# shortcut for simple case
if
isinstance
(
x
,
type
(
self
)):
for
key
in
list
(
vars
(
self
).
keys
()):
item1
=
vars
(
self
)[
key
]
if
key
in
self
.
_ignore_for_hash
or
key
==
'_ignore_for_hash'
:
continue
item2
=
vars
(
x
)[
key
]
if
item1
!=
item2
:
return
False
return
True
return
True
else
:
if
not
isinstance
(
x
,
type
(
self
))
:
return
False
return
False
for
key
in
self
.
_needed_for_hash
:
if
vars
(
self
)[
key
]
!=
vars
(
x
)[
key
]:
return
False
return
True
def
__ne__
(
self
,
x
):
def
__ne__
(
self
,
x
):
return
not
self
.
__eq__
(
x
)
return
not
self
.
__eq__
(
x
)
...
...
nifty/spaces/gl_space/gl_space.py
View file @
4c2a4012
...
@@ -94,6 +94,7 @@ class GLSpace(Space):
...
@@ -94,6 +94,7 @@ class GLSpace(Space):
"The module pyHealpix is needed but not available."
)
"The module pyHealpix is needed but not available."
)
super
(
GLSpace
,
self
).
__init__
()
super
(
GLSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_nlat"
,
"_nlon"
]
self
.
_nlat
=
self
.
_parse_nlat
(
nlat
)
self
.
_nlat
=
self
.
_parse_nlat
(
nlat
)
self
.
_nlon
=
self
.
_parse_nlon
(
nlon
)
self
.
_nlon
=
self
.
_parse_nlon
(
nlon
)
...
...
nifty/spaces/hp_space/hp_space.py
View file @
4c2a4012
...
@@ -80,7 +80,7 @@ class HPSpace(Space):
...
@@ -80,7 +80,7 @@ class HPSpace(Space):
def
__init__
(
self
,
nside
):
def
__init__
(
self
,
nside
):
super
(
HPSpace
,
self
).
__init__
()
super
(
HPSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_nside"
]
self
.
_nside
=
self
.
_parse_nside
(
nside
)
self
.
_nside
=
self
.
_parse_nside
(
nside
)
# ---Mandatory properties and methods---
# ---Mandatory properties and methods---
...
@@ -94,7 +94,7 @@ class HPSpace(Space):
...
@@ -94,7 +94,7 @@ class HPSpace(Space):
@
property
@
property
def
shape
(
self
):
def
shape
(
self
):
return
(
np
.
int
(
12
*
self
.
nside
*
self
.
nside
)
,)
return
(
self
.
dim
,)
@
property
@
property
def
dim
(
self
):
def
dim
(
self
):
...
...
nifty/spaces/lm_space/lm_space.py
View file @
4c2a4012
...
@@ -87,6 +87,7 @@ class LMSpace(Space):
...
@@ -87,6 +87,7 @@ class LMSpace(Space):
def
__init__
(
self
,
lmax
):
def
__init__
(
self
,
lmax
):
super
(
LMSpace
,
self
).
__init__
()
super
(
LMSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_lmax"
]
self
.
_lmax
=
self
.
_parse_lmax
(
lmax
)
self
.
_lmax
=
self
.
_parse_lmax
(
lmax
)
# ---Mandatory properties and methods---
# ---Mandatory properties and methods---
...
...
nifty/spaces/power_space/power_space.py
View file @
4c2a4012
...
@@ -87,8 +87,8 @@ class PowerSpace(Space):
...
@@ -87,8 +87,8 @@ class PowerSpace(Space):
def
__init__
(
self
,
harmonic_partner
,
distribution_strategy
=
None
,
def
__init__
(
self
,
harmonic_partner
,
distribution_strategy
=
None
,
volume_type
=
'rho'
,
binbounds
=
None
):
volume_type
=
'rho'
,
binbounds
=
None
):
super
(
PowerSpace
,
self
).
__init__
()
super
(
PowerSpace
,
self
).
__init__
()
self
.
_
ignore
_for_hash
+=
[
'_
pindex
'
,
'_
k
in
dex'
,
'_rho
'
,
self
.
_
needed
_for_hash
+=
[
'_
harmonic_partner
'
,
'_
b
in
bounds
'
,
'
_
volume_
weight
'
]
'volume_
type
'
]
if
distribution_strategy
is
None
:
if
distribution_strategy
is
None
:
distribution_strategy
=
gc
[
'default_distribution_strategy'
]
distribution_strategy
=
gc
[
'default_distribution_strategy'
]
...
...
nifty/spaces/rg_space/rg_space.py
View file @
4c2a4012
...
@@ -75,10 +75,10 @@ class RGSpace(Space):
...
@@ -75,10 +75,10 @@ class RGSpace(Space):
# ---Overwritten properties and methods---
# ---Overwritten properties and methods---
def
__init__
(
self
,
shape
,
distances
=
None
,
harmonic
=
False
):
def
__init__
(
self
,
shape
,
distances
=
None
,
harmonic
=
False
):
self
.
_harmonic
=
bool
(
harmonic
)
super
(
RGSpace
,
self
).
__init__
()
super
(
RGSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_distances"
,
"_shape"
,
"_harmonic"
]
self
.
_harmonic
=
bool
(
harmonic
)
self
.
_shape
=
self
.
_parse_shape
(
shape
)
self
.
_shape
=
self
.
_parse_shape
(
shape
)
self
.
_distances
=
self
.
_parse_distances
(
distances
)
self
.
_distances
=
self
.
_parse_distances
(
distances
)
...
...
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