pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

Fix narrowing errors by replacing int by ssize_t

Open maresb opened this issue 1 year ago • 6 comments

Ref: https://github.com/pymc-devs/sunode/issues/46#issuecomment-1871087897

Description

I don't actually know any C++ or have any idea if this is a sensible change. But it seems like it may fix some obscure errors on Mac with sunode.

Related Issue

  • [ ] Closes #
  • [ ] Related to #

Checklist

Type of change

  • [ ] New feature / enhancement
  • [X] Bug fix
  • [ ] Documentation
  • [ ] Maintenance
  • [ ] Other (please specify):

maresb avatar Apr 21 '24 16:04 maresb

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.76%. Comparing base (58aad80) to head (7785dc8). Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #725   +/-   ##
=======================================
  Coverage   80.76%   80.76%           
=======================================
  Files         162      162           
  Lines       46715    46715           
  Branches    11427    11427           
=======================================
  Hits        37729    37729           
  Misses       6736     6736           
  Partials     2250     2250           
Files Coverage Δ
pytensor/tensor/elemwise_cgen.py 95.34% <ø> (ø)

codecov[bot] avatar Apr 21 '24 16:04 codecov[bot]

Not sure about this, gonna need to read about it. It seems that stuff were purposefully using int?

ricardoV94 avatar Apr 21 '24 18:04 ricardoV94

Perhaps, I don't really understand much myself.

maresb avatar Apr 21 '24 18:04 maresb

The original int is I think really weird, to a point of just being wrong. Pointer offsets shouldn't be a int, I guess that leads to compiler errors in newer versions? On most machines they are 32 bit, but all strides etc should usually be the same size as pointers, which are 64 bit. I guess they were an int originally because size_t can only be positive. ptrdiff_t should I think be the right type however, not ssize_t, even though in practice they are probably implemented as the same thing most of the time. ssize_t is not guaranteed to be able to represent anything smaller than -1, and it is POSIX only as well.

aseyboldt avatar Apr 23 '24 08:04 aseyboldt

Great, thanks a lot @aseyboldt for the "pointer" to ptrdiff_t. :slightly_smiling_face:

I'm busy with some other stuff at the moment, but I'll come back to this. I'd like to enable some basic tests on macos (which I expect to fail), and then we'll be able to test properly.

maresb avatar Apr 23 '24 09:04 maresb

Was hoping for an easy way out with https://github.com/conda-forge/sunode-feedstock/pull/35, but it didn't work.

maresb avatar Jun 17 '24 12:06 maresb