Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Seitz
pystencils
Commits
e5294b75
Commit
e5294b75
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Allow `cast_func(x, 'float')` (previously only `cast_func(x, create_type('float'))`
parent
9b9a4b54
No related branches found
No related tags found
No related merge requests found
Pipeline
#16414
failed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/data_types.py
+1
-0
1 addition, 0 deletions
pystencils/data_types.py
pystencils_tests/test_cast_cast.py
+63
-0
63 additions, 0 deletions
pystencils_tests/test_cast_cast.py
with
64 additions
and
0 deletions
pystencils/data_types.py
+
1
−
0
View file @
e5294b75
...
...
@@ -56,6 +56,7 @@ class cast_func(sp.Function):
# -> thus a separate class boolean_cast_func is introduced
if
isinstance
(
args
[
0
],
Boolean
):
cls
=
boolean_cast_func
args
=
(
args
[
0
],
create_type
(
args
[
1
]))
return
sp
.
Function
.
__new__
(
cls
,
*
args
,
**
kwargs
)
@property
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_cast_cast.py
0 → 100644
+
63
−
0
View file @
e5294b75
# -*- coding: utf-8 -*-
#
# Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
#
# Distributed under terms of the GPLv3 license.
"""
"""
import
pystencils
from
pystencils.data_types
import
cast_func
import
numpy
as
np
def
test_cast
():
float_type
=
pystencils
.
data_types
.
create_type
(
'
float32
'
)
x
,
y
=
pystencils
.
fields
(
'
x,y: [1d]
'
)
assignments
=
pystencils
.
AssignmentCollection
({
y
.
center
():
cast_func
(
x
.
center
(),
float_type
)},
{})
kernel
=
pystencils
.
create_kernel
(
assignments
)
print
(
pystencils
.
show_code
(
kernel
))
kernel
.
compile
()
def
test_cast_cast
():
float_type
=
pystencils
.
data_types
.
create_type
(
'
float32
'
)
x
,
y
=
pystencils
.
fields
(
'
x,y: [1d]
'
)
assignments
=
pystencils
.
AssignmentCollection
({
y
.
center
():
cast_func
(
cast_func
(
x
.
center
(),
float_type
),
float_type
)},
{})
kernel
=
pystencils
.
create_kernel
(
assignments
)
print
(
pystencils
.
show_code
(
kernel
))
kernel
.
compile
()
def
test_cast_with_string
():
x
,
y
=
pystencils
.
fields
(
'
x,y: [1d]
'
)
assignments
=
pystencils
.
AssignmentCollection
({
y
.
center
():
cast_func
(
x
.
center
(),
np
.
float32
)},
{})
kernel
=
pystencils
.
create_kernel
(
assignments
)
print
(
pystencils
.
show_code
(
kernel
))
kernel
.
compile
()
def
test_cast_cast_with_string
():
x
,
y
=
pystencils
.
fields
(
'
x,y: [1d]
'
)
assignments
=
pystencils
.
AssignmentCollection
({
y
.
center
():
cast_func
(
cast_func
(
x
.
center
(),
'
float32
'
),
np
.
float32
)},
{})
kernel
=
pystencils
.
create_kernel
(
assignments
)
print
(
pystencils
.
show_code
(
kernel
))
def
main
():
test_cast
()
test_cast_cast
()
test_cast_with_string
()
test_cast_cast_with_string
()
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment