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
722948ed
Commit
722948ed
authored
May 13, 2017
by
Theo Steininger
Browse files
Merge branch 'Tests_Operators' into 'master'
Tests operators See merge request
!99
parents
39745ed5
5b674528
Pipeline
#12391
passed with stages
in 12 minutes and 14 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/operators/diagonal_operator/diagonal_operator.py
View file @
722948ed
...
...
@@ -157,7 +157,7 @@ class DiagonalOperator(EndomorphicOperator):
out : Field
The inverse of the diagonal of the Operator.
"""
"""
return
1.
/
self
.
diagonal
(
bare
=
bare
,
copy
=
False
)
def
trace
(
self
,
bare
=
False
):
...
...
@@ -209,6 +209,7 @@ class DiagonalOperator(EndomorphicOperator):
Returns
-------
out : scalar
out : scalar
the determinant of the Operator
...
...
nifty/operators/linear_operator/linear_operator.py
View file @
722948ed
...
...
@@ -211,8 +211,6 @@ class LinearOperator(Loggable, object):
raise
return
y
# If the operator supports inverse() then the inverse adjoint is identical
# to the adjoint inverse. We provide both names for convenience.
def
adjoint_inverse_times
(
self
,
x
,
spaces
=
None
):
""" Applies the adjoint-inverse Operator to a given Field.
...
...
@@ -230,9 +228,15 @@ class LinearOperator(Loggable, object):
out : Field
The processed Field living on the target-domain.
Notes
-----
If the operator has an `inverse` then the inverse adjoint is identical
to the adjoint inverse. We provide both names for convenience.
See Also
--------
"""
if
self
.
unitary
:
return
self
.
times
(
x
,
spaces
)
spaces
=
self
.
_check_input_compatibility
(
x
,
spaces
)
...
...
@@ -246,28 +250,6 @@ class LinearOperator(Loggable, object):
return
y
def
inverse_adjoint_times
(
self
,
x
,
spaces
=
None
):
""" Applies the inverse-adjoint Operator to a given Field.
If the operator supports inverse() then the inverse-adjoint is
identical to the adjoint-inverse. Both names are provided for
convenience.
Operator and Field have to live over the same domain.
Parameters
----------
x : Field
applies the Operator to the given Field
spaces : tuple of ints
defines on which space of the given Field the Operator acts
Returns
-------
out : Field
The processed Field living on the target-domain.
"""
return
self
.
adjoint_inverse_times
(
x
,
spaces
)
def
_times
(
self
,
x
,
spaces
):
...
...
nifty/spaces/rg_space/rg_space.py
View file @
722948ed
...
...
@@ -53,19 +53,19 @@ class RGSpace(Space):
shape : {int, numpy.ndarray}
Number of grid points or numbers of gridpoints along each axis.
zerocenter : {bool, numpy.ndarray}, *optional*
Whether x==0 (or k==0, respectively) is located in the center of
the grid (or the center of each axis speparately) or not.
(default: False).
Whether x==0 (or k==0, respectively) is located in the center of
the grid (or the center of each axis speparately) or not.
(default: False).
distances : {float, numpy.ndarray}, *optional*
Distance between two grid points along each axis
(default: None).
If distances==None:
if harmonic==True, all distances will be set to 1
if harmonic==False, the distance along each axis will be
set to the inverse of the number of points along that
axis.
set to the inverse of the number of points along that
axis.
harmonic : bool, *optional*
Whether the space represents a grid in position or harmonic space.
Whether the space represents a grid in position or harmonic space.
(default: False).
Attributes
...
...
@@ -92,15 +92,6 @@ class RGSpace(Space):
def
__init__
(
self
,
shape
,
zerocenter
=
False
,
distances
=
None
,
harmonic
=
False
):
"""
Sets the attributes for an RGSpace class instance.
Returns
-------
None
"""
self
.
_harmonic
=
bool
(
harmonic
)
super
(
RGSpace
,
self
).
__init__
()
...
...
@@ -227,7 +218,8 @@ class RGSpace(Space):
Returns
-------
distributed_data_object
A d2o containing the distances
A d2o containing the distances.
"""
shape
=
self
.
shape
...
...
test/test_operators/test_diagonal_operator.py
0 → 100644
View file @
722948ed
import
unittest
import
numpy
as
np
from
numpy.testing
import
assert_equal
,
\
assert_allclose
,
\
assert_approx_equal
from
nifty
import
Field
,
\
DiagonalOperator
from
test.common
import
generate_spaces
from
itertools
import
product
from
test.common
import
expand
class
DiagonalOperator_Tests
(
unittest
.
TestCase
):
spaces
=
generate_spaces
()
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_property
(
self
,
space
,
bare
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
)
if
D
.
domain
[
0
]
!=
space
:
raise
TypeError
if
D
.
unitary
!=
False
:
raise
TypeError
if
D
.
self_adjoint
!=
True
:
raise
TypeError
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_times_adjoint
(
self
,
space
,
bare
,
copy
):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt1
=
rand1
.
dot
(
D
.
times
(
rand2
))
tt2
=
rand2
.
dot
(
D
.
times
(
rand1
))
assert_approx_equal
(
tt1
,
tt2
)
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_times_inverse
(
self
,
space
,
bare
,
copy
):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt1
=
D
.
times
(
D
.
inverse_times
(
rand1
))
assert_allclose
(
rand1
.
val
.
get_full_data
(),
tt1
.
val
.
get_full_data
())
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_times
(
self
,
space
,
bare
,
copy
):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt
=
D
.
times
(
rand1
)
assert_equal
(
tt
.
domain
[
0
],
space
)
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_adjoint_times
(
self
,
space
,
bare
,
copy
):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt
=
D
.
adjoint_times
(
rand1
)
assert_equal
(
tt
.
domain
[
0
],
space
)
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_inverse_times
(
self
,
space
,
bare
,
copy
):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt
=
D
.
inverse_times
(
rand1
)
assert_equal
(
tt
.
domain
[
0
],
space
)
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_adjoint_inverse_times
(
self
,
space
,
bare
,
copy
):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt
=
D
.
adjoint_inverse_times
(
rand1
)
assert_equal
(
tt
.
domain
[
0
],
space
)
@
expand
(
product
(
spaces
,
[
True
,
False
]))
def
test_diagonal
(
self
,
space
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
copy
=
copy
)
diag_op
=
D
.
diagonal
()
assert_allclose
(
diag
.
val
.
get_full_data
(),
diag_op
.
val
.
get_full_data
())
@
expand
(
product
(
spaces
,
[
True
,
False
]))
def
test_inverse
(
self
,
space
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
copy
=
copy
)
diag_op
=
D
.
inverse_diagonal
()
assert_allclose
(
1.
/
diag
.
val
.
get_full_data
(),
diag_op
.
val
.
get_full_data
())
@
expand
(
product
(
spaces
,
[
True
,
False
]))
def
test_trace
(
self
,
space
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
copy
=
copy
)
trace_op
=
D
.
trace
()
assert_allclose
(
trace_op
,
np
.
sum
(
diag
.
val
.
get_full_data
()))
@
expand
(
product
(
spaces
,
[
True
,
False
]))
def
test_inverse_trace
(
self
,
space
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
copy
=
copy
)
trace_op
=
D
.
inverse_trace
()
assert_allclose
(
trace_op
,
np
.
sum
(
1.
/
diag
.
val
.
get_full_data
()))
@
expand
(
product
(
spaces
,
[
True
,
False
]))
def
test_trace_log
(
self
,
space
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
copy
=
copy
)
trace_log
=
D
.
trace_log
()
assert_allclose
(
trace_log
,
np
.
sum
(
np
.
log
(
diag
.
val
.
get_full_data
())))
@
expand
(
product
(
spaces
,
[
True
,
False
]))
def
test_determinant
(
self
,
space
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
copy
=
copy
)
det
=
D
.
determinant
()
assert_allclose
(
det
,
np
.
prod
(
diag
.
val
.
get_full_data
()))
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_inverse_determinant
(
self
,
space
,
bare
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
inv_det
=
D
.
inverse_determinant
()
assert_allclose
(
inv_det
,
1.
/
D
.
determinant
())
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
def
test_log_determinant
(
self
,
space
,
bare
,
copy
):
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
log_det
=
D
.
log_determinant
()
assert_allclose
(
log_det
,
np
.
log
(
D
.
determinant
()))
\ No newline at end of file
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