Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
201a6a28
Commit
201a6a28
authored
Jul 04, 2018
by
Martin Reinecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more immutability; start importing Python3 builtins everywhere
parent
8924690e
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
68 additions
and
57 deletions
+68
-57
nifty5/data_objects/distributed_do.py
nifty5/data_objects/distributed_do.py
+6
-1
nifty5/domain_tuple.py
nifty5/domain_tuple.py
+2
-0
nifty5/extra/energy_and_model_tests.py
nifty5/extra/energy_and_model_tests.py
+2
-0
nifty5/field.py
nifty5/field.py
+2
-2
nifty5/logger.py
nifty5/logger.py
+3
-0
nifty5/minimization/l_bfgs.py
nifty5/minimization/l_bfgs.py
+2
-4
nifty5/minimization/vl_bfgs.py
nifty5/minimization/vl_bfgs.py
+2
-3
nifty5/models/binary_helpers.py
nifty5/models/binary_helpers.py
+1
-1
nifty5/multi/multi_domain.py
nifty5/multi/multi_domain.py
+1
-43
nifty5/multi/multi_field.py
nifty5/multi/multi_field.py
+2
-1
nifty5/operators/diagonal_operator.py
nifty5/operators/diagonal_operator.py
+2
-1
nifty5/utilities.py
nifty5/utilities.py
+43
-1
No files found.
nifty5/data_objects/distributed_do.py
View file @
201a6a28
...
...
@@ -16,11 +16,13 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
from
functools
import
reduce
import
numpy
as
np
from
.random
import
Random
from
mpi4py
import
MPI
import
sys
from
functools
import
reduce
_comm
=
MPI
.
COMM_WORLD
ntask
=
_comm
.
Get_size
()
...
...
@@ -62,6 +64,9 @@ class data_object(object):
if
local_shape
(
self
.
_shape
,
self
.
_distaxis
)
!=
self
.
_data
.
shape
:
raise
ValueError
(
"shape mismatch"
)
def
copy
(
self
):
return
data_object
(
self
.
_shape
,
self
.
_data
.
copy
(),
self
.
_distaxis
)
# def _sanity_checks(self):
# # check whether the distaxis is consistent
# if self._distaxis < -1 or self._distaxis >= len(self._shape):
...
...
nifty5/domain_tuple.py
View file @
201a6a28
...
...
@@ -16,6 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
from
functools
import
reduce
from
.domains.domain
import
Domain
...
...
nifty5/extra/energy_and_model_tests.py
View file @
201a6a28
...
...
@@ -16,6 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
import
numpy
as
np
from
..sugar
import
from_random
from
..minimization.energy
import
Energy
...
...
nifty5/field.py
View file @
201a6a28
...
...
@@ -16,8 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
builtins
import
range
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
import
numpy
as
np
from
.
import
utilities
from
.domain_tuple
import
DomainTuple
...
...
nifty5/logger.py
View file @
201a6a28
...
...
@@ -16,6 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
def
_logger_init
():
import
logging
...
...
nifty5/minimization/l_bfgs.py
View file @
201a6a28
...
...
@@ -16,10 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
builtins
import
range
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
from
..logger
import
logger
from
.descent_minimizer
import
DescentMinimizer
from
.line_search_strong_wolfe
import
LineSearchStrongWolfe
...
...
nifty5/minimization/vl_bfgs.py
View file @
201a6a28
...
...
@@ -16,9 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
builtins
import
range
from
builtins
import
object
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
import
numpy
as
np
from
.descent_minimizer
import
DescentMinimizer
from
.line_search_strong_wolfe
import
LineSearchStrongWolfe
...
...
nifty5/models/binary_helpers.py
View file @
201a6a28
...
...
@@ -25,7 +25,7 @@ def _joint_position(model1, model2):
a
=
model1
.
position
.
_val
b
=
model2
.
position
.
_val
# Note: In python >3.5 one could do {**a, **b}
ab
=
a
.
copy
(
)
ab
=
dict
(
a
)
ab
.
update
(
b
)
return
MultiField
(
ab
)
...
...
nifty5/multi/multi_domain.py
View file @
201a6a28
import
collections
from
..domain_tuple
import
DomainTuple
__all
=
[
"MultiDomain"
]
class
frozendict
(
collections
.
Mapping
):
"""
An immutable wrapper around dictionaries that implements the complete
:py:class:`collections.Mapping` interface. It can be used as a drop-in
replacement for dictionaries where immutability is desired.
"""
dict_cls
=
dict
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_dict
=
self
.
dict_cls
(
*
args
,
**
kwargs
)
self
.
_hash
=
None
def
__getitem__
(
self
,
key
):
return
self
.
_dict
[
key
]
def
__contains__
(
self
,
key
):
return
key
in
self
.
_dict
def
copy
(
self
,
**
add_or_replace
):
return
self
.
__class__
(
self
,
**
add_or_replace
)
def
__iter__
(
self
):
return
iter
(
self
.
_dict
)
def
__len__
(
self
):
return
len
(
self
.
_dict
)
def
__repr__
(
self
):
return
'<%s %r>'
%
(
self
.
__class__
.
__name__
,
self
.
_dict
)
def
__hash__
(
self
):
if
self
.
_hash
is
None
:
h
=
0
for
key
,
value
in
self
.
_dict
.
items
():
h
^=
hash
((
key
,
value
))
self
.
_hash
=
h
return
self
.
_hash
from
..utilities
import
frozendict
class
MultiDomain
(
frozendict
):
...
...
nifty5/multi/multi_field.py
View file @
201a6a28
...
...
@@ -19,6 +19,7 @@
from
..field
import
Field
import
numpy
as
np
from
.multi_domain
import
MultiDomain
from
..utilities
import
frozendict
class
MultiField
(
object
):
...
...
@@ -28,7 +29,7 @@ class MultiField(object):
----------
val : dict
"""
self
.
_val
=
val
self
.
_val
=
frozendict
(
val
)
self
.
_domain
=
MultiDomain
.
make
(
{
key
:
val
.
domain
for
key
,
val
in
self
.
_val
.
items
()})
...
...
nifty5/operators/diagonal_operator.py
View file @
201a6a28
...
...
@@ -16,7 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
import
numpy
as
np
from
..field
import
Field
from
..domain_tuple
import
DomainTuple
...
...
nifty5/utilities.py
View file @
201a6a28
...
...
@@ -16,17 +16,19 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
builtins
import
*
import
numpy
as
np
from
itertools
import
product
import
abc
from
future.utils
import
with_metaclass
from
functools
import
reduce
import
collections
__all__
=
[
"get_slice_list"
,
"safe_cast"
,
"parse_spaces"
,
"infer_space"
,
"memo"
,
"NiftyMetaBase"
,
"fft_prep"
,
"hartley"
,
"my_fftn_r2c"
,
"my_fftn"
,
"my_sum"
,
"my_lincomb_simple"
,
"my_lincomb"
,
"my_product"
]
"my_product"
,
"frozendict"
]
def
my_sum
(
terms
):
...
...
@@ -290,3 +292,43 @@ def my_fftn_r2c(a, axes=None):
def
my_fftn
(
a
,
axes
=
None
):
from
pyfftw.interfaces.numpy_fft
import
fftn
return
fftn
(
a
,
axes
=
axes
,
**
_fft_extra_args
)
class
frozendict
(
collections
.
Mapping
):
"""
An immutable wrapper around dictionaries that implements the complete
:py:class:`collections.Mapping` interface. It can be used as a drop-in
replacement for dictionaries where immutability is desired.
"""
dict_cls
=
dict
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_dict
=
self
.
dict_cls
(
*
args
,
**
kwargs
)
self
.
_hash
=
None
def
__getitem__
(
self
,
key
):
return
self
.
_dict
[
key
]
def
__contains__
(
self
,
key
):
return
key
in
self
.
_dict
def
copy
(
self
,
**
add_or_replace
):
return
self
.
__class__
(
self
,
**
add_or_replace
)
def
__iter__
(
self
):
return
iter
(
self
.
_dict
)
def
__len__
(
self
):
return
len
(
self
.
_dict
)
def
__repr__
(
self
):
return
'<%s %r>'
%
(
self
.
__class__
.
__name__
,
self
.
_dict
)
def
__hash__
(
self
):
if
self
.
_hash
is
None
:
h
=
0
for
key
,
value
in
self
.
_dict
.
items
():
h
^=
hash
((
key
,
value
))
self
.
_hash
=
h
return
self
.
_hash
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