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
4dd9b524
Commit
4dd9b524
authored
Oct 06, 2017
by
Theo Steininger
Browse files
Merge branch 'comparisons' into 'nightly'
tweak DomainObject comparisons See merge request !202
parents
fd036abf
3eba13ae
Changes
7
Show whitespace changes
Inline
Side-by-side
nifty/domain_object.py
View file @
4dd9b524
...
...
@@ -43,8 +43,7 @@ class DomainObject(with_metaclass(
"""
def
__init__
(
self
):
# _global_id is used in the Versioning module from keepers
self
.
_ignore_for_hash
=
[
'_global_id'
]
self
.
_needed_for_hash
=
[]
@
abc
.
abstractmethod
def
__repr__
(
self
):
...
...
@@ -53,11 +52,8 @@ class DomainObject(with_metaclass(
def
__hash__
(
self
):
# Extract the identifying parts from the vars(self) dict.
result_hash
=
0
for
key
in
sorted
(
vars
(
self
).
keys
()):
item
=
vars
(
self
)[
key
]
if
key
in
self
.
_ignore_for_hash
or
key
==
'_ignore_for_hash'
:
continue
result_hash
^=
item
.
__hash__
()
^
int
(
hash
(
key
)
//
117
)
for
key
in
self
.
_needed_for_hash
:
result_hash
^=
hash
(
vars
(
self
)[
key
])
return
result_hash
def
__eq__
(
self
,
x
):
...
...
@@ -74,18 +70,14 @@ class DomainObject(with_metaclass(
True if `self` and x describe the same manifold.
"""
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
if
self
is
x
:
# shortcut for simple case
return
True
else
:
if
not
isinstance
(
x
,
type
(
self
))
:
return
False
for
key
in
self
.
_needed_for_hash
:
if
vars
(
self
)[
key
]
!=
vars
(
x
)[
key
]:
return
False
return
True
def
__ne__
(
self
,
x
):
return
not
self
.
__eq__
(
x
)
...
...
nifty/field_types/field_array.py
View file @
4dd9b524
...
...
@@ -24,6 +24,8 @@ class FieldArray(FieldType):
def
__init__
(
self
,
shape
):
super
(
FieldArray
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_shape"
]
try
:
self
.
_shape
=
tuple
([
int
(
i
)
for
i
in
shape
])
except
TypeError
:
...
...
nifty/spaces/gl_space/gl_space.py
View file @
4dd9b524
...
...
@@ -94,6 +94,7 @@ class GLSpace(Space):
"The module pyHealpix is needed but not available."
)
super
(
GLSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_nlat"
,
"_nlon"
]
self
.
_nlat
=
self
.
_parse_nlat
(
nlat
)
self
.
_nlon
=
self
.
_parse_nlon
(
nlon
)
...
...
nifty/spaces/hp_space/hp_space.py
View file @
4dd9b524
...
...
@@ -80,7 +80,7 @@ class HPSpace(Space):
def
__init__
(
self
,
nside
):
super
(
HPSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_nside"
]
self
.
_nside
=
self
.
_parse_nside
(
nside
)
# ---Mandatory properties and methods---
...
...
@@ -94,7 +94,7 @@ class HPSpace(Space):
@
property
def
shape
(
self
):
return
(
np
.
int
(
12
*
self
.
nside
*
self
.
nside
)
,)
return
(
self
.
dim
,)
@
property
def
dim
(
self
):
...
...
nifty/spaces/lm_space/lm_space.py
View file @
4dd9b524
...
...
@@ -87,6 +87,7 @@ class LMSpace(Space):
def
__init__
(
self
,
lmax
):
super
(
LMSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_lmax"
]
self
.
_lmax
=
self
.
_parse_lmax
(
lmax
)
# ---Mandatory properties and methods---
...
...
nifty/spaces/power_space/power_space.py
View file @
4dd9b524
...
...
@@ -87,8 +87,8 @@ class PowerSpace(Space):
def
__init__
(
self
,
harmonic_partner
,
distribution_strategy
=
None
,
volume_type
=
'rho'
,
binbounds
=
None
):
super
(
PowerSpace
,
self
).
__init__
()
self
.
_
ignore
_for_hash
+=
[
'_
pindex
'
,
'_
k
in
dex'
,
'_rho
'
,
'
_
volume_
weight
'
]
self
.
_
needed
_for_hash
+=
[
'_
harmonic_partner
'
,
'_
b
in
bounds
'
,
'volume_
type
'
]
if
distribution_strategy
is
None
:
distribution_strategy
=
gc
[
'default_distribution_strategy'
]
...
...
nifty/spaces/rg_space/rg_space.py
View file @
4dd9b524
...
...
@@ -75,10 +75,10 @@ class RGSpace(Space):
# ---Overwritten properties and methods---
def
__init__
(
self
,
shape
,
distances
=
None
,
harmonic
=
False
):
self
.
_harmonic
=
bool
(
harmonic
)
super
(
RGSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_distances"
,
"_shape"
,
"_harmonic"
]
self
.
_harmonic
=
bool
(
harmonic
)
self
.
_shape
=
self
.
_parse_shape
(
shape
)
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