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
f2py fails for functions returning character(len=len(input_string)) #3425
Comments
Sorry, I couldn't work out how to tag this with component: numpy.f2py |
P.S. I'm running numpy version 1.7.1 on Gentoo GNU/Linux |
@chatcannon I suspect this problem persists, but could you try with numpy 1.8 or current development? |
I can confirm the issue is still here in numpy |
Here's what I've managed to get so far:
pure function test(str)
character(len=*), intent(in) :: str
character(len=len(str)) :: test
integer :: i
test(1:1) = 'A'
do i = 2, len(str)
test(i:i) = str(i:i)
enddo
end function test I get: /tmp/tmpdg8zrhbc/src.linux-x86_64-3.9/stringsmodule.c: In function 'f2py_rout_strings_strings_test':
/tmp/tmpdg8zrhbc/src.linux-x86_64-3.9/stringsmodule.c:279:20: error: 'str_Dims' undeclared (first use in this function)
279 | slen(test) = len(str);
| ^~~
python module strings ! in
interface ! in :strings
module strings ! in :strings:strings.f90
subroutine test(str, a) ! in :strings:strings.f90:strings
character*(*) intent(in) :: str
character*len(str) intent(out) :: a
end subroutine test
end module strings
end interface
end python module strings Running >>> import strings
>>> print(strings.strings.test.__doc__) # should return a as output, but returns
test(str,a)
Wrapper for ``test``.
Parameters
----------
str : input string(len=-1)
a : input string(len=1) (note the incorrect intent for
So the problem seems to be when using a function but not a subroutine. When inspecting the code, IIUC the problem comes from the fact that we need to use My question to @pearu is if we should require the use of the |
My first reaction (without looking at code) is that f2py should be fixed by replacing |
TST: added test for issue numpy#18684 ENH: f2py opens files with correct encoding, fixes numpy#635 TST: added test for issue numpy#6308 TST: added test for issue numpy#4519 TST: added test for issue numpy#3425 ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook. ENH: Add support for detecting utf-16 and utf-32 encodings.
TST: added test for issue numpy#18684 ENH: f2py opens files with correct encoding, fixes numpy#635 TST: added test for issue numpy#6308 TST: added test for issue numpy#4519 TST: added test for issue numpy#3425 ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook. ENH: Add support for detecting utf-16 and utf-32 encodings.
TST: added test for issue numpy#18684 ENH: f2py opens files with correct encoding, fixes numpy#635 TST: added test for issue numpy#6308 TST: added test for issue numpy#4519 TST: added test for issue numpy#3425 ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook. ENH: Add support for detecting utf-16 and utf-32 encodings.
I've written simple toupper() and tolower() functions in Fortran that start like this:
When wrapping these with f2py, I get an error looking like this:
I guess the
len(str)
needs to be replaced byslen(str)
.This problem occurs with both f2py-2.7 and f2py-3.3
It does not depend on the name of the variable
str
- I tried a couple of other names.The text was updated successfully, but these errors were encountered: