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
723089ab
Commit
723089ab
authored
May 04, 2018
by
Martin Reinecke
Browse files
improve checks when drawing from DiagonalOperator
parent
91944cd3
Pipeline
#28885
passed with stages
in 10 minutes and 23 seconds
Changes
3
Pipelines
6
Hide whitespace changes
Inline
Side-by-side
nifty4/data_objects/distributed_do.py
View file @
723089ab
...
@@ -322,6 +322,12 @@ def np_allreduce_sum(arr):
...
@@ -322,6 +322,12 @@ def np_allreduce_sum(arr):
return
res
return
res
def
np_allreduce_min
(
arr
):
res
=
np
.
empty_like
(
arr
)
_comm
.
Allreduce
(
arr
,
res
,
MPI
.
MIN
)
return
res
def
distaxis
(
arr
):
def
distaxis
(
arr
):
return
arr
.
_distaxis
return
arr
.
_distaxis
...
...
nifty4/data_objects/numpy_do.py
View file @
723089ab
...
@@ -70,6 +70,10 @@ def np_allreduce_sum(arr):
...
@@ -70,6 +70,10 @@ def np_allreduce_sum(arr):
return
arr
return
arr
def
np_allreduce_min
(
arr
):
return
arr
def
distaxis
(
arr
):
def
distaxis
(
arr
):
return
-
1
return
-
1
...
...
nifty4/operators/diagonal_operator.py
View file @
723089ab
...
@@ -92,45 +92,46 @@ class DiagonalOperator(EndomorphicOperator):
...
@@ -92,45 +92,46 @@ class DiagonalOperator(EndomorphicOperator):
self
.
_ldiag
=
self
.
_ldiag
.
reshape
(
self
.
_reshaper
)
self
.
_ldiag
=
self
.
_ldiag
.
reshape
(
self
.
_reshaper
)
else
:
else
:
self
.
_ldiag
=
diagonal
.
local_data
self
.
_ldiag
=
diagonal
.
local_data
self
.
_update_diagmin
()
def
_update_diagmin
(
self
):
self
.
_ldiag
.
flags
.
writeable
=
False
self
.
_ldiag
.
flags
.
writeable
=
False
if
not
np
.
issubdtype
(
self
.
_ldiag
.
dtype
,
np
.
complexfloating
):
lmin
=
self
.
_ldiag
.
min
()
if
self
.
_ldiag
.
size
>
0
else
1.
self
.
_diagmin
=
dobj
.
np_allreduce_min
(
np
.
array
(
lmin
))[()]
def
_
skeleton
(
self
,
spc
):
def
_
from_ldiag
(
self
,
spc
,
ldiag
):
res
=
DiagonalOperator
.
__new__
(
DiagonalOperator
)
res
=
DiagonalOperator
.
__new__
(
DiagonalOperator
)
res
.
_domain
=
self
.
_domain
res
.
_domain
=
self
.
_domain
if
self
.
_spaces
is
None
or
spc
is
None
:
if
self
.
_spaces
is
None
or
spc
is
None
:
res
.
_spaces
=
None
res
.
_spaces
=
None
else
:
else
:
res
.
_spaces
=
tuple
(
set
(
self
.
_spaces
)
|
set
(
spc
))
res
.
_spaces
=
tuple
(
set
(
self
.
_spaces
)
|
set
(
spc
))
res
.
_ldiag
=
ldiag
res
.
_update_diagmin
()
return
res
return
res
def
_scale
(
self
,
fct
):
def
_scale
(
self
,
fct
):
if
not
np
.
isscalar
(
fct
):
if
not
np
.
isscalar
(
fct
):
raise
TypeError
(
"scalar value required"
)
raise
TypeError
(
"scalar value required"
)
res
=
self
.
_skeleton
(())
return
self
.
_from_ldiag
((),
self
.
_ldiag
*
fct
)
res
.
_ldiag
=
self
.
_ldiag
*
fct
return
res
def
_add
(
self
,
sum
):
def
_add
(
self
,
sum
):
if
not
np
.
isscalar
(
sum
):
if
not
np
.
isscalar
(
sum
):
raise
TypeError
(
"scalar value required"
)
raise
TypeError
(
"scalar value required"
)
res
=
self
.
_skeleton
(())
return
self
.
_from_ldiag
((),
self
.
_ldiag
+
sum
)
res
.
_ldiag
=
self
.
_ldiag
+
sum
return
res
def
_combine_prod
(
self
,
op
):
def
_combine_prod
(
self
,
op
):
if
not
isinstance
(
op
,
DiagonalOperator
):
if
not
isinstance
(
op
,
DiagonalOperator
):
raise
TypeError
(
"DiagonalOperator required"
)
raise
TypeError
(
"DiagonalOperator required"
)
res
=
self
.
_skeleton
(
op
.
_spaces
)
return
self
.
_from_ldiag
(
op
.
_spaces
,
self
.
_ldiag
*
op
.
_ldiag
)
res
.
_ldiag
=
self
.
_ldiag
*
op
.
_ldiag
return
res
def
_combine_sum
(
self
,
op
,
selfneg
,
opneg
):
def
_combine_sum
(
self
,
op
,
selfneg
,
opneg
):
if
not
isinstance
(
op
,
DiagonalOperator
):
if
not
isinstance
(
op
,
DiagonalOperator
):
raise
TypeError
(
"DiagonalOperator required"
)
raise
TypeError
(
"DiagonalOperator required"
)
res
=
self
.
_skeleton
(
op
.
_spaces
)
tdiag
=
(
self
.
_ldiag
*
(
-
1
if
selfneg
else
1
)
+
res
.
_ldiag
=
(
self
.
_ldiag
*
(
-
1
if
selfneg
else
1
)
+
op
.
_ldiag
*
(
-
1
if
opneg
else
1
))
op
.
_ldiag
*
(
-
1
if
opneg
else
1
))
return
self
.
_from_ldiag
(
op
.
_spaces
,
tdiag
)
return
res
def
apply
(
self
,
x
,
mode
):
def
apply
(
self
,
x
,
mode
):
self
.
_check_input
(
x
,
mode
)
self
.
_check_input
(
x
,
mode
)
...
@@ -166,20 +167,21 @@ class DiagonalOperator(EndomorphicOperator):
...
@@ -166,20 +167,21 @@ class DiagonalOperator(EndomorphicOperator):
return
self
return
self
if
trafo
==
ADJ
and
np
.
issubdtype
(
self
.
_ldiag
.
dtype
,
np
.
floating
):
if
trafo
==
ADJ
and
np
.
issubdtype
(
self
.
_ldiag
.
dtype
,
np
.
floating
):
return
self
return
self
res
=
self
.
_skeleton
(())
if
trafo
==
ADJ
:
if
trafo
==
ADJ
:
re
s
.
_ldiag
=
self
.
_ldiag
.
conjugate
()
re
turn
self
.
_from
_ldiag
((),
self
.
_ldiag
.
conjugate
()
)
elif
trafo
==
INV
:
elif
trafo
==
INV
:
re
s
.
_ldiag
=
1.
/
self
.
_ldiag
re
turn
self
.
_from
_ldiag
((),
1.
/
self
.
_ldiag
)
elif
trafo
==
ADJ
|
INV
:
elif
trafo
==
ADJ
|
INV
:
res
.
_ldiag
=
1.
/
self
.
_ldiag
.
conjugate
()
return
self
.
_from_ldiag
((),
1.
/
self
.
_ldiag
.
conjugate
())
else
:
raise
ValueError
(
"invalid operator transformation"
)
raise
ValueError
(
"invalid operator transformation"
)
return
res
def
draw_sample
(
self
,
from_inverse
=
False
,
dtype
=
np
.
float64
):
def
draw_sample
(
self
,
from_inverse
=
False
,
dtype
=
np
.
float64
):
if
np
.
issubdtype
(
self
.
_ldiag
.
dtype
,
np
.
complexfloating
):
if
np
.
issubdtype
(
self
.
_ldiag
.
dtype
,
np
.
complexfloating
):
raise
ValueError
(
"operator not positive definite"
)
raise
ValueError
(
"operator not positive definite"
)
if
self
.
_diagmin
<
0.
:
raise
ValueError
(
"operator not positive definite"
)
if
self
.
_diagmin
==
0.
and
from_inverse
:
raise
ValueError
(
"operator not positive definite"
)
res
=
Field
.
from_random
(
random_type
=
"normal"
,
domain
=
self
.
_domain
,
res
=
Field
.
from_random
(
random_type
=
"normal"
,
domain
=
self
.
_domain
,
dtype
=
dtype
)
dtype
=
dtype
)
if
from_inverse
:
if
from_inverse
:
...
...
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