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
c9e87ba7
Commit
c9e87ba7
authored
Jul 25, 2018
by
Martin Reinecke
Browse files
more
parent
0f2f262e
Changes
6
Hide whitespace changes
Inline
Side-by-side
nifty5/field.py
View file @
c9e87ba7
...
...
@@ -630,7 +630,6 @@ for op in ["__add__", "__radd__",
tval
=
getattr
(
self
.
_val
,
op
)(
other
)
return
Field
(
self
.
_domain
,
tval
)
raise
TypeError
(
"should not arrive here"
)
return
NotImplemented
return
func2
setattr
(
Field
,
op
,
func
(
op
))
...
...
nifty5/multi/multi_field.py
View file @
c9e87ba7
...
...
@@ -229,6 +229,7 @@ class MultiField(object):
res
[
key
]
=
f
[
key
]
return
MultiField
.
from_dict
(
res
)
for
op
in
[
"__add__"
,
"__radd__"
,
"__sub__"
,
"__rsub__"
,
"__mul__"
,
"__rmul__"
,
...
...
nifty5/operator.py
View file @
c9e87ba7
...
...
@@ -6,8 +6,6 @@ import numpy as np
from
.compat
import
*
from
.utilities
import
NiftyMetaBase
#from ..domain_tuple import DomainTuple
#from ..multi.multi_domain import MultiDomain
from
.field
import
Field
from
.multi.multi_field
import
MultiField
...
...
@@ -62,8 +60,8 @@ class Linearization(object):
return
Linearization
(
self
.
_val
*
other
.
_val
,
self
.
_jac
*
d2
+
d1
*
other
.
_jac
)
if
isinstance
(
other
,
(
int
,
float
,
complex
)):
#if other == 0:
# return ...
#
if other == 0:
#
return ...
return
Linearization
(
self
.
_val
*
other
,
self
.
_jac
*
other
)
if
isinstance
(
other
,
(
Field
,
MultiField
)):
d2
=
makeOp
(
other
)
...
...
@@ -82,11 +80,13 @@ class Linearization(object):
def
make_var
(
field
):
from
.operators.scaling_operator
import
ScalingOperator
return
Linearization
(
field
,
ScalingOperator
(
1.
,
field
.
domain
))
@
staticmethod
def
make_const
(
field
):
from
.operators.null_operator
import
NullOperator
return
Linearization
(
field
,
NullOperator
({},
field
.
domain
))
class
Operator
(
NiftyMetaBase
()):
"""Transforms values living on one domain into values living on another
domain, and can also provide the Jacobian.
...
...
nifty5/operators/field_adapter.py
View file @
c9e87ba7
...
...
@@ -5,6 +5,7 @@ from .linear_operator import LinearOperator
from
..multi.multi_domain
import
MultiDomain
from
..multi.multi_field
import
MultiField
class
FieldAdapter
(
LinearOperator
):
def
__init__
(
self
,
op
,
name_dom
,
name_tgt
):
if
name_dom
is
None
:
...
...
nifty5/operators/relaxed_sum_operator.py
View file @
c9e87ba7
...
...
@@ -23,17 +23,19 @@ import numpy as np
from
..compat
import
*
from
..utilities
import
my_sum
from
.linear_operator
import
LinearOperator
from
..sugar
import
domain_union
from
..multi.multi_domain
import
MultiDomain
from
..multi.multi_field
import
MultiField
class
RelaxedSumOperator
(
LinearOperator
):
"""Class representing sums of operators with compatible
MultiD
omains."""
"""Class representing sums of operators with compatible
d
omains."""
def
__init__
(
self
,
ops
):
super
(
RelaxedSumOperator
,
self
).
__init__
()
self
.
_ops
=
ops
self
.
_domain
=
MultiD
omain
.
union
([
op
.
domain
for
op
in
ops
])
self
.
_target
=
MultiD
omain
.
union
([
op
.
target
for
op
in
ops
])
self
.
_domain
=
d
omain
_
union
([
op
.
domain
for
op
in
ops
])
self
.
_target
=
d
omain
_
union
([
op
.
target
for
op
in
ops
])
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
for
op
in
ops
:
self
.
_capability
&=
op
.
capability
...
...
@@ -58,9 +60,14 @@ class RelaxedSumOperator(LinearOperator):
self
.
_check_mode
(
mode
)
res
=
None
for
op
in
self
.
_ops
:
tmp
=
x
.
extract
(
op
.
_dom
(
mode
),
mode
)
if
isinstance
(
x
.
domain
,
MultiDomain
):
x
=
x
.
extract
(
op
.
_dom
(
mode
))
x
=
op
.
apply
(
x
,
mode
)
if
res
is
None
:
res
=
tmp
else
:
res
=
MultiField
.
combine
([
res
,
tmp
])
if
isinstance
(
x
.
domain
,
MultiDomain
):
res
=
MultiField
.
combine
([
res
,
tmp
])
else
:
res
=
res
+
tmp
return
res
nifty5/sugar.py
View file @
c9e87ba7
...
...
@@ -38,7 +38,7 @@ __all__ = ['PS_field', 'power_analyze', 'create_power_operator',
'create_harmonic_smoothing_operator'
,
'from_random'
,
'full'
,
'from_global_data'
,
'from_local_data'
,
'makeDomain'
,
'sqrt'
,
'exp'
,
'log'
,
'tanh'
,
'conjugate'
,
'get_signal_variance'
,
'makeOp'
]
'get_signal_variance'
,
'makeOp'
,
'domain_union'
]
def
PS_field
(
pspace
,
func
):
...
...
@@ -242,6 +242,14 @@ def makeOp(input):
input
.
domain
,
tuple
(
makeOp
(
val
)
for
val
in
input
.
values
()))
raise
NotImplementedError
def
domain_union
(
domains
):
if
isinstance
(
domains
[
0
],
DomainTuple
):
if
any
(
dom
is
not
domains
[
0
]
for
dom
in
domains
[
1
:]):
raise
ValueError
(
"domain mismatch"
)
return
domains
[
0
]
return
MultiDomain
.
union
(
domains
)
# Arithmetic functions working on Fields
...
...
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