msl.examples.loadlib.dotnet32 module
A wrapper around a 32-bit .NET library, dotnet_lib32.
Example of a server that loads a 32-bit .NET library, dotnet_lib32.dll
in a 32-bit Python interpreter to host the library. The corresponding dotnet64
module can be executed by a 64-bit Python interpreter and the DotNet64
class can send a request to the DotNet32
class which calls the
32-bit library to execute the request and then return the response from the library.
- class msl.examples.loadlib.dotnet32.DotNet32(host, port, **kwargs)[source]
Bases:
Server32
Example of a class that is a wrapper around a 32-bit .NET Framework library, dotnet_lib32.dll. Python for .NET can handle many native Python data types as input arguments.
Note
Any class that is a subclass of
Server32
MUST provide two arguments in its constructor: host and port (in that order) and **kwargs. Otherwise theserver32
executable, seestart_server32
, cannot create an instance of theServer32
subclass.- get_class_names()[source]
Returns the class names in the library.
See the corresponding 64-bit
get_class_names()
method.- Returns:
list
ofstr
– The names of the classes that are available in dotnet_lib32.dll.
- add_integers(a, b)[source]
Add two integers.
The corresponding C# code is
public int add_integers(int a, int b) { return a + b; }
See the corresponding 64-bit
add_integers()
method.
- divide_floats(a, b)[source]
Divide two C# floating-point numbers.
The corresponding C# code is
public float divide_floats(float a, float b) { return a / b; }
See the corresponding 64-bit
divide_floats()
method.
- multiply_doubles(a, b)[source]
Multiply two C# double-precision numbers.
The corresponding C# code is
public double multiply_doubles(double a, double b) { return a * b; }
See the corresponding 64-bit
multiply_doubles()
method.
- add_or_subtract(a, b, do_addition)[source]
Add or subtract two C# double-precision numbers.
The corresponding C# code is
public double add_or_subtract(double a, double b, bool do_addition) { if (do_addition) { return a + b; } else { return a - b; } }
See the corresponding 64-bit
add_or_subtract()
method.
- scalar_multiply(a, xin)[source]
Multiply each element in an array by a number.
The corresponding C# code is
public double[] scalar_multiply(double a, double[] xin) { int n = xin.GetLength(0); double[] xout = new double[n]; for (int i = 0; i < n; i++) { xout[i] = a * xin[i]; } return xout; }
See the corresponding 64-bit
scalar_multiply()
method.
- multiply_matrices(a1, a2)[source]
Multiply two matrices.
The corresponding C# code is
public double[,] multiply_matrices(double[,] A, double[,] B) { int rA = A.GetLength(0); int cA = A.GetLength(1); int rB = B.GetLength(0); int cB = B.GetLength(1); double temp = 0; double[,] C = new double[rA, cB]; if (cA != rB) { Console.WriteLine("matrices can't be multiplied!"); return new double[0, 0]; } else { for (int i = 0; i < rA; i++) { for (int j = 0; j < cB; j++) { temp = 0; for (int k = 0; k < cA; k++) { temp += A[i, k] * B[k, j]; } C[i, j] = temp; } } return C; } }
See the corresponding 64-bit
multiply_matrices()
method.
- reverse_string(original)[source]
Reverse a string.
The corresponding C# code is
public string reverse_string(string original) { char[] charArray = original.ToCharArray(); Array.Reverse(charArray); return new string(charArray); }
See the corresponding 64-bit
reverse_string()
method.
- add_multiple(a, b, c, d, e)[source]
Add multiple integers. Calls a static method in a static class.
The corresponding C# code is
public static int add_multiple(int a, int b, int c, int d, int e) { return a + b + c + d + e; }
See the corresponding 64-bit
add_multiple()
method.
- concatenate(a, b, c, d, e)[source]
Concatenate strings. Calls a static method in a static class.
The corresponding C# code is
public static string concatenate(string a, string b, string c, bool d, string e) { string res = a + b + c; if (d) { res += e; } return res; }
See the corresponding 64-bit
concatenate()
method.