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
afc5daa7
Commit
afc5daa7
authored
Sep 19, 2017
by
Martin Reinecke
Browse files
more compatibility to numpy
parent
1d0e22b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
nifty2go/basic_arithmetics.py
View file @
afc5daa7
...
...
@@ -23,79 +23,84 @@ from .field import Field
__all__
=
[
'cos'
,
'sin'
,
'cosh'
,
'sinh'
,
'tan'
,
'tanh'
,
'arccos'
,
'arcsin'
,
'arccosh'
,
'arcsinh'
,
'arctan'
,
'arctanh'
,
'sqrt'
,
'exp'
,
'log'
,
'conjugate'
]
'conj'
,
'conjugate'
]
def
_math_helper
(
x
,
function
):
if
isinstance
(
x
,
Field
):
return
Field
(
domain
=
x
.
domain
,
val
=
function
(
x
.
val
))
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
:
return
function
(
np
.
asarray
(
x
))
return
Field
(
domain
=
x
.
domain
,
val
=
function
(
x
.
val
))
def
cos
(
x
):
return
_math_helper
(
x
,
np
.
cos
)
def
cos
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
cos
,
out
)
def
sin
(
x
):
return
_math_helper
(
x
,
np
.
sin
)
def
sin
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sin
,
out
)
def
cosh
(
x
):
return
_math_helper
(
x
,
np
.
cosh
)
def
cosh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
cosh
,
out
)
def
sinh
(
x
):
return
_math_helper
(
x
,
np
.
sinh
)
def
sinh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sinh
,
out
)
def
tan
(
x
):
return
_math_helper
(
x
,
np
.
tan
)
def
tan
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
tan
,
out
)
def
tanh
(
x
):
return
_math_helper
(
x
,
np
.
tanh
)
def
tanh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
tanh
,
out
)
def
arccos
(
x
):
return
_math_helper
(
x
,
np
.
arccos
)
def
arccos
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arccos
,
out
)
def
arcsin
(
x
):
return
_math_helper
(
x
,
np
.
arcsin
)
def
arcsin
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arcsin
,
out
)
def
arccosh
(
x
):
return
_math_helper
(
x
,
np
.
arccosh
)
def
arccosh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arccosh
,
out
)
def
arcsinh
(
x
):
return
_math_helper
(
x
,
np
.
arcsinh
)
def
arcsinh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arcsinh
,
out
)
def
arctan
(
x
):
return
_math_helper
(
x
,
np
.
arctan
)
def
arctan
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arctan
,
out
)
def
arctanh
(
x
):
return
_math_helper
(
x
,
np
.
arctanh
)
def
arctanh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arctanh
,
out
)
def
sqrt
(
x
):
return
_math_helper
(
x
,
np
.
sqrt
)
def
sqrt
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sqrt
,
out
)
def
exp
(
x
):
return
_math_helper
(
x
,
np
.
exp
)
def
exp
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
exp
,
out
)
def
log
(
x
):
return
_math_helper
(
x
,
np
.
log
)
def
log
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
log
,
out
)
def
conjugate
(
x
):
return
_math_helper
(
x
,
np
.
conjugate
)
def
conjugate
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
conjugate
,
out
)
def
conj
(
x
):
return
_math_helper
(
x
,
np
.
conj
ugate
)
def
conj
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
conj
,
out
)
nifty2go/operators/laplace_operator/laplace_operator.py
View file @
afc5daa7
...
...
@@ -109,7 +109,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 +131,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