-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomainFlipper.py
26 lines (24 loc) · 998 Bytes
/
domainFlipper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import nifty5 as ift
class DomainFlipper(ift.LinearOperator):
"""
Operator that changes a field's domain to its default codomain
"""
def __init__(self, domain, target=None):
self._domain = ift.DomainTuple.make(domain)
if target is None:
self._target = ift.DomainTuple.make(domain.get_default_codomain())
else:
self._target = ift.DomainTuple.make(target)
self._capability = self._all_ops
return
def apply(self, x, mode):
self._check_input(x, mode)
if mode == self.TIMES:
y = ift.from_global_data(self._target, x.to_global_data())
if mode == self.INVERSE_TIMES:
y = ift.from_global_data(self._domain, x.to_global_data())
if mode == self.ADJOINT_TIMES:
y = ift.from_global_data(self._domain, x.to_global_data())
if mode == self.ADJOINT_INVERSE_TIMES:
y = ift.from_global_data(self._target, x.to_global_data())
return y