Skip to content
Snippets Groups Projects
Commit e5294b75 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Allow `cast_func(x, 'float')` (previously only `cast_func(x, create_type('float'))`

parent 9b9a4b54
Branches update-codegen
No related merge requests found
Pipeline #16414 failed with stage
in 3 minutes and 37 seconds
......@@ -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
......
# -*- 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()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment