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
9628c28d
Commit
9628c28d
authored
Sep 19, 2018
by
Sebastian Hutschenreuter
Browse files
added tests
parent
3c5d3287
Changes
4
Hide whitespace changes
Inline
Side-by-side
nifty5/linearization.py
View file @
9628c28d
...
...
@@ -130,16 +130,14 @@ class Linearization(object):
from
.operators.outer_product_operator
import
OuterProduct
if
isinstance
(
other
,
Linearization
):
return
self
.
new
(
OuterProduct
(
self
.
_val
,
other
.
_val
.
domain
)(
other
.
_val
),
OuterProduct
(
other
.
_val
,
self
.
_jac
.
domain
)(
self
.
_jac
).
_myadd
(
OuterProduct
(
self
.
_val
,
other
.
_jac
.
domain
)(
other
.
_jac
),
False
))
OuterProduct
(
self
.
_val
,
other
.
target
)(
other
.
_val
),
OuterProduct
(
self
.
_jac
(
self
.
_val
),
other
.
target
).
_myadd
(
OuterProduct
(
self
.
_val
,
other
.
target
)(
other
.
_jac
),
False
))
if
np
.
isscalar
(
other
):
return
self
.
__mul__
(
other
)
if
isinstance
(
other
,
(
Field
,
MultiField
)):
return
self
.
new
(
OuterProduct
(
self
.
_val
,
other
.
_val
.
domain
)(
other
.
_val
),
OuterProduct
(
other
.
_val
,
self
.
_jac
.
domain
)(
self
.
_jac
))
return
self
.
new
(
OuterProduct
(
self
.
_val
,
other
.
domain
)(
other
),
OuterProduct
(
self
.
_jac
(
self
.
_val
),
other
.
domain
))
def
vdot
(
self
,
other
):
from
.operators.simple_linear_operators
import
VdotOperator
...
...
test/test_field.py
View file @
9628c28d
...
...
@@ -144,6 +144,26 @@ class Test_Functionality(unittest.TestCase):
res
=
m1
.
outer
(
m2
)
assert_allclose
(
res
.
to_global_data
(),
np
.
full
((
9
,
3
,),
1.5
))
def
test_sum
(
self
):
x1
=
ift
.
RGSpace
((
9
,),
distances
=
2.
)
x2
=
ift
.
RGSpace
((
2
,
12
,),
distances
=
(
0.3
,))
m1
=
ift
.
Field
(
ift
.
makeDomain
(
x1
),
np
.
arange
(
9
))
m2
=
ift
.
Field
.
full
(
ift
.
makeDomain
((
x1
,
x2
)),
0.45
)
res1
=
m1
.
sum
()
res2
=
m2
.
sum
(
spaces
=
1
)
assert_allclose
(
res1
,
36
)
assert_allclose
(
res2
.
to_global_data
(),
np
.
full
(
9
,
2
*
12
*
0.45
))
def
test_integrate
(
self
):
x1
=
ift
.
RGSpace
((
9
,),
distances
=
2.
)
x2
=
ift
.
RGSpace
((
2
,
12
,),
distances
=
(
0.3
,))
m1
=
ift
.
Field
(
ift
.
makeDomain
(
x1
),
np
.
arange
(
9
))
m2
=
ift
.
Field
.
full
(
ift
.
makeDomain
((
x1
,
x2
)),
0.45
)
res1
=
m1
.
integrate
()
res2
=
m2
.
integrate
(
spaces
=
1
)
assert_allclose
(
res1
,
36
*
2
)
assert_allclose
(
res2
.
to_global_data
(),
np
.
full
(
9
,
2
*
12
*
0.45
*
0.3
**
2
))
def
test_dataconv
(
self
):
s1
=
ift
.
RGSpace
((
10
,))
ld
=
np
.
arange
(
ift
.
dobj
.
local_shape
(
s1
.
shape
)[
0
])
...
...
test/test_models/test_model_gradients.py
View file @
9628c28d
...
...
@@ -79,6 +79,9 @@ class Model_Tests(unittest.TestCase):
ift
.
FieldAdapter
(
dom
,
"s1"
)
*
ift
.
FieldAdapter
(
dom
,
"s2"
)))
pos
=
ift
.
from_random
(
"normal"
,
dom
)
ift
.
extra
.
check_value_gradient_consistency
(
model
,
pos
)
pos
=
ift
.
from_random
(
"normal"
,
dom
)
model
=
ift
.
OuterProduct
(
pos
[
's1'
],
ift
.
makeDomain
(
space
))
#(ift.FieldAdapter(dom, "s2"))
ift
.
extra
.
check_value_gradient_consistency
(
model
,
pos
[
's2'
])
if
isinstance
(
space
,
ift
.
RGSpace
):
model
=
ift
.
FFTOperator
(
space
)(
ift
.
FieldAdapter
(
dom
,
"s1"
)
*
ift
.
FieldAdapter
(
dom
,
"s2"
))
...
...
test/test_operators/test_adjoint.py
View file @
9628c28d
...
...
@@ -257,3 +257,15 @@ class Consistency_Tests(unittest.TestCase):
def
testRegridding
(
self
,
domain
,
shape
,
space
):
op
=
ift
.
RegriddingOperator
(
domain
,
shape
,
space
)
ift
.
extra
.
consistency_check
(
op
)
@
expand
(
product
([
ift
.
DomainTuple
.
make
((
ift
.
RGSpace
((
3
,
5
,
4
)),
ift
.
RGSpace
((
16
,),
distances
=
(
7.
,))),),
ift
.
DomainTuple
.
make
(
ift
.
HPSpace
(
12
),)],
[
ift
.
DomainTuple
.
make
((
ift
.
RGSpace
((
2
,)),
ift
.
GLSpace
(
10
)),),
ift
.
DomainTuple
.
make
(
ift
.
RGSpace
((
10
,
12
),
distances
=
(
0.1
,
1.
)),)]
))
def
testOuter
(
self
,
fdomain
,
domain
):
f
=
ift
.
from_random
(
'normal'
,
fdomain
)
op
=
ift
.
OuterProduct
(
f
,
domain
)
ift
.
extra
.
consistency_check
(
op
)
Write
Preview
Markdown
is supported
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