Skip to content
GitLab
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
d752bd3b
Commit
d752bd3b
authored
Sep 15, 2017
by
Martin Reinecke
Browse files
cleanup
parent
89767b59
Changes
6
Hide whitespace changes
Inline
Side-by-side
nifty2go/field.py
View file @
d752bd3b
...
...
@@ -232,7 +232,7 @@ class Field(object):
raise
ValueError
(
"No space for analysis specified."
)
if
keep_phase_information
:
parts
=
self
.
_hermitian_decomposition
(
self
,
False
)
parts
=
[
self
.
real
.
copy
(),
self
.
imag
.
copy
()]
else
:
parts
=
[
self
]
...
...
@@ -392,23 +392,13 @@ class Field(object):
result_list
[
1
]
*=
spec
.
imag
if
real_signal
:
result_list
=
[
self
.
_hermitian_decomposition
(
i
,
True
)[
0
]
for
i
in
result_list
]
result_list
=
[
i
.
real
*
np
.
sqrt
(
2.
)
for
i
in
result_list
]
if
real_power
:
return
result_list
[
0
]
else
:
return
result_list
[
0
]
+
1j
*
result_list
[
1
]
@
staticmethod
def
_hermitian_decomposition
(
inp
,
preserve_gaussian_variance
=
False
):
if
preserve_gaussian_variance
:
if
not
issubclass
(
inp
.
dtype
.
type
,
np
.
complexfloating
):
raise
TypeError
(
"complex input field is needed here"
)
return
(
inp
.
real
*
np
.
sqrt
(
2.
),
inp
.
imag
*
np
.
sqrt
(
2.
))
else
:
return
(
inp
.
real
.
copy
(),
inp
.
imag
.
copy
())
def
_spec_to_rescaler
(
self
,
spec
,
power_space_index
):
power_space
=
self
.
domain
[
power_space_index
]
...
...
@@ -615,7 +605,7 @@ class Field(object):
return
np
.
sqrt
(
np
.
abs
(
self
.
vdot
(
x
=
self
)))
def
conjugate
(
self
,
inplace
=
False
):
""" Ret
r
uns the complex conjugate of the field.
""" Retu
r
ns the complex conjugate of the field.
Parameters
----------
...
...
nifty2go/nifty_utilities.py
View file @
d752bd3b
...
...
@@ -20,6 +20,7 @@ from builtins import next, range
import
numpy
as
np
from
itertools
import
product
from
functools
import
reduce
from
.domain_object
import
DomainObject
def
get_slice_list
(
shape
,
axes
):
...
...
@@ -94,7 +95,6 @@ def cast_axis_to_tuple(axis, length=None):
def
parse_domain
(
domain
):
from
.domain_object
import
DomainObject
if
domain
is
None
:
return
()
if
isinstance
(
domain
,
DomainObject
):
...
...
nifty2go/operators/composed_operator/composed_operator.py
View file @
d752bd3b
...
...
@@ -64,10 +64,8 @@ class ComposedOperator(LinearOperator):
>>> x2 = RGSpace(10)
>>> k1 = RGRGTransformation.get_codomain(x1)
>>> k2 = RGRGTransformation.get_codomain(x2)
>>> FFT1 = FFTOperator(domain=x1, target=k1,
domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT2 = FFTOperator(domain=x2, target=k2,
domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT1 = FFTOperator(domain=x1, target=k1)
>>> FFT2 = FFTOperator(domain=x2, target=k2)
>>> FFT = ComposedOperator((FFT1, FFT2)
>>> f = Field.from_random('normal', domain=(x1,x2))
>>> FFT.times(f)
...
...
nifty2go/operators/fft_operator/fft_operator_support.py
View file @
d752bd3b
...
...
@@ -132,7 +132,7 @@ class SlicingTransformation(Transformation):
def
buildLm
(
nr
,
lmax
):
new_dtype
=
np
.
result_type
(
nr
.
dtype
,
np
.
complex64
)
new_dtype
=
np
.
result_type
(
nr
[
0
]
*
1j
)
size
=
(
len
(
nr
)
-
lmax
-
1
)
//
2
+
lmax
+
1
res
=
np
.
empty
([
size
],
dtype
=
new_dtype
)
...
...
@@ -142,12 +142,7 @@ def buildLm(nr, lmax):
def
buildIdx
(
nr
,
lmax
):
if
nr
.
dtype
==
np
.
dtype
(
'complex64'
):
new_dtype
=
np
.
float32
elif
nr
.
dtype
==
np
.
dtype
(
'complex128'
):
new_dtype
=
np
.
float64
else
:
raise
TypeError
(
"dtype of nr not supported."
)
new_dtype
=
np
.
result_type
(
nr
[
0
].
real
)
size
=
(
lmax
+
1
)
*
(
lmax
+
1
)
final
=
np
.
empty
(
size
,
dtype
=
new_dtype
)
...
...
nifty2go/operators/linear_operator/linear_operator.py
View file @
d752bd3b
...
...
@@ -287,9 +287,8 @@ class LinearOperator(with_metaclass(
else
:
for
i
,
space_index
in
enumerate
(
spaces
):
if
x
.
domain
[
space_index
]
!=
self_domain
[
i
]:
raise
ValueError
(
"The operator's and and field's domains don't "
"match."
)
raise
ValueError
(
"The operator's and and field's domains "
"don't match."
)
return
spaces
...
...
test/test_field.py
View file @
d752bd3b
...
...
@@ -54,27 +54,6 @@ class Test_Interface(unittest.TestCase):
class
Test_Functionality
(
unittest
.
TestCase
):
@
expand
(
product
([
True
,
False
],
[
True
,
False
],
[(
1
,),
(
4
,),
(
5
,)],
[(
1
,),
(
6
,),
(
7
,)]))
def
test_hermitian_decomposition
(
self
,
preserve
,
complexdata
,
s1
,
s2
):
np
.
random
.
seed
(
123
)
r1
=
RGSpace
(
s1
,
harmonic
=
True
)
r2
=
RGSpace
(
s2
,
harmonic
=
True
)
ra
=
RGSpace
(
s1
+
s2
,
harmonic
=
True
)
if
preserve
:
complexdata
=
True
v
=
np
.
random
.
random
(
s1
+
s2
)
if
complexdata
:
v
=
v
+
1j
*
np
.
random
.
random
(
s1
+
s2
)
f1
=
Field
(
ra
,
val
=
v
,
copy
=
True
)
f2
=
Field
((
r1
,
r2
),
val
=
v
,
copy
=
True
)
h1
,
a1
=
Field
.
_hermitian_decomposition
(
f1
.
val
,
preserve
)
h2
,
a2
=
Field
.
_hermitian_decomposition
(
f2
.
val
,
preserve
)
assert_almost_equal
(
h1
,
h2
)
assert_almost_equal
(
a1
,
a2
)
@
expand
(
product
([
RGSpace
((
8
,),
harmonic
=
True
),
RGSpace
((
8
,
8
),
harmonic
=
True
,
distances
=
0.123
)],
[
RGSpace
((
8
,),
harmonic
=
True
),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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