Skip to content

Commit a567cd5

Browse files
committed
Unified result container
1 parent c42bb2d commit a567cd5

25 files changed

Lines changed: 819 additions & 1914 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test-fortran: build-fortran ## run the Fortran tests
114114

115115
.PHONY: install-fortran
116116
install-fortran: build-fortran ## install the Fortran (including the extension module)
117-
uv run meson install -C build -v
117+
uv run meson install -C build # -v
118118
# # Can also do this to see where things go without making a mess
119119
# uv run meson install -C build --destdir ../install-example
120120

fortitude.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
select = [ "C", "E", "S", "PORT" ]
66
#Ignoring:
77
# C003: 'implicit none' missing 'external' [f2py does not recognize the syntax implicit none(type, external)]
8-
ignore = ["C003"]
8+
ignore = ["C003","C072","S221"]
99
line-length = 120

meson.build

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ if pyprojectwheelbuild_enabled
5656
'src/example_fgen_basic/error_v/passing_wrapper.f90',
5757
'src/example_fgen_basic/get_square_root_wrapper.f90',
5858
'src/example_fgen_basic/get_wavelength_wrapper.f90',
59-
'src/example_fgen_basic/result/result_dp_wrapper.f90',
60-
'src/example_fgen_basic/result/result_int_wrapper.f90',
59+
'src/example_fgen_basic/result/result_wrapper.f90',
6160
)
6261

6362
# Specify all the other source Fortran files (original files and managers)
@@ -72,13 +71,15 @@ if pyprojectwheelbuild_enabled
7271
'src/example_fgen_basic/get_square_root.f90',
7372
'src/example_fgen_basic/get_wavelength.f90',
7473
'src/example_fgen_basic/kind_parameters.f90',
75-
'src/example_fgen_basic/result/result.f90',
76-
'src/example_fgen_basic/result/result_none.f90',
77-
'src/example_fgen_basic/result/result_dp.f90',
78-
'src/example_fgen_basic/result/result_dp_manager.f90',
79-
'src/example_fgen_basic/result/result_int.f90',
80-
'src/example_fgen_basic/result/result_int_manager.f90',
81-
'src/example_fgen_basic/result/result_int1D.f90',
74+
'src/example_fgen_basic/result/result_gen.f90',
75+
'src/example_fgen_basic/result/result_manager.f90',
76+
# 'src/example_fgen_basic/result/result.f90',
77+
# 'src/example_fgen_basic/result/result_none.f90',
78+
# 'src/example_fgen_basic/result/result_dp.f90',
79+
# 'src/example_fgen_basic/result/result_dp_manager.f90',
80+
# 'src/example_fgen_basic/result/result_int.f90',
81+
# 'src/example_fgen_basic/result/result_int_manager.f90',
82+
# 'src/example_fgen_basic/result/result_int1D.f90',
8283
)
8384

8485
# All Python files (wrappers and otherwise)
@@ -95,8 +96,7 @@ if pyprojectwheelbuild_enabled
9596
'src/example_fgen_basic/pyfgen_runtime/__init__.py',
9697
'src/example_fgen_basic/pyfgen_runtime/exceptions.py',
9798
'src/example_fgen_basic/result/__init__.py',
98-
'src/example_fgen_basic/result/result_dp.py',
99-
'src/example_fgen_basic/result/result_int.py',
99+
'src/example_fgen_basic/result/result_gen.py',
100100
'src/example_fgen_basic/typing.py',
101101
)
102102

src/example_fgen_basic/get_square_root.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module m_get_square_root
33

44
use kind_parameters, only: dp
55
use m_error_v, only: ErrorV
6-
use m_result_dp, only: ResultDP
6+
use m_result_gen, only: ResultGen, T_DP, T_ERR
77

88
implicit none
99
private
@@ -18,17 +18,17 @@ function get_square_root(inv) result(res)
1818
real(kind=dp), intent(in) :: inv
1919
!! Frequency
2020

21-
type(ResultDP) :: res
21+
type(ResultGen) :: res
2222
!! Result
2323
!!
2424
!! Square root if the number is positive or zero.
2525
!! Error otherwise.
2626

2727
if (inv >= 0) then
28-
res = ResultDP(data_v=sqrt(inv))
28+
res = ResultGen(tag=T_DP,data_dp=sqrt(inv))
2929
else
3030
! TODO: include input value in the message
31-
res = ResultDP(error_v=ErrorV(code=1, message="Input value was negative"))
31+
res = ResultGen(tag=T_ERR,error_v=ErrorV(code=1, message="Input value was negative"))
3232
end if
3333

3434
end function get_square_root

src/example_fgen_basic/get_square_root.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
CompiledExtensionNotFoundError,
99
FortranError,
1010
)
11-
from example_fgen_basic.result import ResultDP
11+
12+
# from example_fgen_basic.result import ResultDP
13+
from example_fgen_basic.result import ResultGen
1214

1315
try:
1416
from example_fgen_basic._lib import m_get_square_root_w # type: ignore
@@ -18,11 +20,9 @@
1820
) from exc
1921

2022
try:
21-
from example_fgen_basic._lib import m_result_dp_w
23+
from example_fgen_basic._lib import m_result_w
2224
except (ModuleNotFoundError, ImportError) as exc: # pragma: no cover
23-
raise CompiledExtensionNotFoundError(
24-
"example_fgen_basic._lib.m_result_dp_w"
25-
) from exc
25+
raise CompiledExtensionNotFoundError("example_fgen_basic._lib.m_result_w") from exc
2626

2727

2828
def get_square_root(inv: float) -> float:
@@ -47,11 +47,11 @@ def get_square_root(inv: float) -> float:
4747
TODO: use a more specific error
4848
"""
4949
result_instance_index: int = m_get_square_root_w.get_square_root(inv)
50-
result = ResultDP.from_instance_index(result_instance_index)
50+
result = ResultGen.from_instance_index(result_instance_index)
5151

5252
if result.error_v is not None:
5353
# TODO: be more specific
54-
m_result_dp_w.finalise_instance(result_instance_index)
54+
m_result_w.finalise_instance(result_instance_index)
5555
raise FortranError(result.error_v.message)
5656
# raise LessThanZeroError(result.error_v.message)
5757

@@ -68,6 +68,6 @@ def get_square_root(inv: float) -> float:
6868
# I like the safety of finalising in `from_instance_index`.
6969
# if not finalised(result_instance_index):
7070
# finalise(result_instance_index)
71-
m_result_dp_w.finalise_instance(result_instance_index)
71+
m_result_w.finalise_instance(result_instance_index)
7272

7373
return res

src/example_fgen_basic/get_square_root_wrapper.f90

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
!> Wrapper for interfacing `m_get_square_root` with python
22
module m_get_square_root_w
33

4-
use m_result_int, only: ResultInt
5-
use m_result_dp, only: ResultDP
6-
use m_result_none, only: ResultNone
4+
use m_result_gen, only: ResultGen
75

86
use m_get_square_root, only: o_get_square_root => get_square_root
97

108
! The manager module, which makes this all work
11-
use m_result_dp_manager, only: &
12-
result_dp_manager_get_available_instance_index => get_available_instance_index, &
13-
result_dp_manager_set_instance_index_to => set_instance_index_to, &
14-
result_dp_manager_ensure_instance_array_size_is_at_least => ensure_instance_array_size_is_at_least
9+
use m_result_manager, only: &
10+
result_manager_get_available_instance_index => get_available_instance_index, &
11+
result_manager_set_instance_index_to => set_instance_index_to, &
12+
result_manager_ensure_instance_array_size_is_at_least => ensure_instance_array_size_is_at_least
1513

1614
implicit none
1715
private
@@ -32,16 +30,17 @@ function get_square_root(inv) result(res_instance_index)
3230
integer :: res_instance_index
3331
!! Instance index of the result type
3432

35-
type(ResultDP) :: res
36-
type(ResultInt) :: res_get_available_instance_index
37-
type(ResultNone) :: res_chk
33+
type(ResultGen) :: res
34+
type(ResultGen) :: res_get_available_instance_index
35+
type(ResultGen) :: res_chk
3836

3937
res = o_get_square_root(inv)
4038

41-
call result_dp_manager_ensure_instance_array_size_is_at_least(1)
39+
call result_manager_ensure_instance_array_size_is_at_least(1)
4240

4341
! Get the instance index to return to Python
44-
res_get_available_instance_index = result_dp_manager_get_available_instance_index()
42+
! res_get_available_instance_index = result_dp_manager_get_available_instance_index()
43+
call result_manager_get_available_instance_index(res_instance_index,res_chk)
4544

4645
! Logic here is trickier.
4746
! If you can't create a result type to return to Python,
@@ -50,9 +49,11 @@ function get_square_root(inv) result(res_instance_index)
5049
! Set the derived type value in the manager's array,
5150
! ready for its attributes to be retrieved from Python.
5251
! MZ it would be probably good to check "res_chk" for errors
53-
res_chk = result_dp_manager_set_instance_index_to(int(res_get_available_instance_index % data_v, kind = 4), res)
52+
! res_chk = result_dp_manager_set_instance_index_to(res_instance_index, res)
53+
call result_manager_set_instance_index_to(instance_index=res_instance_index,&
54+
data_dp=res%data_dp, res_check = res_chk)
5455

55-
res_instance_index = int(res_get_available_instance_index % data_v, kind = 4)
56+
! res_instance_index = int(res_get_available_instance_index % data_v, kind = 4)
5657

5758
end function get_square_root
5859

src/example_fgen_basic/meson.build

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ srcs += files(
99
'fpyfgen/base_finalisable.f90',
1010
'get_wavelength.f90',
1111
'kind_parameters.f90',
12-
'result/result_dp_manager.f90',
13-
'result/result_dp_wrapper.f90',
14-
'result/result_int1D.f90',
15-
'result/result_int_manager.f90',
16-
'result/result_int_wrapper.f90',
17-
'result/result_dp.f90',
18-
'result/result.f90',
19-
'result/result_int.f90',
20-
'result/result_none.f90',
12+
# 'result/result_dp_manager.f90',
13+
# 'result/result_dp_wrapper.f90',
14+
# 'result/result_int1D.f90',
15+
# 'result/result_int_manager.f90',
16+
# 'result/result_int_wrapper.f90',
17+
# 'result/result_dp.f90',
18+
# 'result/result.f90',
19+
# 'result/result_int.f90',
20+
# 'result/result_none.f90',
21+
'result/result_gen.f90',
22+
'result/result_manager.f90',
23+
'result/result_wrapper.f90',
2124
)

src/example_fgen_basic/result/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Definition of result values
33
"""
44

5-
from example_fgen_basic.result.result_dp import ResultDP
6-
from example_fgen_basic.result.result_int import ResultInt
5+
from example_fgen_basic.result.result_gen import ResultGen
76

8-
__all__ = ["ResultDP", "ResultInt"]
7+
__all__ = ["ResultGen"]

src/example_fgen_basic/result/result.f90

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)