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
bbd1c13e
Commit
bbd1c13e
authored
Sep 02, 2016
by
theos
Browse files
Renamed 'datamodel' to 'distribution_strategy'.
parent
c3c16adb
Changes
7
Hide whitespace changes
Inline
Side-by-side
nifty/config/nifty_config.py
View file @
bbd1c13e
...
...
@@ -80,8 +80,8 @@ variable_default_field_dtype = keepers.Variable(
_dtype_validator
,
genus
=
'str'
)
variable_default_d
atamodel
=
keepers
.
Variable
(
'default_d
atamodel
'
,
variable_default_d
istribution_strategy
=
keepers
.
Variable
(
'default_d
istribution_strategy
'
,
[
'fftw'
,
'equal'
],
lambda
z
:
((
'pyfftw'
in
dependency_injector
)
if
z
==
'fftw'
else
True
),
...
...
@@ -95,7 +95,7 @@ nifty_configuration = keepers.get_Configuration(
variable_use_libsharp
,
variable_verbosity
,
variable_default_field_dtype
,
variable_default_d
atamodel
,
variable_default_d
istribution_strategy
,
],
path
=
os
.
path
.
expanduser
(
'~'
)
+
"/.nifty/nifty_config"
)
########
...
...
nifty/field.py
View file @
bbd1c13e
...
...
@@ -25,7 +25,7 @@ class Field(object):
# ---Initialization methods---
def
__init__
(
self
,
domain
=
None
,
val
=
None
,
dtype
=
None
,
field_type
=
None
,
d
atamodel
=
None
,
copy
=
False
):
d
istribution_strategy
=
None
,
copy
=
False
):
self
.
domain
=
self
.
_parse_domain
(
domain
=
domain
,
val
=
val
)
self
.
domain_axes
=
self
.
_get_axes_tuple
(
self
.
domain
)
...
...
@@ -44,8 +44,9 @@ class Field(object):
domain
=
self
.
domain
,
field_type
=
self
.
field_type
)
self
.
datamodel
=
self
.
_parse_datamodel
(
datamodel
=
datamodel
,
val
=
val
)
self
.
distribution_strategy
=
self
.
_parse_distribution_strategy
(
distribution_strategy
=
distribution_strategy
,
val
=
val
)
self
.
set_val
(
new_val
=
val
,
copy
=
copy
)
...
...
@@ -111,28 +112,28 @@ class Field(object):
return
dtype
def
_parse_d
atamodel
(
self
,
datamodel
,
val
):
if
d
atamodel
is
None
:
def
_parse_d
istribution_strategy
(
self
,
distribution_strategy
,
val
):
if
d
istribution_strategy
is
None
:
if
isinstance
(
val
,
distributed_data_object
):
d
atamodel
=
val
.
distribution_strategy
d
istribution_strategy
=
val
.
distribution_strategy
elif
isinstance
(
val
,
Field
):
d
atamodel
=
val
.
datamodel
d
istribution_strategy
=
val
.
distribution_strategy
else
:
about
.
warnings
.
cprint
(
"WARNING: Datamodel set to default!"
)
d
atamodel
=
gc
[
'default_datamodel
'
]
elif
d
atamodel
not
in
DISTRIBUTION_STRATEGIES
[
'all'
]:
d
istribution_strategy
=
gc
[
'default_distribution_strategy
'
]
elif
d
istribution_strategy
not
in
DISTRIBUTION_STRATEGIES
[
'all'
]:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: Invalid d
atamodel
!"
))
return
d
atamodel
"ERROR: Invalid d
istribution_strategy
!"
))
return
d
istribution_strategy
# ---Factory methods---
@
classmethod
def
from_random
(
cls
,
random_type
,
domain
=
None
,
dtype
=
None
,
field_type
=
None
,
d
atamodel
=
None
,
**
kwargs
):
d
istribution_strategy
=
None
,
**
kwargs
):
# create a initially empty field
f
=
cls
(
domain
=
domain
,
dtype
=
dtype
,
field_type
=
field_type
,
d
atamodel
=
datamodel
)
d
istribution_strategy
=
distribution_strategy
)
# now use the processed input in terms of f in order to parse the
# random arguments
...
...
@@ -229,7 +230,7 @@ class Field(object):
harmonic_domain
=
self
.
domain
[
space_index
]
power_domain
=
PowerSpace
(
harmonic_domain
=
harmonic_domain
,
d
atamodel
=
distribution_strategy
,
d
istribution_strategy
=
distribution_strategy
,
log
=
log
,
nbin
=
nbin
,
binbounds
=
binbounds
,
dtype
=
power_dtype
)
...
...
@@ -358,11 +359,12 @@ class Field(object):
else
:
result_list
=
[
None
]
result_list
=
[
self
.
__class__
.
from_random
(
'normal'
,
result_domain
,
dtype
=
harmonic_domain
.
dtype
,
field_type
=
self
.
field_type
,
datamodel
=
self
.
datamodel
)
result_list
=
[
self
.
__class__
.
from_random
(
'normal'
,
result_domain
,
dtype
=
harmonic_domain
.
dtype
,
field_type
=
self
.
field_type
,
distribution_strategy
=
self
.
distribution_strategy
)
for
x
in
result_list
]
# from now on extract the values from the random fields for further
...
...
@@ -512,24 +514,25 @@ class Field(object):
dtype
=
self
.
dtype
return_x
=
distributed_data_object
(
global_shape
=
self
.
shape
,
dtype
=
dtype
,
distribution_strategy
=
self
.
d
atamodel
)
global_shape
=
self
.
shape
,
dtype
=
dtype
,
distribution_strategy
=
self
.
d
istribution_strategy
)
return_x
.
set_full_data
(
x
,
copy
=
False
)
return
return_x
def
copy
(
self
,
domain
=
None
,
dtype
=
None
,
field_type
=
None
,
d
atamodel
=
None
):
d
istribution_strategy
=
None
):
copied_val
=
self
.
get_val
(
copy
=
True
)
new_field
=
self
.
copy_empty
(
domain
=
domain
,
dtype
=
dtype
,
field_type
=
field_type
,
datamodel
=
datamodel
)
new_field
=
self
.
copy_empty
(
domain
=
domain
,
dtype
=
dtype
,
field_type
=
field_type
,
distribution_strategy
=
distribution_strategy
)
new_field
.
set_val
(
new_val
=
copied_val
,
copy
=
False
)
return
new_field
def
copy_empty
(
self
,
domain
=
None
,
dtype
=
None
,
field_type
=
None
,
d
atamodel
=
None
):
d
istribution_strategy
=
None
):
if
domain
is
None
:
domain
=
self
.
domain
else
:
...
...
@@ -545,8 +548,8 @@ class Field(object):
else
:
field_type
=
self
.
_parse_field_type
(
field_type
)
if
d
atamodel
is
None
:
d
atamodel
=
self
.
datamodel
if
d
istribution_strategy
is
None
:
d
istribution_strategy
=
self
.
distribution_strategy
fast_copyable
=
True
try
:
...
...
@@ -562,13 +565,13 @@ class Field(object):
fast_copyable
=
False
if
(
fast_copyable
and
dtype
==
self
.
dtype
and
d
atamodel
==
self
.
datamodel
):
d
istribution_strategy
==
self
.
distribution_strategy
):
new_field
=
self
.
_fast_copy_empty
()
else
:
new_field
=
Field
(
domain
=
domain
,
dtype
=
dtype
,
field_type
=
field_type
,
d
atamodel
=
datamodel
)
d
istribution_strategy
=
distribution_strategy
)
return
new_field
def
_fast_copy_empty
(
self
):
...
...
nifty/operators/diagonal_operator/diagonal_operator.py
View file @
bbd1c13e
...
...
@@ -16,26 +16,63 @@ class DiagonalOperator(EndomorphicOperator):
# ---Overwritten properties and methods---
def
__init__
(
self
,
domain
=
(),
field_type
=
(),
implemented
=
False
,
diagonal
=
None
,
bare
=
False
,
copy
=
True
,
datamodel
=
None
):
diagonal
=
None
,
bare
=
False
,
copy
=
True
,
distribution_strategy
=
None
):
super
(
DiagonalOperator
,
self
).
__init__
(
domain
=
domain
,
field_type
=
field_type
,
implemented
=
implemented
)
self
.
_implemented
=
bool
(
implemented
)
if
d
atamodel
is
None
:
if
d
istribution_strategy
is
None
:
if
isinstance
(
diagonal
,
distributed_data_object
):
d
atamodel
=
diagonal
.
distribution_strategy
d
istribution_strategy
=
diagonal
.
distribution_strategy
elif
isinstance
(
diagonal
,
Field
):
d
atamodel
=
diagonal
.
datamodel
d
istribution_strategy
=
diagonal
.
distribution_strategy
self
.
datamodel
=
self
.
_parse_datamodel
(
datamodel
=
datamodel
,
val
=
diagonal
)
self
.
distribution_strategy
=
self
.
_parse_distribution_strategy
(
distribution_strategy
=
distribution_strategy
,
val
=
diagonal
)
self
.
set_diagonal
(
diagonal
=
diagonal
,
bare
=
bare
,
copy
=
copy
)
def
_times
(
self
,
x
,
spaces
,
types
):
pass
# if the distribution_strategy of self is sub-slice compatible to
# the one of x, reshape the local data of self and apply it directly
active_axes
=
[]
if
spaces
is
None
:
for
axes
in
x
.
domain_axes
:
active_axes
+=
axes
else
:
for
space_index
in
spaces
:
active_axes
+=
x
.
domain_axes
[
space_index
]
if
types
is
None
:
for
axes
in
x
.
field_type_axes
:
active_axes
+=
axes
else
:
for
type_index
in
types
:
active_axes
+=
x
.
field_type_axes
[
type_index
]
if
x
.
val
.
get_axes_local_distribution_strategy
(
active_axes
)
==
\
self
.
distribution_strategy
:
local_data
=
self
.
_diagonal
.
val
.
get_local_data
(
copy
=
False
)
# check if domains match completely
# -> multiply directly
# check if axes_local_distribution_strategy matches.
# If yes, extract local data of self.diagonal and x and use numpy
# reshape.
# assert that indices in spaces and types are striktly increasing
# otherwise a wild transpose would be necessary
# build new shape (1,1,x,1,y,1,1,z)
# copy self.diagonal into new shape
# apply reshaped array to x
def
_adjoint_times
(
self
,
x
,
spaces
,
types
):
pass
...
...
@@ -97,29 +134,29 @@ class DiagonalOperator(EndomorphicOperator):
# ---Added properties and methods---
@
property
def
d
atamodel
(
self
):
return
self
.
_d
atamodel
def
d
istribution_strategy
(
self
):
return
self
.
_d
istribution_strategy
def
_parse_d
atamodel
(
self
,
datamodel
,
val
):
if
d
atamodel
is
None
:
def
_parse_d
istribution_strategy
(
self
,
distribution_strategy
,
val
):
if
d
istribution_strategy
is
None
:
if
isinstance
(
val
,
distributed_data_object
):
d
atamodel
=
val
.
distribution_strategy
d
istribution_strategy
=
val
.
distribution_strategy
elif
isinstance
(
val
,
Field
):
d
atamodel
=
val
.
datamodel
d
istribution_strategy
=
val
.
distribution_strategy
else
:
about
.
warnings
.
cprint
(
"WARNING: Datamodel set to default!"
)
d
atamodel
=
gc
[
'default_datamodel
'
]
elif
d
atamodel
not
in
DISTRIBUTION_STRATEGIES
[
'all'
]:
d
istribution_strategy
=
gc
[
'default_distribution_strategy
'
]
elif
d
istribution_strategy
not
in
DISTRIBUTION_STRATEGIES
[
'all'
]:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: Invalid d
atamodel
!"
))
return
d
atamodel
"ERROR: Invalid d
istribution_strategy
!"
))
return
d
istribution_strategy
def
set_diagonal
(
self
,
diagonal
,
bare
=
False
,
copy
=
True
):
# use the casting functionality from Field to process `diagonal`
f
=
Field
(
domain
=
self
.
domain
,
val
=
diagonal
,
field_type
=
self
.
field_type
,
d
atamodel
=
self
.
datamodel
,
d
istribution_strategy
=
self
.
distribution_strategy
,
copy
=
copy
)
# weight if the given values were `bare` and `implemented` is True
...
...
nifty/operators/linear_operator/linear_operator.py
View file @
bbd1c13e
...
...
@@ -157,8 +157,7 @@ class LinearOperator(object):
# cases:
# 1. Case:
# The user specifies with `spaces` that the operators domain should
# be applied to a certain domain in the domain-tuple of x. This is
# only valid if len(self.domain)==1.
# be applied to certain spaces in the domain-tuple of x.
# 2. Case:
# The domains of self and x match completely.
...
...
@@ -175,16 +174,8 @@ class LinearOperator(object):
"ERROR: The operator's and and field's domains don't "
"match."
))
else
:
if
len
(
self_domain
)
>
1
:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: Specifying `spaces` for operators with multiple "
"domain spaces is not valid."
))
elif
len
(
spaces
)
!=
len
(
self_domain
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: Length of `spaces` does not match the number of "
"spaces in the operator's domain."
))
elif
len
(
spaces
)
==
1
:
if
x
.
domain
[
spaces
[
0
]]
!=
self_domain
[
0
]:
for
i
,
space_index
in
enumerate
(
spaces
):
if
x
.
domain
[
space_index
]
!=
self_domain
[
i
]:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: The operator's and and field's domains don't "
"match."
))
...
...
@@ -195,19 +186,12 @@ class LinearOperator(object):
"ERROR: The operator's and and field's field_types don't "
"match."
))
else
:
if
len
(
self_field_type
)
>
1
:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: Specifying `types` for operators with multiple "
"field-types is not valid."
))
elif
len
(
types
)
!=
len
(
self_field_type
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: Length of `types` does not match the number of "
"the operator's field-types."
))
elif
len
(
types
)
==
1
:
if
x
.
field_type
[
types
[
0
]]
!=
self_field_type
[
0
]:
for
i
,
field_type_index
in
enumerate
(
types
):
if
x
.
field_types
[
field_type_index
]
!=
self_field_type
[
i
]:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: The operator's and and field's field_type "
"don't match."
))
return
(
spaces
,
types
)
def
__repr__
(
self
):
...
...
nifty/operators/nifty_operators.py
View file @
bbd1c13e
...
...
@@ -2840,7 +2840,7 @@ class response_operator(operator):
# TODO: Fix the target spaces
target
=
Space
(
assignments
,
dtype
=
self
.
domain
.
dtype
,
d
atamodel
=
self
.
domain
.
datamodel
)
d
istribution_strategy
=
self
.
domain
.
distribution_strategy
)
else
:
# check target
if
not
isinstance
(
target
,
Space
):
...
...
nifty/spaces/lm_space/lm_space.py
View file @
bbd1c13e
...
...
@@ -499,7 +499,7 @@ class LMSpace(Space):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: unsupported codomain."
))
# if self.d
atamodel
!= 'not':
# if self.d
istribution_strategy
!= 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external alm2map method!")
...
...
@@ -569,7 +569,7 @@ class LMSpace(Space):
elif
sigma
<
0
:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: invalid sigma."
))
# if self.d
atamodel
!= 'not':
# if self.d
istribution_strategy
!= 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external smoothalm method!")
...
...
@@ -612,7 +612,7 @@ class LMSpace(Space):
lmax
=
self
.
paradict
[
'lmax'
]
mmax
=
self
.
paradict
[
'mmax'
]
# if self.d
atamodel
!= 'not':
# if self.d
istribution_strategy
!= 'not':
# about.warnings.cprint(
# "WARNING: Field data is consolidated to all nodes for "
# "external anaalm/alm2cl method!")
...
...
nifty/spaces/power_space/power_space.py
View file @
bbd1c13e
...
...
@@ -14,7 +14,7 @@ class PowerSpace(Space):
# ---Overwritten properties and methods---
def
__init__
(
self
,
harmonic_domain
=
RGSpace
((
1
,)),
d
atamodel
=
'not'
,
def
__init__
(
self
,
harmonic_domain
=
RGSpace
((
1
,)),
d
istribution_strategy
=
'not'
,
log
=
False
,
nbin
=
None
,
binbounds
=
None
,
dtype
=
np
.
dtype
(
'float'
)):
...
...
@@ -31,7 +31,7 @@ class PowerSpace(Space):
power_index
=
PowerIndexFactory
.
get_power_index
(
domain
=
self
.
harmonic_domain
,
distribution_strategy
=
d
atamodel
,
distribution_strategy
=
d
istribution_strategy
,
log
=
log
,
nbin
=
nbin
,
binbounds
=
binbounds
)
...
...
@@ -71,9 +71,9 @@ class PowerSpace(Space):
return
reduce
(
lambda
x
,
y
:
x
*
y
,
self
.
pindex
.
shape
)
def
copy
(
self
):
d
atamodel
=
self
.
pindex
.
distribution_strategy
d
istribution_strategy
=
self
.
pindex
.
distribution_strategy
return
self
.
__class__
(
harmonic_domain
=
self
.
harmonic_domain
,
d
atamodel
=
datamodel
,
d
istribution_strategy
=
distribution_strategy
,
log
=
self
.
log
,
nbin
=
self
.
nbin
,
binbounds
=
self
.
binbounds
,
...
...
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