@@ -44,22 +44,36 @@ contains
4444end module numeric_types
4545```
4646
47- Inspect the resolved mapping, then build it :
47+ It is highly recommended to generate the type contract first for inspection :
4848
4949``` bash
50- python3 -m x2py numeric_types.f90 \
51- --wrap \
52- --out-dir build/numeric-types \
53- --json
50+ python3 -m x2py numeric_types.f90 --pyi
5451```
5552
56- It is highly recommended to also generate the type contract first for inspection :
53+ Build the wrapper with :
5754
5855``` bash
59- python3 -m x2py numeric_types.f90 --pyi
56+ python3 -m x2py numeric_types.f90 --out-dir build/numeric-types
6057```
61- Use the semantic types shown in the ` .pyi ` file (e.g. ` Int32 ` , ` Float64 ` , etc.) when calling from Python.
62- The tables below summarize the currently verified mappings.
58+
59+ Here is how to call the generated module from Python:
60+
61+ ``` python
62+ import sys
63+ import numpy as np
64+
65+ sys.path.insert(0 , " build/numeric-types" )
66+ import numeric_types
67+
68+ api = numeric_types.numeric_types
69+
70+ assert api.add_one(np.int32(4 )) == np.int32(5 )
71+ assert api.double(np.float64(1.5 )) == np.float64(3.0 )
72+ assert api.conjugate_value(np.complex128(1.0 + 2.0j )) == np.complex128(1.0 - 2.0j )
73+ assert bool (api.invert(True )) is False
74+ ```
75+
76+ The tables below summarize the currently verified Fortran-to-Python type mappings.
6377
6478## Scalar Mapping
6579
@@ -78,25 +92,6 @@ The tables below summarize the currently verified mappings.
7892| derived type | generated class name | instance of that generated class | arrays of derived types are unsupported |
7993| dummy procedure | ` Callable[[...], T] ` | Python callable with the exact argument/result contract | not applicable |
8094
81-
82- Import the child module and call it with matching values:
83-
84- ``` python
85- import sys
86-
87- import numpy as np
88-
89- sys.path.insert(0 , " build/numeric-types" )
90- import numeric_types
91-
92- api = numeric_types.numeric_types
93-
94- assert api.add_one(np.int32(4 )) == np.int32(5 )
95- assert api.double(np.float64(1.5 )) == np.float64(3.0 )
96- assert api.conjugate_value(np.complex128(1.0 + 2.0j )) == np.complex128(1.0 - 2.0j )
97- assert bool (api.invert(True )) is False
98- ```
99-
10095The checked [ First Wrapped Function] ( ../getting-started/first-wrapped-function.md )
10196uses the same explicit-dtype rule for the smaller ` scale.f90 ` example.
10297
0 commit comments