diff --git a/klamath/basic.py b/klamath/basic.py index e880393..f545090 100644 --- a/klamath/basic.py +++ b/klamath/basic.py @@ -149,7 +149,7 @@ def encode_real8(fnums: NDArray[numpy.float64]) -> NDArray[numpy.uint64]: gds_exp = exp16 + 64 neg_biased = (gds_exp < 0) - gds_mant[neg_biased] >>= (-gds_exp[neg_biased] * 4).astype(numpy.uint16) + gds_mant[neg_biased] >>= (gds_exp[neg_biased] * 4).astype(numpy.uint16) gds_exp[neg_biased] = 0 too_big = (gds_exp > 0x7f) & ~(zero | subnorm) @@ -160,6 +160,7 @@ def encode_real8(fnums: NDArray[numpy.float64]) -> NDArray[numpy.uint64]: real8 = sign | gds_exp_bits | gds_mant real8[zero] = 0 + real8[gds_exp < -14] = 0 # number is too small return real8.astype(numpy.uint64, copy=False) diff --git a/klamath/elements.py b/klamath/elements.py index c0d5567..9a12b7d 100644 --- a/klamath/elements.py +++ b/klamath/elements.py @@ -2,7 +2,6 @@ Functionality for reading/writing elements (geometry, text labels, structure references) and associated properties. """ -import io from typing import IO, TypeVar from collections.abc import Mapping from abc import ABCMeta, abstractmethod @@ -54,8 +53,6 @@ def read_properties(stream: IO[bytes]) -> dict[int, bytes]: if key in properties: raise KlamathError(f'Duplicate property key: {key!r}') properties[key] = value - else: - stream.seek(size, io.SEEK_CUR) size, tag = Record.read_header(stream) return properties diff --git a/klamath/library.py b/klamath/library.py index 8b3ab20..f7b68bd 100644 --- a/klamath/library.py +++ b/klamath/library.py @@ -220,15 +220,10 @@ def scan_hierarchy(stream: IO[bytes]) -> dict[bytes, dict[bytes, int]]: colrow = COLROW.read_data(stream, size) ref_count = colrow[0] * colrow[1] elif tag == ENDEL.tag: - if ref_name is not None: - if ref_count is None: - ref_count = 1 - cur_structure[ref_name] += ref_count - ref_name = None - ref_count = None - elif tag in (SREF.tag, AREF.tag): - ref_name = None - ref_count = None + if ref_count is None: + ref_count = 1 + assert ref_name is not None + cur_structure[ref_name] += ref_count else: stream.seek(size, io.SEEK_CUR) size, tag = Record.read_header(stream)