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
66fbb7db
Commit
66fbb7db
authored
Aug 25, 2018
by
Martin Reinecke
Browse files
Merge branch 'NIFTy_5' into minimizer_revolution
parents
a39d4d69
4769b6b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
nifty5/__init__.py
View file @
66fbb7db
...
...
@@ -22,7 +22,7 @@ from .operators.operator import Operator
from
.operators.central_zero_padder
import
CentralZeroPadder
from
.operators.diagonal_operator
import
DiagonalOperator
from
.operators.distributors
import
DOFDistributor
,
PowerDistributor
from
.operators.
domain_distributor
import
DomainDistribu
tor
from
.operators.
contraction_operator
import
ContractionOpera
tor
from
.operators.endomorphic_operator
import
EndomorphicOperator
from
.operators.exp_transform
import
ExpTransform
from
.operators.harmonic_operators
import
(
...
...
nifty5/library/correlated_fields.py
View file @
66fbb7db
...
...
@@ -21,8 +21,8 @@ from __future__ import absolute_import, division, print_function
from
..compat
import
*
from
..domain_tuple
import
DomainTuple
from
..multi_domain
import
MultiDomain
from
..operators.contraction_operator
import
ContractionOperator
from
..operators.distributors
import
PowerDistributor
from
..operators.domain_distributor
import
DomainDistributor
from
..operators.harmonic_operators
import
HarmonicTransformOperator
from
..operators.simple_linear_operators
import
FieldAdapter
from
..sugar
import
exp
...
...
@@ -65,8 +65,8 @@ def MfCorrelatedField(s_space_spatial, s_space_energy, amplitude_model_spatial,
pd_energy
=
PowerDistributor
(
pd_spatial
.
domain
,
p_space_energy
,
1
)
pd
=
pd_spatial
(
pd_energy
)
dom_distr_spatial
=
DomainDistribu
tor
(
pd
.
domain
,
0
)
dom_distr_energy
=
DomainDistribu
tor
(
pd
.
domain
,
1
)
dom_distr_spatial
=
ContractionOpera
tor
(
pd
.
domain
,
0
)
.
adjoint
dom_distr_energy
=
ContractionOpera
tor
(
pd
.
domain
,
1
)
.
adjoint
a_spatial
=
dom_distr_spatial
(
amplitude_model_spatial
)
a_energy
=
dom_distr_energy
(
amplitude_model_energy
)
...
...
nifty5/operators/
domain_distribu
tor.py
→
nifty5/operators/
contraction_opera
tor.py
View file @
66fbb7db
...
...
@@ -27,40 +27,38 @@ from ..field import Field
from
.linear_operator
import
LinearOperator
class
DomainDistribu
tor
(
LinearOperator
):
"""A linear operator which
broadcasts a field to a larger domain
.
class
ContractionOpera
tor
(
LinearOperator
):
"""A linear operator which
sums up fields into the direction of subspaces
.
This DomainDistributor broadcasts a field which is defined on a
DomainTuple to a DomainTuple which contains the former as a subset. The
entries of the field are copied such that they are constant in the
direction of the new spaces.
This ContractionOperator sums up a field with is defined on a DomainTuple
to a DomainTuple which contains the former as a subset.
Parameters
----------
target
: Domain, tuple of Domain or DomainTuple
domain
: Domain, tuple of Domain or DomainTuple
spaces : int or tuple of int
The elements of "
target
" which are taken as
domain
.
The elements of "
domain
" which are taken as
target
.
"""
def
__init__
(
self
,
target
,
spaces
):
self
.
_
target
=
DomainTuple
.
make
(
target
)
self
.
_spaces
=
utilities
.
parse_spaces
(
spaces
,
len
(
self
.
_
target
))
self
.
_
domain
=
[
tgt
for
i
,
tgt
in
enumerate
(
self
.
_
target
)
if
i
in
self
.
_spaces
def
__init__
(
self
,
domain
,
spaces
):
self
.
_
domain
=
DomainTuple
.
make
(
domain
)
self
.
_spaces
=
utilities
.
parse_spaces
(
spaces
,
len
(
self
.
_
domain
))
self
.
_
target
=
[
dom
for
i
,
dom
in
enumerate
(
self
.
_
domain
)
if
i
in
self
.
_spaces
]
self
.
_
domain
=
DomainTuple
.
make
(
self
.
_
domain
)
self
.
_
target
=
DomainTuple
.
make
(
self
.
_
target
)
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
def
apply
(
self
,
x
,
mode
):
self
.
_check_input
(
x
,
mode
)
if
mode
==
self
.
TIMES
:
if
mode
==
self
.
ADJOINT_
TIMES
:
ldat
=
x
.
local_data
if
0
in
self
.
_spaces
else
x
.
to_global_data
()
shp
=
[]
for
i
,
tgt
in
enumerate
(
self
.
_
target
):
tmp
=
tgt
.
shape
if
i
>
0
else
tgt
.
local_shape
shp
+=
tmp
if
i
in
self
.
_spaces
else
(
1
,)
*
len
(
tgt
.
shape
)
ldat
=
np
.
broadcast_to
(
ldat
.
reshape
(
shp
),
self
.
_
target
.
local_shape
)
return
Field
.
from_local_data
(
self
.
_
target
,
ldat
)
for
i
,
dom
in
enumerate
(
self
.
_
domain
):
tmp
=
dom
.
shape
if
i
>
0
else
dom
.
local_shape
shp
+=
tmp
if
i
in
self
.
_spaces
else
(
1
,)
*
len
(
dom
.
shape
)
ldat
=
np
.
broadcast_to
(
ldat
.
reshape
(
shp
),
self
.
_
domain
.
local_shape
)
return
Field
.
from_local_data
(
self
.
_
domain
,
ldat
)
else
:
return
x
.
sum
(
[
s
for
s
in
range
(
len
(
x
.
domain
))
if
s
not
in
self
.
_spaces
])
test/test_operators/test_adjoint.py
View file @
66fbb7db
...
...
@@ -188,10 +188,10 @@ class Consistency_Tests(unittest.TestCase):
@
expand
(
product
([
0
,
1
,
2
,
3
,
(
0
,
1
),
(
0
,
2
),
(
0
,
1
,
2
),
(
0
,
2
,
3
),
(
1
,
3
)],
[
np
.
float64
,
np
.
complex128
]))
def
test
DomainDistribu
tor
(
self
,
spaces
,
dtype
):
def
test
ContractionOpera
tor
(
self
,
spaces
,
dtype
):
dom
=
(
ift
.
RGSpace
(
10
),
ift
.
UnstructuredDomain
(
13
),
ift
.
GLSpace
(
5
),
ift
.
HPSpace
(
4
))
op
=
ift
.
DomainDistribu
tor
(
dom
,
spaces
)
op
=
ift
.
ContractionOpera
tor
(
dom
,
spaces
)
ift
.
extra
.
consistency_check
(
op
,
dtype
,
dtype
)
@
expand
(
product
([
0
,
2
],
[
np
.
float64
,
np
.
complex128
]))
...
...
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