Skip to content

Fortran64¤

Communicates with the fortran_lib library via the Fortran32 class that is running on a server.

Fortran64 ¤

Fortran64()

Bases: Client64

Communicates with a 32-bit FORTRAN library.

This class demonstrates how to communicate with a 32-bit FORTRAN library if an instance of this class is created within a 64-bit Python interpreter.

Source code in src/msl/examples/loadlib/fortran64.py
17
18
19
20
21
22
23
24
25
def __init__(self) -> None:
    """Communicates with the 32-bit .NET [fortran_lib][fortran-lib] library.

    This class demonstrates how to communicate with a 32-bit FORTRAN library if an
    instance of this class is created within a 64-bit Python interpreter.
    """
    # specify the name of the corresponding 32-bit server module, fortran32, which hosts
    # the 32-bit FORTRAN library -- fortran_lib32.
    super().__init__(module32="fortran32", append_sys_path=Path(__file__).parent)

add_1d_arrays ¤

add_1d_arrays(a1, a2)

Perform an element-wise addition of two 1D double-precision arrays.

See the corresponding Fortran32.add_1d_arrays method.

Parameters:

Name Type Description Default
a1 Sequence[float]

First array.

required
a2 Sequence[float]

Second array.

required

Returns:

Type Description
list[float]

The element-wise addition of a1 + a2.

Source code in src/msl/examples/loadlib/fortran64.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def add_1d_arrays(self, a1: Sequence[float], a2: Sequence[float]) -> list[float]:
    """Perform an element-wise addition of two 1D double-precision arrays.

    See the corresponding [Fortran32.add_1d_arrays][msl.examples.loadlib.fortran32.Fortran32.add_1d_arrays] method.

    Args:
        a1: First array.
        a2: Second array.

    Returns:
        The element-wise addition of `a1 + a2`.
    """
    reply: list[float] = self.request32("add_1d_arrays", a1, a2)
    return reply

add_or_subtract ¤

add_or_subtract(a, b, *, do_addition)

Add or subtract two integers.

See the corresponding Fortran32.add_or_subtract method.

Parameters:

Name Type Description Default
a int

First integer.

required
b int

Second integer.

required
do_addition bool

Whether to add or subtract the numbers.

required

Returns:

Type Description
int

a + b if do_addition is True else a - b.

Source code in src/msl/examples/loadlib/fortran64.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def add_or_subtract(self, a: int, b: int, *, do_addition: bool) -> int:
    """Add or subtract two integers.

    See the corresponding [Fortran32.add_or_subtract][msl.examples.loadlib.fortran32.Fortran32.add_or_subtract]
    method.

    Args:
        a: First integer.
        b: Second integer.
        do_addition: Whether to add or subtract the numbers.

    Returns:
        `a + b` if `do_addition` is `True` else `a - b`.
    """
    reply: int = self.request32("add_or_subtract", a, b, do_addition=do_addition)
    return reply

besselJ0 ¤

besselJ0(x)

Compute the Bessel function of the first kind of order 0 of x.

See the corresponding Fortran32.besselJ0 method.

Parameters:

Name Type Description Default
x float

The value to compute BESSEL_J0 of.

required

Returns:

Type Description
float

The value of BESSEL_J0(x).

Source code in src/msl/examples/loadlib/fortran64.py
180
181
182
183
184
185
186
187
188
189
190
191
192
def besselJ0(self, x: float) -> float:  # noqa: N802
    """Compute the Bessel function of the first kind of order 0 of x.

    See the corresponding [Fortran32.besselJ0][msl.examples.loadlib.fortran32.Fortran32.besselJ0] method.

    Args:
        x: The value to compute `BESSEL_J0` of.

    Returns:
        The value of `BESSEL_J0(x)`.
    """
    reply: float = self.request32("besselJ0", x)
    return reply

factorial ¤

factorial(n)

Compute the n'th factorial.

See the corresponding Fortran32.factorial method.

Parameters:

Name Type Description Default
n int

The integer to computer the factorial of. The maximum allowed value is 127.

required

Returns:

Type Description
float

The factorial of n.

Source code in src/msl/examples/loadlib/fortran64.py
150
151
152
153
154
155
156
157
158
159
160
161
162
def factorial(self, n: int) -> float:
    """Compute the n'th factorial.

    See the corresponding [Fortran32.factorial][msl.examples.loadlib.fortran32.Fortran32.factorial] method.

    Args:
        n: The integer to computer the factorial of. The maximum allowed value is 127.

    Returns:
        The factorial of `n`.
    """
    reply: float = self.request32("factorial", n)
    return reply

is_positive ¤

is_positive(a)

Returns whether the value of the input argument is > 0.

See the corresponding Fortran32.is_positive method.

Parameters:

Name Type Description Default
a float

Double-precision number.

required

Returns:

Type Description
bool

Whether the value of a is > 0.

Source code in src/msl/examples/loadlib/fortran64.py
119
120
121
122
123
124
125
126
127
128
129
130
131
def is_positive(self, a: float) -> bool:
    """Returns whether the value of the input argument is > 0.

    See the corresponding [Fortran32.is_positive][msl.examples.loadlib.fortran32.Fortran32.is_positive] method.

    Args:
        a: Double-precision number.

    Returns:
        Whether the value of `a` is > 0.
    """
    reply: bool = self.request32("is_positive", a)
    return reply

matrix_multiply ¤

matrix_multiply(a1, a2)

Multiply two matrices.

See the corresponding Fortran32.matrix_multiply method.

Parameters:

Name Type Description Default
a1 Sequence[Sequence[float]]

First matrix.

required
a2 Sequence[Sequence[float]]

Second matrix.

required

Returns:

Type Description
list[list[float]]

The product, a1 @ a2.

Source code in src/msl/examples/loadlib/fortran64.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def matrix_multiply(self, a1: Sequence[Sequence[float]], a2: Sequence[Sequence[float]]) -> list[list[float]]:
    """Multiply two matrices.

    See the corresponding [Fortran32.matrix_multiply][msl.examples.loadlib.fortran32.Fortran32.matrix_multiply]
    method.

    Args:
        a1: First matrix.
        a2: Second matrix.

    Returns:
        The product, `a1 @ a2`.
    """
    reply: list[list[float]] = self.request32("matrix_multiply", a1, a2)
    return reply

multiply_float32 ¤

multiply_float32(a, b)

Send a request to multiply two FORTRAN floating-point numbers.

See the corresponding Fortran32.multiply_float32 method.

Parameters:

Name Type Description Default
a float

First floating-point number.

required
b float

Second floating-point number.

required

Returns:

Type Description
float

The product, a * b.

Source code in src/msl/examples/loadlib/fortran64.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def multiply_float32(self, a: float, b: float) -> float:
    """Send a request to multiply two FORTRAN floating-point numbers.

    See the corresponding [Fortran32.multiply_float32][msl.examples.loadlib.fortran32.Fortran32.multiply_float32]
    method.

    Args:
        a: First floating-point number.
        b: Second floating-point number.

    Returns:
        The product, `a * b`.
    """
    reply: float = self.request32("multiply_float32", a, b)
    return reply

multiply_float64 ¤

multiply_float64(a, b)

Send a request to multiply two FORTRAN double-precision numbers.

See the corresponding Fortran32.multiply_float64 method.

Parameters:

Name Type Description Default
a float

First double-precision number.

required
b float

Second double-precision number.

required

Returns:

Type Description
float

The product, a * b.

Source code in src/msl/examples/loadlib/fortran64.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def multiply_float64(self, a: float, b: float) -> float:
    """Send a request to multiply two FORTRAN double-precision numbers.

    See the corresponding [Fortran32.multiply_float64][msl.examples.loadlib.fortran32.Fortran32.multiply_float64]
    method.

    Args:
        a: First double-precision number.
        b: Second double-precision number.

    Returns:
        The product, `a * b`.
    """
    reply: float = self.request32("multiply_float64", a, b)
    return reply

reverse_string ¤

reverse_string(original)

Reverse a string.

See the corresponding Fortran32.reverse_string method.

Parameters:

Name Type Description Default
original str

The original string.

required

Returns:

Type Description
str

The string reversed.

Source code in src/msl/examples/loadlib/fortran64.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def reverse_string(self, original: str) -> str:
    """Reverse a string.

    See the corresponding [Fortran32.reverse_string][msl.examples.loadlib.fortran32.Fortran32.reverse_string]
    method.

    Args:
        original: The original string.

    Returns:
        The string reversed.
    """
    reply: str = self.request32("reverse_string", original)
    return reply

standard_deviation ¤

standard_deviation(data)

Compute the standard deviation.

See the corresponding Fortran32.standard_deviation method.

Parameters:

Name Type Description Default
data Sequence[float]

The values to compute the standard deviation of.

required

Returns:

Type Description
float

The standard deviation of data.

Source code in src/msl/examples/loadlib/fortran64.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def standard_deviation(self, data: Sequence[float]) -> float:
    """Compute the standard deviation.

    See the corresponding
    [Fortran32.standard_deviation][msl.examples.loadlib.fortran32.Fortran32.standard_deviation]
    method.

    Args:
        data: The values to compute the standard deviation of.

    Returns:
        The standard deviation of `data`.
    """
    reply: float = self.request32("standard_deviation", data)
    return reply

sum_16bit ¤

sum_16bit(a, b)

Send a request to add two 16-bit signed integers.

See the corresponding Fortran32.sum_16bit method.

Parameters:

Name Type Description Default
a int

First 16-bit signed integer.

required
b int

Second 16-bit signed integer.

required

Returns:

Type Description
int

The sum, a + b.

Source code in src/msl/examples/loadlib/fortran64.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def sum_16bit(self, a: int, b: int) -> int:
    """Send a request to add two 16-bit signed integers.

    See the corresponding [Fortran32.sum_16bit][msl.examples.loadlib.fortran32.Fortran32.sum_16bit] method.

    Args:
        a: First 16-bit signed integer.
        b: Second 16-bit signed integer.

    Returns:
        The sum, `a + b`.
    """
    reply: int = self.request32("sum_16bit", a, b)
    return reply

sum_32bit ¤

sum_32bit(a, b)

Send a request to add two 32-bit signed integers.

See the corresponding Fortran32.sum_32bit method.

Parameters:

Name Type Description Default
a int

First 32-bit signed integer.

required
b int

Second 32-bit signed integer.

required

Returns:

Type Description
int

The sum, a + b.

Source code in src/msl/examples/loadlib/fortran64.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def sum_32bit(self, a: int, b: int) -> int:
    """Send a request to add two 32-bit signed integers.

    See the corresponding [Fortran32.sum_32bit][msl.examples.loadlib.fortran32.Fortran32.sum_32bit] method.

    Args:
        a: First 32-bit signed integer.
        b: Second 32-bit signed integer.

    Returns:
        The sum, `a + b`.
    """
    reply: int = self.request32("sum_32bit", a, b)
    return reply

sum_64bit ¤

sum_64bit(a, b)

Send a request to add two 64-bit signed integers.

See the corresponding Fortran32.sum_64bit method.

Parameters:

Name Type Description Default
a int

First 64-bit signed integer.

required
b int

Second 64-bit signed integer.

required

Returns:

Type Description
int

The sum, a + b.

Source code in src/msl/examples/loadlib/fortran64.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def sum_64bit(self, a: int, b: int) -> int:
    """Send a request to add two 64-bit signed integers.

    See the corresponding [Fortran32.sum_64bit][msl.examples.loadlib.fortran32.Fortran32.sum_64bit] method.

    Args:
        a: First 64-bit signed integer.
        b: Second 64-bit signed integer.

    Returns:
        The sum, `a + b`.
    """
    reply: int = self.request32("sum_64bit", a, b)
    return reply

sum_8bit ¤

sum_8bit(a, b)

Send a request to add two 8-bit signed integers.

See the corresponding Fortran32.sum_8bit method.

Parameters:

Name Type Description Default
a int

First 8-bit signed integer.

required
b int

Second 8-bit signed integer.

required

Returns:

Type Description
int

The sum, a + b.

Source code in src/msl/examples/loadlib/fortran64.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def sum_8bit(self, a: int, b: int) -> int:
    """Send a request to add two 8-bit signed integers.

    See the corresponding [Fortran32.sum_8bit][msl.examples.loadlib.fortran32.Fortran32.sum_8bit] method.

    Args:
        a: First 8-bit signed integer.
        b: Second 8-bit signed integer.

    Returns:
        The sum, `a + b`.
    """
    reply: int = self.request32("sum_8bit", a, b)
    return reply