Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
eb6465ad
Commit
eb6465ad
authored
Sep 04, 2018
by
Martin Reinecke
Browse files
experimental union method for MultiFields
parent
4cb24a5d
Changes
1
Show whitespace changes
Inline
Side-by-side
nifty5/multi_field.py
View file @
eb6465ad
...
@@ -222,6 +222,35 @@ class MultiField(object):
...
@@ -222,6 +222,35 @@ class MultiField(object):
res
[
key
]
=
res
[
key
]
+
val
if
key
in
res
else
val
res
[
key
]
=
res
[
key
]
+
val
if
key
in
res
else
val
return
MultiField
.
from_dict
(
res
)
return
MultiField
.
from_dict
(
res
)
@
staticmethod
def
union
(
fields
,
domain
=
None
):
"""Returns the union of its input fields
Parameters
----------
fields: iterable of MultiFields
The set of input fields. Their domains need not be identical,
but they must not be incompatible, e.g. by having different
DomainTuples for the same key.
domain: MultiDomain or None
If supplied, this mjst be the domain of the resulting field.
Providing this domain will accelerate the function.
Returns
-------
MultiField
The union of the input fields
Notes
-----
If the same key occurs more than once in the input fields, the value
associated with the last occurrence will be put into the output.
No summation is performed!
"""
res
=
{}
for
field
in
fields
:
res
.
update
(
field
.
to_dict
())
return
MultiField
.
from_dict
(
res
,
domain
)
def
flexible_addsub
(
self
,
other
,
neg
):
def
flexible_addsub
(
self
,
other
,
neg
):
if
self
.
_domain
is
other
.
_domain
:
if
self
.
_domain
is
other
.
_domain
:
return
self
-
other
if
neg
else
self
+
other
return
self
-
other
if
neg
else
self
+
other
...
...
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