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
0e8af4d4
Commit
0e8af4d4
authored
Oct 02, 2018
by
Philipp Arras
Browse files
Simplifications SlopeOperator
parent
30f8f70c
Changes
1
Show whitespace changes
Inline
Side-by-side
nifty5/operators/slope_operator.py
View file @
0e8af4d4
...
@@ -46,40 +46,27 @@ class SlopeOperator(LinearOperator):
...
@@ -46,40 +46,27 @@ class SlopeOperator(LinearOperator):
sigmas : np.array, shape=(2,)
sigmas : np.array, shape=(2,)
The slope variance and the y-intercept variance.
The slope variance and the y-intercept variance.
"""
"""
def
__init__
(
self
,
target
):
def
__init__
(
self
,
target
):
if
not
isinstance
(
target
,
LogRGSpace
):
if
not
isinstance
(
target
,
LogRGSpace
):
raise
TypeError
raise
TypeError
if
len
(
target
.
shape
)
!=
1
:
raise
ValueError
(
"Slope Operator only works for ndim == 1"
)
self
.
_domain
=
DomainTuple
.
make
(
UnstructuredDomain
((
2
,)))
self
.
_domain
=
DomainTuple
.
make
(
UnstructuredDomain
((
2
,)))
self
.
_target
=
DomainTuple
.
make
(
target
)
self
.
_target
=
DomainTuple
.
make
(
target
)
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
pos
=
self
.
target
[
0
].
get_k_array
()
-
self
.
target
[
0
].
t_0
[
0
]
self
.
ndim
=
len
(
self
.
target
[
0
].
shape
)
self
.
_pos
=
pos
[
0
,
1
:]
if
self
.
ndim
!=
1
:
raise
ValueError
(
"Slope Operator only works for ndim == 1"
)
# Prepare pos
self
.
pos
=
self
.
target
[
0
].
get_k_array
()
-
self
.
target
[
0
].
t_0
[
0
]
def
apply
(
self
,
x
,
mode
):
def
apply
(
self
,
x
,
mode
):
self
.
_check_input
(
x
,
mode
)
self
.
_check_input
(
x
,
mode
)
# Times
if
mode
==
self
.
TIMES
:
inp
=
x
.
to_global_data
()
inp
=
x
.
to_global_data
()
res
=
inp
[
-
1
]
if
mode
==
self
.
TIMES
:
for
i
in
range
(
self
.
ndim
):
res
=
np
.
empty
(
self
.
target
.
shape
,
dtype
=
x
.
dtype
)
res
=
res
+
inp
[
i
]
*
self
.
pos
[
i
]
res
[
0
]
=
0
res
[
0
]
=
0.
res
[
1
:]
=
inp
[
1
]
+
inp
[
0
]
*
self
.
_pos
return
Field
.
from_global_data
(
self
.
target
,
res
)
else
:
res
=
np
.
array
(
# Adjoint times
[
np
.
sum
(
self
.
_pos
*
inp
[
1
:]),
res
=
np
.
zeros
(
self
.
domain
[
0
].
shape
,
dtype
=
x
.
dtype
)
np
.
sum
(
inp
[
1
:])],
dtype
=
x
.
dtype
)
xglob
=
x
.
to_global_data
()
return
Field
.
from_global_data
(
self
.
_tgt
(
mode
),
res
)
res
[
-
1
]
=
np
.
sum
(
xglob
[
1
:])
for
i
in
range
(
self
.
ndim
):
res
[
i
]
=
np
.
sum
(
self
.
pos
[
i
][
1
:]
*
xglob
[
1
:])
return
Field
.
from_global_data
(
self
.
domain
,
res
)
Write
Preview
Supports
Markdown
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