Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neel Shah
NIFTy
Commits
abbf03ba
Commit
abbf03ba
authored
Oct 05, 2017
by
Martin Reinecke
Browse files
introduce 'out' argument in basic_arithmetics; other small fixes
parent
8d177bd0
Changes
3
Hide whitespace changes
Inline
Side-by-side
nifty/basic_arithmetics.py
View file @
abbf03ba
...
...
@@ -27,81 +27,92 @@ __all__ = ['cos', 'sin', 'cosh', 'sinh', 'tan', 'tanh', 'arccos', 'arcsin',
'conjugate'
,
'clipped_exp'
,
'limited_exp'
,
'limited_exp_deriv'
]
def
_math_helper
(
x
,
function
):
if
isinstance
(
x
,
Field
):
result_val
=
x
.
val
.
apply_scalar_function
(
function
)
result
=
x
.
copy_empty
(
dtype
=
result_val
.
dtype
)
result
.
val
=
result_val
elif
isinstance
(
x
,
distributed_data_object
):
result
=
x
.
apply_scalar_function
(
function
,
inplace
=
False
)
def
_math_helper
(
x
,
function
,
out
):
if
not
isinstance
(
x
,
Field
):
raise
TypeError
(
"This function only accepts Field objects."
)
if
out
is
not
None
:
if
not
isinstance
(
out
,
Field
)
or
x
.
domain
!=
out
.
domain
:
raise
ValueError
(
"Bad 'out' argument"
)
function
(
x
.
val
,
out
=
out
.
val
)
return
out
else
:
re
sult
=
function
(
np
.
asarray
(
x
))
re
turn
Field
(
domain
=
x
.
domain
,
val
=
function
(
x
.
val
))
return
result
def
cos
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
cos
,
out
)
def
sin
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sin
,
out
)
def
cos
(
x
):
return
_math_helper
(
x
,
np
.
cos
)
def
cos
h
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
cos
h
,
out
)
def
sin
(
x
):
return
_math_helper
(
x
,
np
.
sin
)
def
sin
h
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sin
h
,
out
)
def
cosh
(
x
):
return
_math_helper
(
x
,
np
.
cosh
)
def
tan
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
tan
,
out
)
def
si
nh
(
x
):
return
_math_helper
(
x
,
np
.
sinh
)
def
ta
nh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
tanh
,
out
)
def
tan
(
x
):
return
_math_helper
(
x
,
np
.
tan
)
def
arccos
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arccos
,
out
)
def
tanh
(
x
):
return
_math_helper
(
x
,
np
.
tanh
)
def
arcsin
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arcsin
,
out
)
def
arccos
(
x
):
return
_math_helper
(
x
,
np
.
arccos
)
def
arccos
h
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arccos
h
,
out
)
def
arcsin
(
x
):
return
_math_helper
(
x
,
np
.
arcsin
)
def
arcsin
h
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arcsin
h
,
out
)
def
arc
cosh
(
x
):
return
_math_helper
(
x
,
np
.
arc
cosh
)
def
arc
tan
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arc
tan
,
out
)
def
arc
si
nh
(
x
):
return
_math_helper
(
x
,
np
.
arc
sinh
)
def
arc
ta
nh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arc
tanh
,
out
)
def
arctan
(
x
):
return
_math_helper
(
x
,
np
.
arctan
)
def
sqrt
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sqrt
,
out
)
def
arctanh
(
x
):
return
_math_helper
(
x
,
np
.
arctanh
)
def
exp
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
exp
,
out
)
def
sqrt
(
x
):
return
_math_helper
(
x
,
np
.
sqr
t
)
def
log
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
log
,
ou
t
)
def
exp
(
x
):
return
_math_helper
(
x
,
np
.
exp
)
def
conjugate
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
conjugate
,
out
)
def
c
lipped_exp
(
x
):
return
_math_helper
(
x
,
lambda
z
:
np
.
exp
(
np
.
minimum
(
200
,
z
))
)
def
c
onj
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
conj
,
out
)
def
limited_exp
(
x
):
return
_math_helper
(
x
,
_limited_exp_helper
)
def
clipped_exp
(
x
,
out
=
None
):
return
_math_helper
(
x
,
lambda
z
:
np
.
exp
(
np
.
minimum
(
200
,
z
)),
out
)
def
limited_exp
(
x
,
out
=
None
):
return
_math_helper
(
x
,
_limited_exp_helper
,
out
)
def
_limited_exp_helper
(
x
):
...
...
@@ -114,8 +125,8 @@ def _limited_exp_helper(x):
return
result
def
limited_exp_deriv
(
x
):
return
_math_helper
(
x
,
_limited_exp_deriv_helper
)
def
limited_exp_deriv
(
x
,
out
=
None
):
return
_math_helper
(
x
,
_limited_exp_deriv_helper
,
out
)
def
_limited_exp_deriv_helper
(
x
):
...
...
@@ -127,19 +138,3 @@ def _limited_exp_deriv_helper(x):
result
[
mask
]
=
np
.
exp
(
thr
)
result
[
~
mask
]
=
np
.
exp
(
x
[
~
mask
])
return
result
def
log
(
x
,
base
=
None
):
result
=
_math_helper
(
x
,
np
.
log
)
if
base
is
not
None
:
result
=
result
/
log
(
base
)
return
result
def
conjugate
(
x
):
return
_math_helper
(
x
,
np
.
conjugate
)
def
conj
(
x
):
return
_math_helper
(
x
,
np
.
conjugate
)
nifty/minimization/iteration_controlling/iteration_controller.py
View file @
abbf03ba
...
...
@@ -39,7 +39,7 @@ class IterationController(
The concrete convergence criteria can be chosen by inheriting from this
class; the implementer has full flexibility to use whichever criteria are
appropriate for a particular problem - as ong as they can be computed from
appropriate for a particular problem - as
l
ong as they can be computed from
the information passed to the controller during the iteration process.
"""
...
...
nifty/operators/laplace_operator/laplace_operator.py
View file @
abbf03ba
...
...
@@ -20,7 +20,6 @@ import numpy as np
from
...field
import
Field
from
...spaces.power_space
import
PowerSpace
from
..endomorphic_operator
import
EndomorphicOperator
from
...
import
sqrt
from
...
import
nifty_utilities
as
utilities
...
...
@@ -109,7 +108,7 @@ class LaplaceOperator(EndomorphicOperator):
ret
[
sl_l
]
=
deriv
ret
[
prefix
+
(
-
1
,)]
=
0.
ret
[
sl_r
]
-=
deriv
ret
/=
sqrt
(
dposc
)
ret
/=
np
.
sqrt
(
dposc
)
ret
[
prefix
+
(
slice
(
None
,
2
),)]
=
0.
ret
[
prefix
+
(
-
1
,)]
=
0.
return
Field
(
self
.
domain
,
val
=
ret
).
weight
(
power
=-
0.5
,
spaces
=
spaces
)
...
...
@@ -131,7 +130,7 @@ class LaplaceOperator(EndomorphicOperator):
dpos
=
self
.
_dpos
.
reshape
((
1
,)
*
axis
+
(
nval
-
1
,))
dposc
=
self
.
_dposc
.
reshape
((
1
,)
*
axis
+
(
nval
,))
y
=
x
.
copy
().
weight
(
power
=
0.5
).
val
y
/=
sqrt
(
dposc
)
y
/=
np
.
sqrt
(
dposc
)
y
[
prefix
+
(
slice
(
None
,
2
),)]
=
0.
y
[
prefix
+
(
-
1
,)]
=
0.
deriv
=
(
y
[
sl_r
]
-
y
[
sl_l
])
/
dpos
# defined between points
...
...
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