Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • pystencils pystencils
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 18
    • Issues 18
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pycodegen
  • pystencilspystencils
  • Merge requests
  • !43

Use get_type_of_expression in typing_form_sympy_inspection to infer types

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Stephan Seitz requested to merge seitz/pystencils:infer-symbol-types-from-definition into master Aug 29, 2019
  • Overview 1
  • Commits 4
  • Pipelines 9
  • Changes 5

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 Aug 30, 2019 by Stephan Seitz
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: infer-symbol-types-from-definition