multiplied.core.utils package#

Submodules#

multiplied.core.utils.bool module#

multiplied.core.utils.bool.isalpha(ch: str) bool[source]#

Return True if string is exactly one alphabetic character

multiplied.core.utils.bool.isbbox(bounds: dict[str, list[tuple[int, int]]]) bool[source]#

Return True if dict represents a recognised bounding box.

Notes

Tuple pairs are expected to be in the format: >>> # (start, y), (end, y) >>> […, (x0, y), (x1, y), …]

Examples

>>> isbbox({"a": [(0, 0), (4, 0)]})
True
>>> isbbox({
>>>     "a": [(0, 0), (4, 0)],
>>>     "b": [(0, 0), (4, 0)]})
True
>>> isbbox({"aa": [(0, 0), (4, 0)]})
False
>>> isbbox({"a": [(4, 0)]})
False
>>> isbbox({
>>>     "a": [(0, 0), (4, 0)],
>>>     "b": [(5, 0)]})
False
multiplied.core.utils.bool.ischar(ch: str) bool[source]#

Return True if string is exactly one character

multiplied.core.utils.bool.ishex2(val: str) bool[source]#

Return True if string represents a 2-bit hex value

multiplied.core.utils.bool.isint(source: Any) bool[source]#

Return True if source converts to int

multiplied.core.utils.bool.isppm(nested_list: list[list[str]]) bool[source]#

Return True if nested list represents a Partial Product matrix

multiplied.core.utils.bool.validate_bitwidth(bits: int) None[source]#

Raise ValueError if bitwidth is supported by Multiplied

multiplied.core.utils.char module#

multiplied.core.utils.char.allchars(
matrix: list[list[str]],
*,
hash: list[int | bool] = [],
) set[str][source]#

Returns set of unique characters from a nested list.

Parameters:
  • matrix (list[list[str]]) – Matrix of characters to extract unique characters from.

  • hash (list[int | bool], optional) – List of bools or 0s and 1s indicating if a row contains characters.

Return type:

set[str]

Notes

Ignores underscore characters and converts characters to uppercase

See also

Matrix

Multiplied 2D Matrix Object

Examples

>>> allchars([['A', 'B'], ['C', 'D']])
{'A', 'B', 'C', 'D'}
multiplied.core.utils.char.chargen(start: str = 'A') Generator[str][source]#

Return Generator characters from A to Z.

Yields:

str

Example

>>> x = chargen()
>>> next(x)
'A'
>>> next(x)
'B'
>>> next(x)
'C'
multiplied.core.utils.char.chartff(ch: str) Generator[str][source]#

Generator to flip flop between upper and lowercase characters.

Parameters:

ch (str) – Single alphabetic character to flip flop.

Yields:

str – Upper or lowercase version of the input character.

Raises:

ValueError – If input is not a single alphabetic character.

Examples

>>> x = chartff('a')
>>> next(x)
'a'
>>> next(x)
'A'
>>> next(x)
'a'
multiplied.core.utils.char.infer_matrix_format(
source: list[list[str]],
fmt: str,
) list[list[str]][source]#

Infers the format of a litmus test string and returns a matrix of characters.

Parameters:
  • source (list[list[str]]) – Source matrix to infer format from.

  • fmt (str) – Default char used in each matrix cell.

  • l

Return type:

list[list[str]]

Examples

>>> infer_matrix_format("auto", "FF")  # infer as "map"
[['00', '00', '00', '00'...
>>> infer_matrix_format("auto", "0")   # infer as "empty"
[['_', '_', '_', '_'...
>>> infer_matrix_format("zero", "")  # zero-filled
[['0', '0', '0', '0'...
multiplied.core.utils.char.to_int_array(matrix: list[list[str]]) list[int][source]#

Converts a matrix of characters to a array of integers

Parameters:

matrix (list[list[str]]) – Matrix of characters to convert from 2D Multiplied formatted matrix into to list of integers.

Return type:

list[int]

Examples

>>> to_int_array([['_', '1', '_'], ['1', '0', '1']])
[2, 5]

multiplied.core.utils.pretty module#

multiplied.core.utils.pretty.mprint(matrix: Any)[source]#

Wrapper for print(mp.pretty)

multiplied.core.utils.pretty.pretty(listy_object: Any) str[source]#

Format Multiplied types, or list as a string.

Parameters:

listy_object (Any) – List or Dict style object to format as a string.

Return type:

str

Examples

>>> pretty(mp.Matrix(4))
____0000
___0000_
__0000__
_0000___
multiplied.core.utils.pretty.pretty_dict(listy_dict: Any) str[source]#

Format Dict type object as a string:

>>> {0: [[1, _, _],[_, 2, _],[_, _, 3]],
>>>  1: [[a, _, _],[_, b, _],[_, _, c]],
>>>  2: [[x, y, z],[x, y, z],[x, y, z]]}
0:{
1__
_2_
__3
}
...
multiplied.core.utils.pretty.pretty_nested_list(
listy_object: Any,
*,
whitespace=False,
) str[source]#

Format nested list as a string.

Parameters:
  • listy_object (Any) – The nested list to be formatted.

  • whitespace (bool, optional) – Whether to add whitespace between elements, by default False.

Examples

>>> pretty_nested_list([[1, _, _],[_, 2, _],[_, _, 3]])
1__
_2_
__3

Module contents#