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
ift
NIFTy
Commits
7c821ad1
Commit
7c821ad1
authored
Sep 18, 2017
by
Martin Reinecke
Browse files
improve DomainTuple and DomainObject hashing
parent
cfbd598e
Pipeline
#18358
passed with stage
in 5 minutes and 53 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty2go/domain_object.py
View file @
7c821ad1
...
...
@@ -41,7 +41,7 @@ class DomainObject(with_metaclass(
"""
def
__init__
(
self
):
self
.
_
ignore
_for_hash
=
[
'_ignore_for_hash'
]
self
.
_
needed
_for_hash
=
[]
@
abc
.
abstractmethod
def
__repr__
(
self
):
...
...
@@ -50,9 +50,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
()):
if
key
not
in
self
.
_ignore_for_hash
:
result_hash
^=
vars
(
self
)[
key
].
__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
):
...
...
@@ -73,10 +72,9 @@ class DomainObject(with_metaclass(
return
True
if
not
isinstance
(
x
,
type
(
self
)):
return
False
for
key
in
list
(
vars
(
self
).
keys
()):
if
key
not
in
self
.
_ignore_for_hash
:
if
vars
(
self
)[
key
]
!=
vars
(
x
)[
key
]:
return
False
for
key
in
self
.
_needed_for_hash
:
if
vars
(
self
)[
key
]
!=
vars
(
x
)[
key
]:
return
False
return
True
def
__ne__
(
self
,
x
):
...
...
nifty2go/domain_tuple.py
View file @
7c821ad1
...
...
@@ -20,6 +20,8 @@ from functools import reduce
from
.domain_object
import
DomainObject
class
DomainTuple
(
object
):
_tupleCache
=
{}
def
__init__
(
self
,
domain
):
self
.
_dom
=
self
.
_parse_domain
(
domain
)
self
.
_axtuple
=
self
.
_get_axes_tuple
()
...
...
@@ -40,7 +42,13 @@ class DomainTuple(object):
def
make
(
domain
):
if
isinstance
(
domain
,
DomainTuple
):
return
domain
return
DomainTuple
(
domain
)
domain
=
DomainTuple
.
_parse_domain
(
domain
)
obj
=
DomainTuple
.
_tupleCache
.
get
(
domain
)
if
obj
is
not
None
:
return
obj
obj
=
DomainTuple
(
domain
)
DomainTuple
.
_tupleCache
[
domain
]
=
obj
return
obj
@
staticmethod
def
_parse_domain
(
domain
):
...
...
nifty2go/spaces/gl_space/gl_space.py
View file @
7c821ad1
...
...
@@ -82,7 +82,7 @@ class GLSpace(Space):
def
__init__
(
self
,
nlat
,
nlon
=
None
):
super
(
GLSpace
,
self
).
__init__
()
self
.
_
ignore
_for_hash
+=
[
"_
wgt
"
]
self
.
_
needed
_for_hash
+=
[
"_
nlat"
,
"_nlon
"
]
self
.
_nlat
=
self
.
_parse_nlat
(
nlat
)
self
.
_nlon
=
self
.
_parse_nlon
(
nlon
)
...
...
nifty2go/spaces/hp_space/hp_space.py
View file @
7c821ad1
...
...
@@ -80,6 +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---
...
...
nifty2go/spaces/lm_space/lm_space.py
View file @
7c821ad1
...
...
@@ -85,6 +85,7 @@ class LMSpace(Space):
def
__init__
(
self
,
lmax
):
super
(
LMSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_lmax"
]
self
.
_lmax
=
self
.
_parse_lmax
(
lmax
)
def
__repr__
(
self
):
...
...
nifty2go/spaces/power_space/power_space.py
View file @
7c821ad1
...
...
@@ -144,7 +144,7 @@ class PowerSpace(Space):
def
__init__
(
self
,
harmonic_partner
,
binbounds
=
None
):
super
(
PowerSpace
,
self
).
__init__
()
self
.
_
ignore
_for_hash
+=
[
'_
pindex
'
,
'_
k
in
dex'
,
'_rho
'
]
self
.
_
needed
_for_hash
+=
[
'_
harmonic_partner
'
,
'_
b
in
bounds
'
]
if
not
(
isinstance
(
harmonic_partner
,
Space
)
and
harmonic_partner
.
harmonic
):
...
...
nifty2go/spaces/rg_space/rg_space.py
View file @
7c821ad1
...
...
@@ -82,6 +82,7 @@ class RGSpace(Space):
def
__init__
(
self
,
shape
,
distances
=
None
,
harmonic
=
False
):
super
(
RGSpace
,
self
).
__init__
()
self
.
_needed_for_hash
+=
[
"_distances"
,
"_shape"
,
"_harmonic"
]
self
.
_harmonic
=
bool
(
harmonic
)
self
.
_shape
=
self
.
_parse_shape
(
shape
)
...
...
Write
Preview
Supports
Markdown
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