Skip to content
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

ENH: Symbolic solver for dimension specifications. #19805

Merged
merged 10 commits into from Sep 26, 2021

Conversation

pearu
Copy link
Contributor

@pearu pearu commented Aug 31, 2021

Resolves #8062

Possibly conflicting with #19388 that replaces shape with f2py_shape. Whichever PR lands last, should update the usage of shape in crackfortran.py.

@pearu pearu self-assigned this Aug 31, 2021
@pearu pearu added this to In progress in f2py core via automation Aug 31, 2021
@pearu pearu marked this pull request as ready for review September 1, 2021 12:26
@mattip
Copy link
Member

mattip commented Sep 1, 2021

LGTM give 6 new alerts for this PR. Are they accurate?

This pull request introduces 6 alerts when merging 26752c3 into 0656fc4 - view on LGTM.com
new alerts:

3 for Variable defined multiple times
1 for Comparison using is when operands support __eq__
1 for Unused local variable
1 for Incomplete ordering

@pearu
Copy link
Contributor Author

pearu commented Sep 1, 2021

LGTM give 6 new alerts for this PR. Are they accurate?

The LGTM alerts were partially accurate but were certainly useful to pinpoint one real bug. Fixed the bug and warnings in the latest commit.

@mattip
Copy link
Member

mattip commented Sep 1, 2021

+1 for LGTM

numpy/f2py/crackfortran.py Outdated Show resolved Hide resolved
numpy/f2py/symbolic.py Outdated Show resolved Hide resolved
Copy link
Member

@HaoZeke HaoZeke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic! I will recheck the issues to see if this fixes more than the one referenced here; but this is a huge step forward.

@pearu
Copy link
Contributor Author

pearu commented Sep 3, 2021

scipy builds and all its tests pass with this PR.

@charris
Copy link
Member

charris commented Sep 17, 2021

@pearu Could you add a release note for this in doc/release/upcoming_changes? This is probably a new_feature or improvement.

Copy link
Member

@melissawm melissawm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very tiny typos otherwise this looks great, thanks @pearu !



class TestDimSpec(util.F2PyTest):
"""This test site tests various expressions that are used as dimension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""This test site tests various expressions that are used as dimension
"""This test suite tests various expressions that are used as dimension

`lower` and `upper` are arbitrary expressions of input parameters.
The evaluation is performed in C, so f2py has to translate Fortran
expressions to valid C expressions (an alternative approach is
that a developer specifies the corresponing C expressions in a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
that a developer specifies the corresponing C expressions in a
that a developer specifies the corresponding C expressions in a

@charris charris merged commit 4681424 into numpy:main Sep 26, 2021
f2py core automation moved this from In progress to Done Sep 26, 2021
charris added a commit to charris/numpy that referenced this pull request Sep 26, 2021
- Spelling fixes
- Release note fragment for numpygh-19805.
@charris
Copy link
Member

charris commented Sep 26, 2021

Thanks @pearu. I've done the spelling fixes and added a release note in #19961, feel free to edit the release note. Does #19388 need fixes?

charris added a commit that referenced this pull request Sep 28, 2021
MAINT: Minor cleanups after merging gh-19805
howjmay pushed a commit to howjmay/numpy that referenced this pull request Sep 29, 2021
- Spelling fixes
- Release note fragment for numpygh-19805.
@risicle
Copy link

risicle commented Mar 6, 2022

Hmm. Ever since commit 88f988a introduced here, in NixOS, the scikit-learn 1.0.2 kernel PCA unit tests cause crashes for us which appear to be related to a corrupted heap. This is with joblib 1.1.0, scipy 1.8.0, threadpoolctl 3.0.0, gfortran 9.3.0, gcc 10.3. Still investigating.

Edit: also tried with numpy 1.22.2 including fix #20724

@melissawm
Copy link
Member

@pearu thoughts?

@pearu
Copy link
Contributor Author

pearu commented Mar 8, 2022

@risicle Can you provide a minimal reproducer of the reported crashes? The reproducer should include the f2py wrapping step as the messages there may give a hint of what goes wrong.

@risicle
Copy link

risicle commented Mar 8, 2022

I'll try - it's all inside scipy's flapack_dsyevr, so I'll have to kick scipy's build process a bit.

Currently trying to convince our lapack to build with debugging symbols..

@risicle
Copy link

risicle commented Mar 11, 2022

A lot of fighting with debug symbols and a crash course in fortran later, it looks like what is happening is dsyevr is being called with an M of 10, but a ISUPPZ array allocated only one element long (4 bytes).

I'll try to get scipy's f2py calls to give up their secrets next.

@risicle
Copy link

risicle commented Mar 11, 2022

https://gist.github.com/risicle/d7450ec92bd89bff138ead438c28ce1c
https://gist.github.com/risicle/0e201ea432ffda2d0015a51daec88e7f

@@ -49783,33 +49783,33 @@
   capi_iwork_tmp = array_from_pyobj(NPY_INT,iwork_Dims,iwork_Rank,capi_iwork_intent,Py_None);
   if (capi_iwork_tmp == NULL) {
     PyObject *exc, *val, *tb;
     PyErr_Fetch(&exc, &val, &tb);
     PyErr_SetString(exc ? exc : _flapack_error,"failed in converting hidden `iwork' of _flapack.dsyevr to C/Fortran array" );
     npy_PyErr_ChainExceptionsCause(exc, val, tb);
   } else {
     iwork = (int *)(PyArray_DATA(capi_iwork_tmp));

   /* Processing variable z */
-  z_Dims[0]=(compute_v?MAX(0,n):0),z_Dims[1]=(compute_v?(*range=='I'?iu-il+1:MAX(1,n)):0);
+  z_Dims[0]=(compute_v ? MAX(0, n) : 0),z_Dims[1]=(compute_v ? (*range == 'I' ? 1 - il + iu : MAX(1, n)) : 0);
   capi_z_intent |= F2PY_INTENT_OUT|F2PY_INTENT_HIDE;
   capi_z_tmp = array_from_pyobj(NPY_DOUBLE,z_Dims,z_Rank,capi_z_intent,Py_None);
   if (capi_z_tmp == NULL) {
     PyObject *exc, *val, *tb;
     PyErr_Fetch(&exc, &val, &tb);
     PyErr_SetString(exc ? exc : _flapack_error,"failed in converting hidden `z' of _flapack.dsyevr to C/Fortran array" );
     npy_PyErr_ChainExceptionsCause(exc, val, tb);
   } else {
     z = (double *)(PyArray_DATA(capi_z_tmp));

   /* Processing variable isuppz */
-  isuppz_Dims[0]=(compute_v?(2*(*range=='A'||(*range=='I' && iu-il+1==n)?n:0)):0);
+  isuppz_Dims[0]=(compute_v ? 2 * (*range == 'A'||(*range == 1 + 'I' && iu - il == n) ? n : 0) : 0);
   capi_isuppz_intent |= F2PY_INTENT_OUT|F2PY_INTENT_HIDE;
   capi_isuppz_tmp = array_from_pyobj(NPY_INT,isuppz_Dims,isuppz_Rank,capi_isuppz_intent,Py_None);
   if (capi_isuppz_tmp == NULL) {
     PyObject *exc, *val, *tb;
     PyErr_Fetch(&exc, &val, &tb);
     PyErr_SetString(exc ? exc : _flapack_error,"failed in converting hidden `isuppz' of _flapack.dsyevr to C/Fortran array" );
     npy_PyErr_ChainExceptionsCause(exc, val, tb);
   } else {
     isuppz = (int *)(PyArray_DATA(capi_isuppz_tmp));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

f2py incorrectly translate dimension declaration
6 participants