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
15
Issues
15
List
Boards
Labels
Service Desk
Milestones
Merge Requests
15
Merge Requests
15
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
03f59cc3
Commit
03f59cc3
authored
Aug 20, 2018
by
Philipp Arras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DomainDistributor -> ContractionOperator
parent
63789fe6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
26 deletions
+24
-26
nifty5/__init__.py
nifty5/__init__.py
+1
-1
nifty5/library/correlated_fields.py
nifty5/library/correlated_fields.py
+3
-3
nifty5/operators/contraction_operator.py
nifty5/operators/contraction_operator.py
+18
-20
test/test_operators/test_adjoint.py
test/test_operators/test_adjoint.py
+2
-2
No files found.
nifty5/__init__.py
View file @
03f59cc3
...
...
@@ -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 @
03f59cc3
...
...
@@ -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
=
DomainDistributor
(
pd
.
domain
,
0
)
dom_distr_energy
=
DomainDistributor
(
pd
.
domain
,
1
)
dom_distr_spatial
=
ContractionOperator
(
pd
.
domain
,
0
).
adjoint
dom_distr_energy
=
ContractionOperator
(
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 @
03f59cc3
...
...
@@ -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 @
03f59cc3
...
...
@@ -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
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