Browse Source

typing and docs for interpret, mvarray

devel
stefan 1 day ago
parent
commit
f5af7ec3d9
  1. 2
      src/kyupy/__init__.py
  2. 3
      src/kyupy/circuit.py
  3. 11
      src/kyupy/logic.py

2
src/kyupy/__init__.py

@ -12,6 +12,8 @@ import gzip
import numpy as np import numpy as np
type NestedNumericList = list['int|NestedNumericList']
type NestedStrIntDict = dict[str,'int|NestedStrIntDict']
_pop_count_lut = np.asarray([bin(x).count('1') for x in range(256)]) _pop_count_lut = np.asarray([bin(x).count('1') for x in range(256)])

3
src/kyupy/circuit.py

@ -17,8 +17,7 @@ import re
import numpy as np import numpy as np
type NestedNumericList = list['int|NestedNumericList'] from . import NestedNumericList, NestedStrIntDict
type NestedStrIntDict = dict[str,'int|NestedStrIntDict']
class GrowingList[T](list[T]): class GrowingList[T](list[T]):
def __setitem__(self, index, value): def __setitem__(self, index, value):

11
src/kyupy/logic.py

@ -49,7 +49,7 @@ from collections.abc import Iterable
import numpy as np import numpy as np
from numpy.typing import DTypeLike from numpy.typing import DTypeLike
from . import numba, hr_bytes from . import numba, hr_bytes, NestedNumericList
ZERO = 0b000 ZERO = 0b000
@ -104,7 +104,7 @@ _mv_merge = np.array([[0,0,0,1,1,1,1,1], # 0
], dtype=np.uint8) ], dtype=np.uint8)
def interpret(value): def interpret(value) -> int|NestedNumericList:
"""Converts characters, strings, and lists of them to lists of logic constants defined above. """Converts characters, strings, and lists of them to lists of logic constants defined above.
:param value: A character (string of length 1), Boolean, Integer, None, or Iterable. :param value: A character (string of length 1), Boolean, Integer, None, or Iterable.
@ -123,11 +123,12 @@ def interpret(value):
return UNKNOWN return UNKNOWN
def mvarray(*a): def mvarray(*a) -> np.ndarray[tuple[int]|tuple[int,int],np.dtype[np.uint8]]:
"""Converts (lists of) Boolean values or strings into a multi-valued array. """Converts (lists of) Boolean values or strings into a multi-valued array.
The given values are interpreted and the axes are arranged as per KyuPy's convention. Iterable over characters, Booleans, Integers (0,1), None are interpreted as a single pattern.
Use this function to convert strings into multi-valued arrays. Multi-character strings are Iterables over characters and are interpreted as a single pattern.
Lists of said patterns form a pattern set as ndarray with the axes are arranged as per KyuPy's convention.
""" """
mva = np.array(interpret(a), dtype=np.uint8) mva = np.array(interpret(a), dtype=np.uint8)
if mva.ndim < 2: return mva if mva.ndim < 2: return mva

Loading…
Cancel
Save