New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: f2py 1.24 - string scalars fail #23192
Comments
Even if I use "proper" F90 character(len=8) :: nameprob I still get the same issue
PS - I'd like to take this opportunity to thank the character(len=2), dimension(-1:nzsym) :: izsym |
The problem seems to be when the {"nameprob",1,{{8}},NPY_STRING, 8}, where I assume the first |
The issue seems to be with the call dm = capi_maps.getarrdims(n, var) in {'dims': '8', 'size': '8', 'rank': '1'} where {'typespec': 'character', 'charselector': {'len': '8'}, 'attrspec': []} for my |
Ping @pearu and @melissawm since this should have to do with the f2py character rework. |
I propose to change in ret['dims'] = getstrlength(var)
ret['size'] = ret['dims']
ret['rank'] = '1' to ret['size'] = getstrlength(var)
ret['rank'] = '0'
ret['dims'] = '' which seems to work for my really big code ... |
Cool, setting the rank to 0 does seem sensible. Would you be happy to create a PR? Maybe we can get one of the f2py folks to look at it, or we just have to hope its right :). |
I will give it a try. |
I never submitted to numpy. I tried to push on a new branch, but it seems this is not how you set it up [f2py-string-scalar] ~/numpy/.git> git push --set-upstream origin f2py-string-scalar
ERROR: Permission to numpy/numpy.git denied to 2sn.
fatal: Could not read from remote repository. |
You have to create the new branch on your own fork, the rest is the same. |
in previous version, any string scalar was converted to a string array of dimension len, i.e., a definition character(len=N) :: X effectively became character(len=NNN), dimension(NNN) :: X from the point of few of the numpy (python) interface: X.shape == (NNN,) X.dtype == '|SNNN' Closes numpygh-23192
Describe the issue:
Since NumPy Version 1.24 string scalars seem to fail. I have a code that defines a character variable of length 8,
which in the
puf
file becomesas it should. After compilation, however, when I access the variable though its module (
data
) or its common block (namcom
), either way I getan array of length 8 of character of length 8. It seems
8
has been wrongly used twice, as char length and as array length - despite the variable is a scalar. For another variable defined ascharacter*16
there are 16 units of!S16
type. Etc.What is returned is just extra stuff from memory.
When a dimension is specified, e.g.,
all is fine
and I get the desired array. Only scalar
character
variables seem to be converted to arraysI should add that this is an interface module that is linked to library with the actual code (so I can use all Fortran statements w/o interfering with
f2py
. But I think it is not relevant, and I assume a very easy-to-fix small bug. Hopefully.In NumPy Version 1.23.5 this issue is not present.
Reproduce the code example:
Error message:
Runtime information:
1.24.2
3.11.1 (main, Jan 21 2023, 21:33:07) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]
[{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX'],
'not_found': ['AVX512_KNL',
'AVX512_KNM',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'SkylakeX',
'filepath': '/home/alex/Python_3.11.1/lib/python3.11/site-packages/numpy.libs/libopenblas64_p-r0-15028c96.3.21.so',
'internal_api': 'openblas',
'num_threads': 16,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.21'},
{'architecture': 'SkylakeX',
'filepath': '/home/alex/Python_3.11.1/lib/python3.11/site-packages/scipy.libs/libopenblasp-r0-41284840.3.18.so',
'internal_api': 'openblas',
'num_threads': 16,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.18'},
{'filepath': '/usr/lib64/libgomp.so.1.0.0',
'internal_api': 'openmp',
'num_threads': 16,
'prefix': 'libgomp',
'user_api': 'openmp',
'version': None},
{'architecture': 'SkylakeX',
'filepath': '/usr/lib64/libopenblaso-r0.3.21.so',
'internal_api': 'openblas',
'num_threads': 16,
'prefix': 'libopenblas',
'threading_layer': 'openmp',
'user_api': 'blas',
'version': '0.3.21'}]
None
Context for the issue:
The code expects a variable, and now returned are other parts of memory that could cause segmentation faults.
Also, the data type is not what is expected, so the python code breaks (in this case, it was used to concatenate a list of strings, but one was an array with arbitrary data from memory, and the GUI function that was passed to (to set as Window title) was not happy about some of the characters, such as
\x00
.Could you please also point me where in f2py this issue may occur?
Initially I was happy when I read in the NumPy 1.24 release notes that there have been some improvements to handling of strings - to try them out - but now it seems the change also had some side effect and broke at least my string declarations.
:-(
PS - Is there a more detailed statement / example what has changes and is the new functionality of
f2py
for strings?The text was updated successfully, but these errors were encountered: