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)

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 (or hostname) to use for the server.

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

  • kwargs (str) – Optional keyword arguments. The keys and values are of type str.

get_class_names()

Returns the class names in the library.

See the corresponding 64-bit get_class_names() method.

Returns:

The names of the classes that are available in dotnet_lib32.dll.

Return type:

list[str]

add_integers(a, b)

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) – First integer.

  • b (int) – Second integer.

Returns:

The sum of a and b.

Return type:

int

divide_floats(a, b)

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) – First floating-point number.

  • b (float) – Second floating-point number.

Returns:

The quotient of a / b.

Return type:

float

multiply_doubles(a, b)

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) – First double-precision number.

  • b (float) – Second double-precision number.

Returns:

The product of a * b.

Return type:

float

add_or_subtract(a, b, do_addition)

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) – First double-precision number.

  • b (float) – Second double-precision number.

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

Returns:

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

Return type:

float

scalar_multiply(a, xin)

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:
Returns:

A new array with each element in xin multiplied by a.

Return type:

list[float]

multiply_matrices(a1, a2)

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:

The result of a1 * a2.

Return type:

list[list[float]]

reverse_string(original)

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:

The string reversed.

Return type:

str

add_multiple(a, b, c, d, e)

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) – First integer.

  • b (int) – Second integer.

  • c (int) – Third integer.

  • d (int) – Fourth integer.

  • e (int) – Fifth integer.

Returns:

The sum of the input arguments.

Return type:

int

concatenate(a, b, c, d, e)

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) – First string.

  • b (str) – Second string.

  • c (str) – Third string.

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

  • e (str) – Fourth string.

Returns:

The strings concatenated together.

Return type:

str