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
pycodegen
pystencils
Commits
f76edf72
Commit
f76edf72
authored
Jan 08, 2021
by
Dominik Thoennes
Browse files
add single argument integer functions
parent
26fce4ff
Pipeline
#29199
failed with stage
in 5 minutes and 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pystencils/integer_functions.py
View file @
f76edf72
...
...
@@ -27,6 +27,27 @@ class IntegerFunctionTwoArgsMixIn(sp.Function):
raise
ValueError
(
"Integer functions can only be constructed with typed expressions"
)
return
super
().
__new__
(
cls
,
*
args
)
class
IntegerFunctionOneArgMixIn
(
sp
.
Function
):
is_integer
=
True
def
__new__
(
cls
,
arg1
):
args
=
[]
if
isinstance
(
arg1
,
sp
.
Number
)
or
isinstance
(
arg1
,
int
):
args
.
append
(
cast_func
(
arg1
,
create_type
(
"int"
)))
elif
isinstance
(
arg1
,
np
.
generic
):
args
.
append
(
cast_func
(
arg1
,
arg1
.
dtype
))
else
:
args
.
append
(
arg1
)
try
:
type
=
get_type_of_expression
(
arg1
)
if
not
type
.
is_int
():
raise
ValueError
(
"Argument to integer function is not an int but "
+
str
(
type
))
except
NotImplementedError
:
raise
ValueError
(
"Integer functions can only be constructed with typed expressions"
)
return
super
().
__new__
(
cls
,
*
args
)
# noinspection PyPep8Naming
class
bitwise_xor
(
IntegerFunctionTwoArgsMixIn
):
...
...
@@ -59,11 +80,11 @@ class int_div(IntegerFunctionTwoArgsMixIn):
# noinspection PyPep8Naming
class
int_power_of_2
(
sp
.
Functio
n
):
class
int_power_of_2
(
IntegerFunctionOneArgMixI
n
):
pass
# noinspection PyPep8Naming
class
post_increment
(
sp
.
Functio
n
):
class
post_increment
(
IntegerFunctionOneArgMixI
n
):
pass
...
...
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