Deferred dimensions
Description
Support deferred dimensions (:). We make use of these whenever we deal with allocatable arrays where we don't know their size beforehand. A deferred shaped array cannot be used as return value in wrapped code as f2py can't handle them directly. Instead, we return the shape, dtype and a pointer to the array created by fortran. These parameters can be used to create a numpy array that references the same piece of memory.
See an example of the wrapped code for accessing a deferred_shape attribute
subroutine ig_deferred_shape(model_index, nd, dtype, dshape, dloc)
! Returns a pointer to an array which can be directly modified
!f2py integer(8), intent(out) :: dloc
integer, intent(in) :: model_index
integer, intent(out) :: nd
character(len=20), intent(out) :: dtype
integer, dimension(10), intent(out) :: dshape
type(c_ptr), intent(out) :: dloc
type(ArrayHandling), pointer :: instance
call manager_get_instance(model_index, instance)
nd = rank(instance % deferred_shape)
dtype = "float64"
dshape(1:nd) = shape(instance % deferred_shape)
dloc = c_loc(instance % deferred_shape)
end subroutine ig_deferred_shape
This is still a draft, but I would like your thoughts. The current implementation only performs this operation when we use deferred shape arrays. We could in fact do this anytime we have arrays that might be more consistent. fgen handles fixed shape arrays -> numpy natively , but I don't know if they actually make a copy (they are copies).
Merge Request Steps
Please confirm that this pull request has done the following:
-
Tests added -
Documentation added (where applicable) -
Changelog item added to changelog/.