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.

Parameters:
  • host (str) – The IP address of the server.

  • port (int) – The port to open on the server.

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 the server32 executable, see start_server32, cannot create an instance of the Server32 subclass.

get_class_names()[source]

Returns the class names in the library.

See the corresponding 64-bit get_class_names() method.

Returns:

list of str – 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.

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

  • b (int) – The second integer.

Returns:

int – The sum of a and b.

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.

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

  • b (float) – The second number.

Returns:

float – The quotient of a / b.

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.

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

  • b (float) – The second number.

Returns:

float – The product of a * b.

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.

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

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

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

Returns:

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

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.

Parameters:
  • a (float) – The scalar value.

  • xin (list of float) – The array to modify.

Returns:

list of float – A new array with each element in xin multiplied by a.

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.

Parameters:
Returns:

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

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.

Parameters:

original (str) – The original string.

Returns:

str – The string reversed.

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.

Parameters:
  • a (int) – An integer.

  • b (int) – An integer.

  • c (int) – An integer.

  • d (int) – An integer.

  • e (int) – An integer.

Returns:

int – The sum of the input arguments.

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.

Parameters:
  • a (str) – A string.

  • b (str) – A string.

  • c (str) – A string.

  • d (bool) – Whether to include e in the concatenation.

  • e (str) – A string.

Returns:

str – The strings concatenated together.