Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
import re
from ..optimizer import OptimizerPass
import hls4ml.model.hls_model as hls_model
import hls4ml.model.templates as templates
class BatchNormalizationQuantizedTanh(hls_model.Layer):
''' Merged Batch Normalization and quantized (binary or ternary) Tanh layer.
The mean, variance, beta, gamma parameters are folded into the threshold(s) at which the
sign of the input flips after the quantized (binary or ternary) Tanh activation.
'''
def initialize(self):
inp = self.get_input_variable()
shape = inp.shape
dims = inp.dim_names
precision_bits = re.search('.+<(.+?)>', inp.type.precision).group(1).split(',')
if 'ap_int' in inp.type.precision:
W = int(precision_bits[0])
I = W
F = 0
elif 'ap_fixed' in inp.type.precision:
W = int(precision_bits[0])