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
Neel Shah
NIFTy
Commits
b746da72
Commit
b746da72
authored
May 20, 2019
by
Martin Reinecke
Browse files
cosmetics
parent
4f6b914c
Changes
7
Hide whitespace changes
Inline
Side-by-side
nifty5/extra.py
View file @
b746da72
...
...
@@ -72,7 +72,7 @@ def _full_implementation(op, domain_dtype, target_dtype, atol, rtol,
def
_check_linearity
(
op
,
domain_dtype
,
atol
,
rtol
):
fld1
=
from_random
(
"normal"
,
op
.
domain
,
dtype
=
domain_dtype
)
fld2
=
from_random
(
"normal"
,
op
.
domain
,
dtype
=
domain_dtype
)
alpha
=
np
.
random
.
random
()
# FIXME: this can break badly with MPI!
alpha
=
np
.
random
.
random
()
# FIXME: this can break badly with MPI!
val1
=
op
(
alpha
*
fld1
+
fld2
)
val2
=
alpha
*
op
(
fld1
)
+
op
(
fld2
)
_assert_allclose
(
val1
,
val2
,
atol
=
atol
,
rtol
=
rtol
)
...
...
@@ -81,8 +81,9 @@ def _check_linearity(op, domain_dtype, atol, rtol):
def
_domain_check
(
op
):
for
dd
in
[
op
.
domain
,
op
.
target
]:
if
not
isinstance
(
dd
,
(
DomainTuple
,
MultiDomain
)):
raise
TypeError
(
'The domain and the target of an operator need to'
,
'be instances of either DomainTuple or MultiDomain.'
)
raise
TypeError
(
'The domain and the target of an operator need to'
,
'be instances of either DomainTuple or MultiDomain.'
)
def
consistency_check
(
op
,
domain_dtype
=
np
.
float64
,
target_dtype
=
np
.
float64
,
...
...
nifty5/operators/diagonal_operator.py
View file @
b746da72
...
...
@@ -158,7 +158,7 @@ class DiagonalOperator(EndomorphicOperator):
def
process_sample
(
self
,
samp
,
from_inverse
):
if
(
self
.
_complex
or
(
self
.
_diagmin
<
0.
)
or
(
self
.
_diagmin
==
0.
and
from_inverse
)):
raise
ValueError
(
"operator not positive definite"
)
raise
ValueError
(
"operator not positive definite"
)
if
from_inverse
:
res
=
samp
.
local_data
/
np
.
sqrt
(
self
.
_ldiag
)
else
:
...
...
nifty5/operators/scaling_operator.py
View file @
b746da72
...
...
@@ -87,7 +87,7 @@ class ScalingOperator(EndomorphicOperator):
fct
=
self
.
_factor
if
(
fct
.
imag
!=
0.
or
fct
.
real
<
0.
or
(
fct
.
real
==
0.
and
from_inverse
)):
raise
ValueError
(
"operator not positive definite"
)
raise
ValueError
(
"operator not positive definite"
)
return
1.
/
np
.
sqrt
(
fct
)
if
from_inverse
else
np
.
sqrt
(
fct
)
# def process_sample(self, samp, from_inverse):
...
...
nifty5/plot.py
View file @
b746da72
...
...
@@ -423,7 +423,7 @@ def _plot(f, ax, **kwargs):
if
len
(
f
)
==
0
:
raise
ValueError
(
"need something to plot"
)
if
not
isinstance
(
f
[
0
],
Field
):
raise
TypeError
(
"incorrect data type"
)
raise
TypeError
(
"incorrect data type"
)
dom1
=
f
[
0
].
domain
if
(
len
(
dom1
)
==
1
and
(
isinstance
(
dom1
[
0
],
PowerSpace
)
or
...
...
test/test_operators/test_adjoint.py
View file @
b746da72
...
...
@@ -39,6 +39,7 @@ dtype = list2fixture([np.float64, np.complex128])
np
.
random
.
seed
(
42
)
@
pmp
(
'sp'
,
_p_RG_spaces
)
def
testLOSResponse
(
sp
,
dtype
):
starts
=
np
.
random
.
randn
(
len
(
sp
.
shape
),
10
)
...
...
@@ -76,14 +77,14 @@ def testLinearInterpolator():
def
testRealizer
(
sp
):
op
=
ift
.
Realizer
(
sp
)
ift
.
extra
.
consistency_check
(
op
,
np
.
complex128
,
np
.
float64
,
only_r_linear
=
True
)
only_r_linear
=
True
)
@
pmp
(
'sp'
,
_h_spaces
+
_p_spaces
+
_pow_spaces
)
def
testConjugationOperator
(
sp
):
op
=
ift
.
ConjugationOperator
(
sp
)
ift
.
extra
.
consistency_check
(
op
,
np
.
complex128
,
np
.
complex128
,
only_r_linear
=
True
)
only_r_linear
=
True
)
@
pmp
(
'args'
,
[(
ift
.
RGSpace
(
10
,
harmonic
=
True
),
4
,
0
),
(
ift
.
RGSpace
(
...
...
test/test_operators/test_nft.py
View file @
b746da72
...
...
@@ -17,7 +17,7 @@
import
numpy
as
np
import
pytest
from
numpy.testing
import
assert_allclose
from
numpy.testing
import
assert_allclose
,
assert_
import
nifty5
as
ift
...
...
@@ -26,11 +26,11 @@ np.random.seed(40)
pmp
=
pytest
.
mark
.
parametrize
def
_l2error
(
a
,
b
):
def
_l2error
(
a
,
b
):
return
np
.
sqrt
(
np
.
sum
(
np
.
abs
(
a
-
b
)
**
2
)
/
np
.
sum
(
np
.
abs
(
a
)
**
2
))
@
pmp
(
'eps'
,
[
1e-2
,
1e-4
,
1e-7
,
1e-10
,
1e-11
,
1e-12
,
2e-13
])
@
pmp
(
'eps'
,
[
1e-2
,
1e-4
,
1e-7
,
1e-10
,
1e-11
,
1e-12
,
2e-13
])
@
pmp
(
'nu'
,
[
12
,
128
])
@
pmp
(
'nv'
,
[
4
,
12
,
128
])
@
pmp
(
'N'
,
[
1
,
10
,
100
])
...
...
@@ -39,7 +39,7 @@ def test_gridding(nu, nv, N, eps):
vis
=
np
.
random
.
randn
(
N
)
+
1j
*
np
.
random
.
randn
(
N
)
# Nifty
GM
=
ift
.
GridderMaker
(
ift
.
RGSpace
((
nu
,
nv
)),
eps
=
eps
)
GM
=
ift
.
GridderMaker
(
ift
.
RGSpace
((
nu
,
nv
)),
eps
=
eps
)
# re-order for performance
idx
=
GM
.
getReordering
(
uv
)
uv
,
vis
=
uv
[
idx
],
vis
[
idx
]
...
...
@@ -53,7 +53,7 @@ def test_gridding(nu, nv, N, eps):
dft
=
pynu
*
0.
for
i
in
range
(
N
):
dft
+=
(
vis
[
i
]
*
np
.
exp
(
2j
*
np
.
pi
*
(
x
*
uv
[
i
,
0
]
+
y
*
uv
[
i
,
1
]))).
real
assert
(
_l2error
(
dft
,
pynu
)
<
eps
)
assert
_
(
_l2error
(
dft
,
pynu
)
<
eps
)
@
pmp
(
'eps'
,
[
1e-2
,
1e-6
,
2e-13
])
...
...
test/test_operators/test_simplification.py
View file @
b746da72
...
...
@@ -23,23 +23,23 @@ import nifty5 as ift
def
test_simplification
():
from
nifty5.operators.operator
import
_ConstantOperator
f1
=
ift
.
Field
.
full
(
ift
.
RGSpace
(
10
),
2.
)
f1
=
ift
.
Field
.
full
(
ift
.
RGSpace
(
10
),
2.
)
op
=
ift
.
FFTOperator
(
f1
.
domain
)
_
,
op2
=
op
.
simplify_for_constant_input
(
f1
)
assert_equal
(
isinstance
(
op2
,
_ConstantOperator
),
True
)
assert_allclose
(
op
(
f1
).
local_data
,
op2
(
f1
).
local_data
)
dom
=
{
"a"
:
ift
.
RGSpace
(
10
)}
f1
=
ift
.
full
(
dom
,
2.
)
f1
=
ift
.
full
(
dom
,
2.
)
op
=
ift
.
FFTOperator
(
f1
.
domain
[
"a"
]).
ducktape
(
"a"
)
_
,
op2
=
op
.
simplify_for_constant_input
(
f1
)
assert_equal
(
isinstance
(
op2
,
_ConstantOperator
),
True
)
assert_allclose
(
op
(
f1
).
local_data
,
op2
(
f1
).
local_data
)
dom
=
{
"a"
:
ift
.
RGSpace
(
10
),
"b"
:
ift
.
RGSpace
(
5
)}
f1
=
ift
.
full
(
dom
,
2.
)
f1
=
ift
.
full
(
dom
,
2.
)
pdom
=
{
"a"
:
ift
.
RGSpace
(
10
)}
f2
=
ift
.
full
(
pdom
,
2.
)
f2
=
ift
.
full
(
pdom
,
2.
)
o1
=
ift
.
FFTOperator
(
f1
.
domain
[
"a"
])
o2
=
ift
.
FFTOperator
(
f1
.
domain
[
"b"
])
op
=
(
o1
.
ducktape
(
"a"
).
ducktape_left
(
"a"
)
+
...
...
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