8000 BUG: Allocatable array variables don't show up in `dir` · Issue #27696 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Allocatable array variables don't show up in dir #27696

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 < 8000 a class="Link--inTextBlock" href="https://docs.github.com/terms" target="_blank">terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
HaoZeke opened this issue Nov 4, 2024 · 1 comment
Open

BUG: Allocatable array variables don't show up in dir #27696

HaoZeke opened this issue Nov 4, 2024 · 1 comment

Comments

@HaoZeke
Copy link
Member
HaoZeke commented Nov 4, 2024
          @HaoZeke Thank you very much for the fix!

I installed using

pip install git+https://github.com/numpy/numpy.git@refs/pull/27695/merge

Yes, it is including the lanedata module. Interestingly, the allocatable module variable theta, however, is not listed by dir

In [9]: dir(laneemden._solver.lanedata)
Out[9]: 
['__call__',
 '__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'maxdata',
 'ndata']

but it is accessible, and returns None if not allocated and returns the array when allocated. Even when allocated, however, it is not listed.

In [11]: laneemden._solver.lanedata.<TAB>
maxdata ndata   
In [11]:

This may not be new behaviour (I do not recall having tried this before), but is a bit curious, and might be confusing.

Before allocating

In [5]: laneemden._solver.lanedata.theta

In [6]:

and after allocating (laneemden.solver.test())

In [10]: laneemden._solver.lanedata.theta
Out[10]: 
array([[ 1.00000000e+00,  0.00000000e+00],
       [ 9.99999999e-01, -2.03450521e-05],
       [ 9.99999998e-01, -4.06901040e-05],
       ...,
       [ 5.09606183e-06, -4.24312354e-02],
       [ 2.50628767e-06, -4.24304844e-02],
       [-8.34406605e-08, -4.24297334e-02]])

In [11]:

Originally posted by @2sn in #27695 (comment)

@HaoZeke
Copy link
Member Author
HaoZeke commented Nov 4, 2024

Basically because allocatable arrays get proxied into a dimension helper call f2pysetupfunc(maxdata,f2py_lanedata_getdims_theta,ndata)...

!     -*- f90 -*-
!     This file is autogenerated with f2py (version:2.2.0.dev0+git20241104.531a694)
!     It contains Fortran 90 wrappers to fortran functions.

      
      subroutine f2pyinittypes(f2pysetupfunc)
      use types, only : int32
      use types, only : int64
      use types, only : real64
      external f2pysetupfunc
      call f2pysetupfunc(int32,int64,real64)
      end subroutine f2pyinittypes

      subroutine f2py_lanedata_getdims_theta(r,s,f2pysetdata,flag)
      use lanedata, only: d => theta

      integer flag
      external f2pysetdata
      logical ns
      integer r,i
      integer(8) s(*)
      ns = .FALSE.
      if (allocated(d)) then
         do i=1,r
            if ((size(d,i).ne.s(i)).and.(s(i).ge.0)) then
               ns = .TRUE.
            end if
         end do
         if (ns) then
            deallocate(d)
         end if
      end if
      if ((.not.allocated(d)).and.(s(1).ge.1)) then
       allocate(d(s(1),s(2)))
      end if
      if (allocated(d)) then
         do i=1,r
            s(i) = size(d,i)
         end do
      end if
      flag = 1
      call f2pysetdata(d,allocated(d))
      end subroutine f2py_lanedata_getdims_theta
      
      subroutine f2pyinitlanedata(f2pysetupfunc)
      use lanedata, only : maxdata
      use lanedata, only : theta
      use lanedata, only : ndata
      external f2pysetupfunc
      external f2py_lanedata_getdims_theta
      call f2pysetupfunc(maxdata,f2py_lanedata_getdims_theta,ndata)
      end subroutine f2pyinitlanedata

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

No branches or pull requests

1 participant
0