fixedpoint package uses standard logging constructs to generate
warnings and debug logs. The following specifications allow you to customize
the logging schemes, handlers, formats, etc. to your liking.
fixedpoint warnings are generated using the
stream is set to
level is set to logging.DEBUG.
name is FP.CONSOLE
level defaults to logging.WARNING
You can retrieve this logger with
WARNER_CONSOLE_HANDLER is added to
FixedPoint object has a unique
serial number associated with it that is available in the
LogRecord instance as the key sn. This is described in
more detail here as the extra
Logging is also used for debug purposes.
name is FP
level defaults to logging.CRITICAL
filename is set to fixedpoint.log located in the same directory as the source code
mode is set to ‘w’
delay is set to True, thus no file is generated (or overwritten) until logging is enabled with
level defaults to logging.DEBUG
DEFAULT_FILE_HANDLER is added to the
On initial import,
LOGGER’s level is set to logging.CRITICAL. Since
no critical level logs are made within
fixedpoint, it essentially
disables debug logging.
FixedPoint.enable_logging() is called,
LOGGER’s level is set to logging.DEBUG.
FixedPoint.disable_logging() is called,
LOGGER’s level is set back to logging.CRITICAL.
fixedpoint package is typed (see PEP 484) and supported by
FixedPoint is also supported.
While not specifically tested, integration with
numpy should be possible as
long as unsupported operators (like
%, etc.) are not
Examples taken from the
>>> import numpy as np >>> a = [FixedPoint(1), FixedPoint(2), FixedPoint(3)] >>> b = [FixedPoint(0), FixedPoint(1), FixedPoint(0.5)] >>> x = np.convolve(a, b) >>> [float(fp) for fp in x] [0.0, 1.0, 2.5, 4.0, 1.5] >>> y = np.convolve(a, b, 'same') >>> [float(fp) for fp in y] [1.0, 2.5, 4.0] >>> z = np.convolve(a, b, 'valid') >>> [float(fp) for fp in z] [2.5]
>>> from fixedpoint.json import FixedPointEncoder, FixedPointDecoder >>> import random, json >>> L = 52 >>> signed = random.randrange(2) >>> m = random.randrange(L) >>> n = L - m >>> original = FixedPoint(hex(random.getrandbits(L)), signed, m, n) >>> serialized = json.dumps(original, cls=FixedPointEncoder) >>> deserialized = json.loads(serialized, cls=FixedPointDecoder) >>> original == deserialized True
pickle scheme works out of the box:
>>> import random, pickle >>> L = 52 >>> signed = random.randrange(2) >>> m = random.randrange(signed, L) >>> n = L - m >>> original = FixedPoint(hex(random.getrandbits(L)), signed, m, n) >>> pickled = pickle.dumps(original) >>> unpickled = pickle.loads(pickled) >>> original == unpickled True