# Path: qkeras/qtools/generate_layer_data_type_map.py
# KERAS_LAYERS = [
#     "Dense",
#     "Conv1D",
#     "Conv2D",
#     "DepthwiseConv2D",
#     "SeparableConv2D",
#     "OctaveConv2D",
# ]
# 
# Path: qkeras/qtools/generate_layer_data_type_map.py
# QKERAS_LAYERS = [
#     "QDense",
#     "QConv1D",
#     "QConv2D",
#     "QDepthwiseConv2D",
#     "QSeparableConv2D",
#     "QOctaveConv2D",
# ]
# 
# Path: qkeras/qtools/quantized_operators/quantizer_impl.py
# class IQuantizer(abc.ABC):
#   """abstract class for quantizer."""
# 
#   def __init__(self):
#     self.mode = -1
#     self.bits = -1
#     self.int_bits = -1
#     self.is_signed = 0
#     self.is_floating_point = False
#     self.max_val_po2 = -1
#     self.is_po2 = 0
#     self.name = None
#     self.op_type = "quantizer"
# 
# Path: qkeras/qtools/settings.py
# class ConfigClass:
#   def __init__(self):
#   def update(self, process, cfg_setting):


import numpy as np
from qkeras.qtools.generate_layer_data_type_map import KERAS_LAYERS
from qkeras.qtools.generate_layer_data_type_map import QKERAS_LAYERS
from qkeras.qtools.quantized_operators.quantizer_impl import IQuantizer
from qkeras.qtools.settings import cfg
# limitations under the License.
# ==============================================================================
"""Calculate energy consumption of a given quantized model."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



# Model based on：
#   Mark Horowitz, Computing’s Energy Problem (and what we can
#   do about it). IEEE ISSCC, pp. 10–14, 2014
#   www.youtube.com/watch?v=eZdOkDtYMoo&feature=youtu.be&t=497

# all metrics converted to pJ/bit

OP = {
    "fp32": {
        "add": lambda x: max(cfg.fp32_add(x), 0),
        "mul": lambda x: max(cfg.fp32_mul(x), 0)
    },
    "fp16": {
        "add": lambda x: max(cfg.fp16_add(x), 0),
        "mul": lambda x: max(cfg.fp16_mul(x), 0)
    },
    "fpm": {
        "add": lambda x: max(cfg.fpm_add(x), 0),
        "mux": lambda x: max(cfg.fpm_add(x), 0),
        "xor": lambda x: max(cfg.fpm_add(x), 0),

# Path: qkeras/qtools/generate_layer_data_type_map.py
# KERAS_LAYERS = [
#     "Dense",
#     "Conv1D",
#     "Conv2D",
#     "DepthwiseConv2D",
#     "SeparableConv2D",
#     "OctaveConv2D",
# ]
# 
# Path: qkeras/qtools/generate_layer_data_type_map.py
# QKERAS_LAYERS = [
#     "QDense",
#     "QConv1D",
#     "QConv2D",
#     "QDepthwiseConv2D",
#     "QSeparableConv2D",
#     "QOctaveConv2D",
# ]
# 
# Path: qkeras/qtools/quantized_operators/quantizer_impl.py
# class IQuantizer(abc.ABC):
#   """abstract class for quantizer."""
# 
#   def __init__(self):
#     self.mode = -1
#     self.bits = -1
#     self.int_bits = -1
#     self.is_signed = 0
#     self.is_floating_point = False
#     self.max_val_po2 = -1
#     self.is_po2 = 0
#     self.name = None
#     self.op_type = "quantizer"
# 
# Path: qkeras/qtools/settings.py
# class ConfigClass:
#   def __init__(self):
#   def update(self, process, cfg_setting):


# Path: qkeras/qtools/qenergy/qenergy.py
import numpy as np
from qkeras.qtools.generate_layer_data_type_map import KERAS_LAYERS
from qkeras.qtools.generate_layer_data_type_map import QKERAS_LAYERS
from qkeras.qtools.quantized_operators.quantizer_impl import IQuantizer
from qkeras.qtools.settings import cfg

# limitations under the License.
# ==============================================================================
"""Calculate energy consumption of a given quantized model."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



# Model based on：
#   Mark Horowitz, Computing’s Energy Problem (and what we can
#   do about it). IEEE ISSCC, pp. 10–14, 2014
#   www.youtube.com/watch?v=eZdOkDtYMoo&feature=youtu.be&t=497

# all metrics converted to pJ/bit

OP = {
    "fp32": {
        "add": lambda x: max(cfg.fp32_add(x), 0),
        "mul": lambda x: max(cfg.fp32_mul(x), 0)
    },
    "fp16": {
        "add": lambda x: max(cfg.fp16_add(x), 0),
        "mul": lambda x: max(cfg.fp16_mul(x), 0)
    },
    "fpm": {
        "add": lambda x: max(cfg.fpm_add(x), 0),
        "mux": lambda x: max(cfg.fpm_add(x), 0),
        "xor": lambda x: max(cfg.fpm_add(x), 0),

        "and": lambda x: max(cfg.fpm_add(x), 0),