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
Frederik Hennig
pystencils
Commits
65c7e576
Commit
65c7e576
authored
May 11, 2022
by
Markus Holzer
Browse files
Implemented Logarithm
parent
ea943334
Changes
3
Hide whitespace changes
Inline
Side-by-side
pystencils/kernel_contrains_check.py
View file @
65c7e576
...
...
@@ -10,10 +10,11 @@ from pystencils.field import Field
from
pystencils.node_collection
import
NodeCollection
from
pystencils.transformations
import
NestedScopes
# TODO use this in Constraint Checker
accepted_functions
=
[
sp
.
Pow
,
sp
.
sqrt
,
sp
.
log
,
# TODO trigonometric functions (and whatever tests will fail)
]
...
...
pystencils/typing/leaf_typing.py
View file @
65c7e576
...
...
@@ -212,7 +212,7 @@ class TypeAdder:
new_args
.
append
(
a
)
return
expr
.
func
(
*
new_args
)
if
new_args
else
expr
,
collated_type
elif
isinstance
(
expr
,
(
sp
.
Pow
,
sp
.
exp
,
InverseTrigonometricFunction
,
TrigonometricFunction
,
HyperbolicFunction
)):
HyperbolicFunction
,
sp
.
log
)):
args_types
=
[
self
.
figure_out_type
(
arg
)
for
arg
in
expr
.
args
]
collated_type
=
collate_types
([
t
for
_
,
t
in
args_types
])
new_args
=
[
a
if
t
.
dtype_eq
(
collated_type
)
else
CastFunc
(
a
,
collated_type
)
for
a
,
t
in
args_types
]
...
...
pystencils_tests/test_logarithm.py
0 → 100644
View file @
65c7e576
import
pytest
import
numpy
as
np
import
sympy
as
sp
import
pystencils
as
ps
@
pytest
.
mark
.
parametrize
(
'dtype'
,
[
"float64"
,
"float32"
])
def
test_log
(
dtype
):
a
=
sp
.
Symbol
(
"a"
)
x
=
ps
.
fields
(
f
'x:
{
dtype
}
[1d]'
)
assignments
=
ps
.
AssignmentCollection
({
x
.
center
():
sp
.
log
(
a
)})
ast
=
ps
.
create_kernel
(
assignments
)
code
=
ps
.
get_code_str
(
ast
)
kernel
=
ast
.
compile
()
# ps.show_code(ast)
if
dtype
==
"float64"
:
assert
"float"
not
in
code
array
=
np
.
zeros
((
10
,),
dtype
=
dtype
)
kernel
(
x
=
array
,
a
=
100
)
assert
np
.
allclose
(
array
,
4.60517019
)
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