-
Notifications
You must be signed in to change notification settings - Fork 107
WIP real-valued functional #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d4e5498
7a278f0
09b1e94
89652b1
69521ba
85650f7
7382635
246a31b
5a55e75
d1c4d68
9003572
77842df
c7a6127
3fa93d9
0951041
0ddd06c
cb6df08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1076,7 +1076,6 @@ class OperatorSum(Operator): | |
|
||
The sum is only well-defined for `Operator` instances where | ||
`Operator.range` is a `LinearSpace`. | ||
|
||
""" | ||
|
||
def __init__(self, left, right, tmp_ran=None, tmp_dom=None): | ||
|
@@ -1111,8 +1110,14 @@ def __init__(self, left, right, tmp_ran=None, tmp_dom=None): | |
rn(3).element([ 2., 4., 6.]) | ||
""" | ||
if left.range != right.range: | ||
raise OpTypeError('operator ranges {!r} and {!r} do not match' | ||
''.format(left.range, right.range)) | ||
if (isinstance(left.range, Field) and | ||
isinstance(right.range, Field)): | ||
range = left.range + right.range | ||
else: | ||
raise OpTypeError('operator ranges {!r} and {!r} do not match' | ||
''.format(left.range, right.range)) | ||
else: | ||
range = left.range | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'd prefer not to have any clever mechanism for "fixing" cases that "obviously" should work, like L1Norm(cn(2), range=ComplexNumbers()) + L1Norm(cn(2), range=RealNumbers()) IMO this should fail, and users should explicitly have to use |
||
if not isinstance(left.range, (LinearSpace, Field)): | ||
raise OpTypeError('`left.range` {!r} not a `LinearSpace` or ' | ||
'`Field` instance'.format(left.range)) | ||
|
@@ -1129,7 +1134,7 @@ def __init__(self, left, right, tmp_ran=None, tmp_dom=None): | |
''.format(tmp_dom, left.domain)) | ||
|
||
super(OperatorSum, self).__init__( | ||
left.domain, left.range, | ||
left.domain, range, | ||
linear=left.is_linear and right.is_linear) | ||
self.__left = left | ||
self.__right = right | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,10 +428,10 @@ def __hash__(self): | |
|
||
def element(self, inp=None): | ||
"""Return a real number from ``inp`` or from scratch.""" | ||
if inp is not None: | ||
return float(inp) | ||
else: | ||
if inp is None: | ||
return 0.0 | ||
else: | ||
return float(getattr(inp, 'real', inp)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides the implementation, I'm wondering if we really want this implicit conversion. I'd actually prefer to let this fail for objects that don't implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just needed something to convert the complex numbers to real ones. You could instead have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, my point was that IMO this shouldn't happen in the first place. If you call To me the better approach would be to make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this last case, should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd take Python (and NumPy) as a guide here: >>> x = 1.0
>>> x.imag
0.0
>>> x = np.array(1.0)
>>> x.imag
array(0.)
>>> float(1 + 1j)
...
TypeError: can't convert complex to float
>>> np.array(1 + 1j, dtype=float)
...
TypeError: can't convert complex to float There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some quick trials gives:
Hence, |
||
|
||
@property | ||
def examples(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that wasn't meant to be pushed... I used it for a mapping-oparator from R2 to C...