Skip to content

Conversation

@mzecc
Copy link
Collaborator

@mzecc mzecc commented Sep 9, 2025

Description

Providing classes to handle 1D integer arrays of results.

Checklist

Please confirm that this pull request has done the following:

  • Tests added
  • Documentation added (where applicable)
  • Changelog item added to changelog/

@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 91.48936% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.52%. Comparing base (ca2a5f5) to head (4322463).
⚠️ Report is 1 commits behind head on cross-reference.

Files with missing lines Patch % Lines
src/example_fgen_basic/get_square_root.py 88.23% 1 Missing and 1 partial ⚠️
src/example_fgen_basic/result/result_dp.py 92.85% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           cross-reference      #33      +/-   ##
===================================================
- Coverage           100.00%   96.52%   -3.48%     
===================================================
  Files                    7       10       +3     
  Lines                   68      115      +47     
  Branches                 0        4       +4     
===================================================
+ Hits                    68      111      +43     
- Misses                   0        3       +3     
- Partials                 0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@znicholls znicholls changed the base branch from main to cross-reference September 10, 2025 08:07
Copy link
Contributor

@znicholls znicholls left a comment

Choose a reason for hiding this comment

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

Nice - going in the right direction

Comment on lines 17 to 28
! class(*), allocatable :: data_v(..)
! MZ: assumed rank can only be dummy argument NOT type/class argument
! Data i.e. the result (if no error occurs)
!
! Assumed rank array
! (https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049)
! Technically a Fortran 2018 feature,
! so maybe we need to update our file extensions.
! If we can't use this, just comment this out
! and leave each subclass of Result to set its data type
! (e.g. ResultInteger will have `integer :: data`,
! ResultDP1D will have `real(dp), dimension(:), allocatable :: data`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
! class(*), allocatable :: data_v(..)
! MZ: assumed rank can only be dummy argument NOT type/class argument
! Data i.e. the result (if no error occurs)
!
! Assumed rank array
! (https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049)
! Technically a Fortran 2018 feature,
! so maybe we need to update our file extensions.
! If we can't use this, just comment this out
! and leave each subclass of Result to set its data type
! (e.g. ResultInteger will have `integer :: data`,
! ResultDP1D will have `real(dp), dimension(:), allocatable :: data`)
! Sub-classess hould have a `data` attribute
! We do not have that here, because Fortran does not have an `Any` type.


contains

subroutine clean_up(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is clean_up the name to use for automatic deallocation ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No it is not. The automatic deallocation is done using the final :: my_procedure.

But for abstract types I've found a problem:

  • Fortran requires that the dummy argument of a final procedure must be declared with the exact type, not the polymorphic class;
  • But an abstract type cannot be instantiated.

So final requires an exact type, but abstract types forbid exact-type dummies and that's a conflict I could not resolve.

The solution might be to have a clean_up procedure in the abstract type that gets called in the final routine of the child type to then make error_v to deallocate. I do not know if this makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

super makes sense to me

Comment on lines 37 to 39
! procedure, public:: build
! TODO: Think about whether build should be on the abstract class
! or just on each concrete implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
! procedure, public:: build
! TODO: Think about whether build should be on the abstract class
! or just on each concrete implementation
! Sub-classes should implement a build method too.
! As above, we can't implement this here
! because Fortran doesn't have an `Any` type
! (which is what we would need for `data`)

!!
!! Holds either an integer value or an error.

integer, allocatable :: data_v(:)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
integer, allocatable :: data_v(:)
integer :: data_v
! or
integer, allocatable :: data_v

To start, let's just do an int, rather than a 1D array of int

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did an array because one has to take care of the allocation. But ok, no problem in doing scalars first.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it


end function constructor

subroutine build(self, data_v_in, error_v_in)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
subroutine build(self, data_v_in, error_v_in)
function build(self, data_v_in) result(error_v_in)
! or would the following work
function build(self, data_v_in) result(result_v)
! and we return a `ResultNone` type

! Hopefully can leave without docstring (like Python)

if (allocated(self % data_v)) deallocate (self % data_v)
if (allocated(self % error_v)) call self % clean_up()

Choose a reason for hiding this comment

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

Suggested change
if (allocated(self % error_v)) call self % clean_up()
call self % clean_up()

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants