1 Commits
Author SHA1 Message Date
stefan f5af7ec3d9 typing and docs for interpret, mvarray 2026-06-27 11:26:23 +09:00
3 changed files with 9 additions and 7 deletions

No files matched your search

+2
View File
@@ -12,6 +12,8 @@ import gzip
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)])
+1 -2
View File
@@ -17,8 +17,7 @@ import re
import numpy as np
type NestedNumericList = list['int|NestedNumericList']
type NestedStrIntDict = dict[str,'int|NestedStrIntDict']
from . import NestedNumericList, NestedStrIntDict
class GrowingList[T](list[T]):
def __setitem__(self, index, value):
+6 -5
View File
@@ -49,7 +49,7 @@ from collections.abc import Iterable
import numpy as np
from numpy.typing import DTypeLike
from . import numba, hr_bytes
from . import numba, hr_bytes, NestedNumericList
ZERO = 0b000
@@ -104,7 +104,7 @@ _mv_merge = np.array([[0,0,0,1,1,1,1,1], # 0
], 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.
:param value: A character (string of length 1), Boolean, Integer, None, or Iterable.
@@ -123,11 +123,12 @@ def interpret(value):
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.
The given values are interpreted and the axes are arranged as per KyuPy's convention.
Use this function to convert strings into multi-valued arrays.
Iterable over characters, Booleans, Integers (0,1), None are interpreted as a single pattern.
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)
if mva.ndim < 2: return mva