Commit dbe056fc authored by Martin Reinecke's avatar Martin Reinecke
Browse files

add Operator.__pow__

parent cb31d136
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import numpy as np
from ..compat import * from ..compat import *
from ..utilities import NiftyMetaBase from ..utilities import NiftyMetaBase
...@@ -56,6 +57,11 @@ class Operator(NiftyMetaBase()): ...@@ -56,6 +57,11 @@ class Operator(NiftyMetaBase()):
return NotImplemented return NotImplemented
return _OpSum(self, x) return _OpSum(self, x)
def __pow__(self, power):
if not np.isscalar(power):
return NotImplemented
return _OpChain.make((_PowerOp(self.target, power), self))
def apply(self, x): def apply(self, x):
raise NotImplementedError raise NotImplementedError
...@@ -97,6 +103,17 @@ class _FunctionApplier(Operator): ...@@ -97,6 +103,17 @@ class _FunctionApplier(Operator):
return getattr(x, self._funcname)() return getattr(x, self._funcname)()
class _PowerOp(Operator):
def __init__(self, domain, power):
from ..sugar import makeDomain
self._domain = self._target = makeDomain(domain)
self._power = power
def apply(self, x):
self._check_input(x)
return x**self._power
class _CombinedOperator(Operator): class _CombinedOperator(Operator):
def __init__(self, ops, _callingfrommake=False): def __init__(self, ops, _callingfrommake=False):
if not _callingfrommake: if not _callingfrommake:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment