msl.examples.loadlib.fortran64 module

Communicates with fortran_lib32 via the Fortran32 class.

Example of a module that can be executed within a 64-bit Python interpreter which can communicate with a 32-bit library, fortran_lib32, that is hosted by a 32-bit Python server, fortran32. A 64-bit process cannot load a 32-bit library and therefore inter-process communication is used to interact with a 32-bit library from a 64-bit process.

Fortran64 is the 64-bit client and Fortran32 is the 32-bit server for inter-process communication.

class msl.examples.loadlib.fortran64.Fortran64[source]

Bases: Client64

Communicates with the 32-bit FORTRAN fortran_lib32 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.

Base class for communicating with a 32-bit library from 64-bit Python.

Starts a 32-bit server, Server32, to host a Python class that is a wrapper around a 32-bit library. Client64 runs within a 64-bit Python interpreter, and it sends a request to the server which calls the 32-bit library to execute the request. The server then provides a response back to the client.

Changed in version 0.6: Added the rpc_timeout argument.

Changed in version 0.8: Added the protocol argument and the default quiet value became None.

Changed in version 0.10: Added the server32_dir argument.

Parameters:
  • module32 (str) – The name of the Python module that is to be imported by the 32-bit server.

  • host (str, optional) – The address of the 32-bit server. Default is '127.0.0.1'.

  • port (int, optional) – The port to open on the 32-bit server. Default is None, which means to automatically find a port that is available.

  • timeout (float, optional) – The maximum number of seconds to wait to establish a connection to the 32-bit server. Default is 10 seconds.

  • quiet (bool, optional) – This keyword argument is no longer used and will be removed in a future release.

  • append_sys_path (str or list of str, optional) – Append path(s) to the 32-bit server’s sys.path variable. The value of sys.path from the 64-bit process is automatically included, i.e., sys.path(32bit) = sys.path(64bit) + append_sys_path.

  • append_environ_path (str or list of str, optional) – Append path(s) to the 32-bit server’s os.environ['PATH'] variable. This can be useful if the library that is being loaded requires additional libraries that must be available on PATH.

  • rpc_timeout (float, optional) – The maximum number of seconds to wait for a response from the 32-bit server. The RPC timeout value is used for all requests from the server. If you want different requests to have different timeout values then you will need to implement custom timeout handling for each method on the server. Default is None, which means to use the default timeout value used by the socket module (which is to wait forever).

  • protocol (int, optional) – The pickle protocol to use. If not specified then determines the value to use based on the version of Python that the Client64 is running in.

  • server32_dir (str, optional) – The directory where the frozen 32-bit server is located.

  • **kwargs – All additional keyword arguments are passed to the Server32 subclass. The data type of each value is not preserved. It will be a string at the constructor of the Server32 subclass.

Note

If module32 is not located in the current working directory then you must either specify the full path to module32 or you can specify the folder where module32 is located by passing a value to the append_sys_path parameter. Using the append_sys_path option also allows for any other modules that module32 may depend on to also be included in sys.path so that those modules can be imported when module32 is imported.

Raises:
  • ConnectionTimeoutError – If the connection to the 32-bit server cannot be established.

  • OSError – If the frozen executable cannot be found.

  • TypeError – If the data type of append_sys_path or append_environ_path is invalid.

sum_8bit(a, b)[source]

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

See the corresponding 32-bit sum_8bit() method.

Parameters:
  • a (int) – The first 8-bit signed integer.

  • b (int) – The second 8-bit signed integer.

Returns:

int – The sum of a and b.

sum_16bit(a, b)[source]

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

See the corresponding 32-bit sum_16bit() method.

Parameters:
  • a (int) – The first 16-bit signed integer.

  • b (int) – The second 16-bit signed integer.

Returns:

int – The sum of a and b.

sum_32bit(a, b)[source]

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

See the corresponding 32-bit sum_32bit() method.

Parameters:
  • a (int) – The first 32-bit signed integer.

  • b (int) – The second 32-bit signed integer.

Returns:

int – The sum of a and b.

sum_64bit(a, b)[source]

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

See the corresponding 32-bit sum_64bit() method.

Parameters:
  • a (int) – The first 64-bit signed integer.

  • b (int) – The second 64-bit signed integer.

Returns:

int – The sum of a and b.

multiply_float32(a, b)[source]

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

See the corresponding 32-bit multiply_float32() method.

Parameters:
  • a (float) – The first floating-point number.

  • b (float) – The second floating-point number.

Returns:

float – The product of a and b.

multiply_float64(a, b)[source]

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

See the corresponding 32-bit multiply_float64() method.

Parameters:
  • a (float) – The first double-precision number.

  • b (float) – The second double-precision number.

Returns:

float – The product of a and b.

is_positive(a)[source]

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

See the corresponding 32-bit is_positive() method.

Parameters:

a (float) – A double-precision number.

Returns:

bool – Whether the value of a is > 0.

add_or_subtract(a, b, do_addition)[source]

Add or subtract two integers.

See the corresponding 32-bit add_or_subtract() method.

Parameters:
  • a (int) – The first integer.

  • b (int) – The second integer.

  • do_addition (bool) – Whether to add the numbers.

Returns:

int – Either a + b if do_addition is True else a - b.

factorial(n)[source]

Compute the n’th factorial.

See the corresponding 32-bit factorial() method.

Parameters:

n (int) – The integer to computer the factorial of. The maximum allowed value is 127.

Returns:

float – The factorial of n.

standard_deviation(data)[source]

Compute the standard deviation.

See the corresponding 32-bit standard_deviation() method.

Parameters:

data (list of float) – The data to compute the standard deviation of.

Returns:

float – The standard deviation of data.

besselJ0(x)[source]

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

See the corresponding 32-bit besselJ0() method.

Parameters:

x (float) – The value to compute BESSEL_J0 of.

Returns:

float – The value of BESSEL_J0(x).

reverse_string(original)[source]

Reverse a string.

See the corresponding 32-bit reverse_string() method.

Parameters:

original (str) – The original string.

Returns:

str – The string reversed.

add_1D_arrays(a1, a2)[source]

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

See the corresponding 32-bit add_1D_arrays() method.

Parameters:
Returns:

list of float – The element-wise addition of a1 + a2.

matrix_multiply(a1, a2)[source]

Multiply two matrices.

See the corresponding 32-bit matrix_multiply() method.

Parameters:
Returns:

list of list of float – The result of a1 * a2.