Compare commits

..

1 Commits

Author SHA1 Message Date
jan
14f795e592 add file formats tag 2025-12-30 02:52:40 -08:00
2 changed files with 8 additions and 13 deletions

View File

@ -17,11 +17,6 @@ logger = logging.getLogger(__name__)
class KlamathError(Exception):
pass
try:
from klamath_rs_ext import pack_int2, pack_int4
_USE_RS_EXT = True
except ImportError:
_USE_RS_EXT = False
#
# Parse functions
@ -98,14 +93,14 @@ def pack_bitarray(data: int) -> bytes:
return struct.pack('>H', data)
def _pack_int2(data: NDArray[numpy.integer] | Sequence[int] | int) -> bytes:
def pack_int2(data: NDArray[numpy.integer] | Sequence[int] | int) -> bytes:
arr = numpy.asarray(data)
if (arr > 32767).any() or (arr < -32768).any():
raise KlamathError(f'int2 data out of range: {arr}')
return arr.astype('>i2').tobytes()
def _pack_int4(data: NDArray[numpy.integer] | Sequence[int] | int) -> bytes:
def pack_int4(data: NDArray[numpy.integer] | Sequence[int] | int) -> bytes:
arr = numpy.asarray(data)
if (arr > 2147483647).any() or (arr < -2147483648).any():
raise KlamathError(f'int4 data out of range: {arr}')
@ -194,9 +189,3 @@ def read(stream: IO[bytes], size: int) -> bytes:
if len(data) != size:
raise EOFError
return data
if not _USE_RS_EXT:
pack_int2 = _pack_int2
pack_int4 = _pack_int4

View File

@ -44,6 +44,7 @@ classifiers = [
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
"Topic :: File Formats",
]
requires-python = ">=3.11"
include = [
@ -54,6 +55,11 @@ dependencies = [
"numpy>=1.26",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
path = "klamath/__init__.py"