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
85db45e4
Commit
85db45e4
authored
May 12, 2018
by
Martin Reinecke
Browse files
make ScalingOperator work on MultiField
parent
e759eb60
Pipeline
#29014
passed with stages
in 3 minutes and 27 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty4/multi/multi_field.py
View file @
85db45e4
...
...
@@ -32,6 +32,13 @@ class MultiField(object):
def
dtype
(
self
):
return
{
key
:
val
.
dtype
for
key
,
val
in
self
.
_val
.
items
()}
@
staticmethod
def
from_random
(
random_type
,
domain
,
dtype
=
np
.
float64
,
**
kwargs
):
dtype
=
self
.
build_dtype
(
dtype
)
return
MultiField
({
key
:
Field
.
from_random
(
random_type
,
domain
[
key
],
dtype
[
key
],
**
kwargs
)
for
key
in
domain
.
keys
})
def
_check_domain
(
self
,
other
):
if
other
.
domain
!=
self
.
domain
:
raise
ValueError
(
"domains are incompatible."
)
...
...
nifty4/operators/scaling_operator.py
View file @
85db45e4
...
...
@@ -19,6 +19,7 @@
from
__future__
import
division
import
numpy
as
np
from
..field
import
Field
from
..multi.multi_field
import
MultiField
from
..domain_tuple
import
DomainTuple
from
.endomorphic_operator
import
EndomorphicOperator
...
...
@@ -61,7 +62,7 @@ class ScalingOperator(EndomorphicOperator):
if
self
.
_factor
==
1.
:
return
x
.
copy
()
if
self
.
_factor
==
0.
:
return
Field
.
zeros_like
(
x
)
return
x
.
zeros_like
(
x
)
if
mode
==
self
.
TIMES
:
return
x
*
self
.
_factor
...
...
@@ -103,5 +104,6 @@ class ScalingOperator(EndomorphicOperator):
if
fct
.
real
==
0.
and
from_inverse
:
raise
ValueError
(
"operator not positive definite"
)
fct
=
1.
/
np
.
sqrt
(
fct
)
if
from_inverse
else
np
.
sqrt
(
fct
)
return
Field
.
from_random
(
cls
=
Field
if
isinstance
(
self
.
_domain
,
DomainTuple
)
else
MultiField
return
cls
.
from_random
(
random_type
=
"normal"
,
domain
=
self
.
_domain
,
std
=
fct
,
dtype
=
dtype
)
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