Skip to content

Commit fcc77a2

Browse files
committed
rm fxpmath dependency
1 parent 86afff3 commit fcc77a2

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

hls4ml/model/optimizer/passes/infer_precision.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from collections.abc import Iterable
33

44
import numpy as np
5-
from fxpmath import Fxp
65

76
from hls4ml.model.optimizer import ConfigurableOptimizerPass
7+
from hls4ml.model.optimizer.passes.bit_exact import minimal_kif
88
from hls4ml.model.types import (
99
FixedPrecisionType,
1010
IntegerPrecisionType,
@@ -618,18 +618,6 @@ def _get_precision_from_constant(value: int | float, max_width=8):
618618
if value == 0:
619619
return FixedPrecisionType(width=1, integer=1, signed=False)
620620

621-
signed = value < 0
622-
absval = abs(value)
623-
# check if power of 2
624-
mantissa, exp = np.frexp(absval)
625-
if mantissa == 0.5: # is it a power of 2?
626-
# One could consider returning an ExponentPrecisionType here.
627-
# Decided on FixedPrecisionType everywhere since ExponentPrecisionType is less supported
628-
return FixedPrecisionType(1 + signed, exp, signed)
629-
630-
# now is the general case. First try Fxp
631-
fxpval = Fxp(value, signed=signed)
632-
if isinstance(fxpval.n_word, int) and fxpval.n_word <= max_width:
633-
return FixedPrecisionType(fxpval.n_word, signed + fxpval.n_int, signed)
634-
635-
return FixedPrecisionType(signed + max_width, signed + exp, signed)
621+
signed, integer, fraction = map(int, minimal_kif(np.array(value)))
622+
width = min(signed + integer + fraction, signed + max_width)
623+
return FixedPrecisionType(width, signed + integer, bool(signed))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ classifiers = [
2525
"Topic :: Software Development :: Libraries :: Python Modules",
2626
]
2727
dynamic = [ "version" ]
28-
dependencies = [ "fxpmath", "h5py", "numpy", "pydigitalwavetools==1.1", "pyyaml", "quantizers" ]
28+
dependencies = [ "h5py", "numpy", "pydigitalwavetools==1.1", "pyyaml", "quantizers" ]
2929

3030
optional-dependencies.da = [ "da4ml>=0.2.1,<=0.4" ]
3131
optional-dependencies.doc = [

0 commit comments

Comments
 (0)