optimus.utils.conversions

Utilities for data type checks and conversions.

Module Contents

Functions

convert_to_positive_int(value[, label])

Check if the input value can be converted into a positive integer.

convert_to_float(value[, label])

Check if the input value can be converted into a float.

convert_to_positive_float(value[, label, nonnegative])

Check if the input value can be converted into a positive float.

convert_to_array(vector[, shape, label])

Check if the input vector can be converted into an array for the specified

convert_to_complex_array(vector[, shape, label])

Check if the input vector can be converted into an array for the specified

convert_to_3n_array(array[, label])

Convert the input array into a 3xN Numpy array, if possible.

optimus.utils.conversions.convert_to_positive_int(value, label='variable')

Check if the input value can be converted into a positive integer.

Parameters
valueAny

The input value to be converted into a positive integer.

labelstr

The name of the variable.

Returns
valueint

The output value.

optimus.utils.conversions.convert_to_float(value, label='variable')

Check if the input value can be converted into a float.

Parameters
valueAny

The input value to be converted into a float.

labelstr

The name of the variable.

Returns
valuefloat

The output value.

optimus.utils.conversions.convert_to_positive_float(value, label='variable', nonnegative=False)

Check if the input value can be converted into a positive float.

Parameters
valueAny

The input value to be converted into a positive float.

labelstr

The name of the variable.

nonnegativebool

Check for nonnegative instead of strictly positive numbers.

Returns
valuefloat

The output value.

optimus.utils.conversions.convert_to_array(vector, shape=None, label='variable')

Check if the input vector can be converted into an array for the specified shape, and perform the conversion.

Parameters
vectorAny

The input vector to be converted into a Numpy array.

shapetuple[int], None

The output shape of the vector.

labelstr

The name of the variable.

Returns
arraynumpy.ndarray

The output array with the specified shape.

optimus.utils.conversions.convert_to_complex_array(vector, shape=None, label='variable')

Check if the input vector can be converted into an array for the specified shape, and perform the conversion.

Parameters
vectorAny

The input vector to be converted into a Numpy array.

shapetuple[int], None

The output shape of the vector.

labelstr

The name of the variable.

Returns
arraynumpy.ndarray[complex]

The output array with the specified shape.

optimus.utils.conversions.convert_to_3n_array(array, label='variable')

Convert the input array into a 3xN Numpy array, if possible.

Parameters
arrayAny

The input vector to be converted into a 3xN Numpy array.

labelstr

The name of the variable.

Returns
arraynumpy.ndarray

The output array with the shape (3,N).