Use get_type_of_expression in typing_form_sympy_inspection to infer types
DANGER ZONE: this changes something in the core behavior of pystencils. Be careful before merging!
In summary, when typing_form_sympy_inspection
reaches the point where it would just use default_type
, we try to use get_type_of_expression
to infer the actual type.
We use information of previously defined variables in current scope.
Another approach would be to just type all the intermediate variable with auto
.
x = pystencils.fields('x: float32[3d]')
assignments = pystencils.AssignmentCollection({
a: cast_func(10, create_type('float64')),
b: cast_func(10, create_type('uint16')),
e: 11,
c: b,
f: c + b,
d: c + b + x.center + e,
x.center: c + b + x.center
})
Before:
FUNC_PREFIX void kernel(float * RESTRICT _data_x, int64_t const _size_x_0, int64_t const _size_x_1,
int64_t const _size_x_2, int64_t const _stride_x_0, int64_t const _stride_x_1, int64_t const _stri
de_x_2)
{
const double a = 10.0;
const double b = 10;
const double e = 11.0;
const double c = b;
const double f = b + c;
for (int ctr_0 = 0; ctr_0 < _size_x_0; ctr_0 += 1)
{
float * RESTRICT _data_x_00 = _data_x + _stride_x_0*ctr_0;
for (int ctr_1 = 0; ctr_1 < _size_x_1; ctr_1 += 1)
{
float * RESTRICT _data_x_00_10 = _stride_x_1*ctr_1 + _data_x_00;
for (int ctr_2 = 0; ctr_2 < _size_x_2; ctr_2 += 1)
{
const double d = b + c + e + _data_x_00_10[_stride_x_2*ctr_2];
_data_x_00_10[_stride_x_2*ctr_2] = b + c + _data_x_00_10[_stride_x_2*ctr_2];
}
}
}
}
After:
FUNC_PREFIX void kernel(float * RESTRICT _data_x, int64_t const _size_x_0, int64_t const _size_x_1,
int64_t const _size_x_2, int64_t const _stride_x_0, int64_t const _stride_x_1, int64_t const _stri
de_x_2)
{
const double a = 10.0;
const uint16_t b = 10;
const int64_t e = 11.0;
const uint16_t c = b;
const uint16_t f = b + c;
for (int ctr_0 = 0; ctr_0 < _size_x_0; ctr_0 += 1)
{
float * RESTRICT _data_x_00 = _data_x + _stride_x_0*ctr_0;
for (int ctr_1 = 0; ctr_1 < _size_x_1; ctr_1 += 1)
{
float * RESTRICT _data_x_00_10 = _stride_x_1*ctr_1 + _data_x_00;
for (int ctr_2 = 0; ctr_2 < _size_x_2; ctr_2 += 1)
{
const float d = b + c + e + _data_x_00_10[_stride_x_2*ctr_2];
_data_x_00_10[_stride_x_2*ctr_2] = b + c + _data_x_00_10[_stride_x_2*ctr_2];
}
}
}
}
Edited by Stephan Seitz
Merge request reports
Activity
Filter activity
added 1 commit
- 4e6131ab - Restore previous behavior of get_type_of_expression for untyped symbol
added 1 commit
- 52699563 - Restore previous behavior of get_type_of_expression for untyped symbol
added 6 commits
-
52699563...ddbe84da - 4 commits from branch
pycodegen:master
- d4a98452 - Use get_type_of_expression in typing_form_sympy_inspection to infer types
- 55f67d43 - Restore previous behavior of get_type_of_expression for untyped symbol
-
52699563...ddbe84da - 4 commits from branch
mentioned in merge request !47 (closed)
added 30 commits
-
55f67d43...1db024c5 - 27 commits from branch
pycodegen:master
- d6301eea - Added integration test that checks out pycodegen repo
- 43f6d5de - Use get_type_of_expression in typing_form_sympy_inspection to infer types
- 869d901a - Restore previous behavior of get_type_of_expression for untyped symbol
Toggle commit list-
55f67d43...1db024c5 - 27 commits from branch
enabled an automatic merge when the pipeline for 8770acd7 succeeds
mentioned in commit 0a8c16b0
Please register or sign in to reply