# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Dl

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

class TensorAnnotation(object):
    __slots__ = ['_tab']

    @classmethod
    def GetRootAs(cls, buf, offset=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = TensorAnnotation()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsTensorAnnotation(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # TensorAnnotation
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # TensorAnnotation
    def TensorName(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # TensorAnnotation
    def QuantParameterTensorNames(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            x = self._tab.Vector(o)
            x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
            x = self._tab.Indirect(x)
            from FlatBuffers.Dl.StringStringEntry import StringStringEntry
            obj = StringStringEntry()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # TensorAnnotation
    def QuantParameterTensorNamesLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # TensorAnnotation
    def QuantParameterTensorNamesIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        return o == 0

def TensorAnnotationStart(builder):
    builder.StartObject(2)

def Start(builder):
    TensorAnnotationStart(builder)

def TensorAnnotationAddTensorName(builder, tensorName):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(tensorName), 0)

def AddTensorName(builder, tensorName):
    TensorAnnotationAddTensorName(builder, tensorName)

def TensorAnnotationAddQuantParameterTensorNames(builder, quantParameterTensorNames):
    builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(quantParameterTensorNames), 0)

def AddQuantParameterTensorNames(builder, quantParameterTensorNames):
    TensorAnnotationAddQuantParameterTensorNames(builder, quantParameterTensorNames)

def TensorAnnotationStartQuantParameterTensorNamesVector(builder, numElems):
    return builder.StartVector(4, numElems, 4)

def StartQuantParameterTensorNamesVector(builder, numElems):
    return TensorAnnotationStartQuantParameterTensorNamesVector(builder, numElems)

def TensorAnnotationEnd(builder):
    return builder.EndObject()

def End(builder):
    return TensorAnnotationEnd(builder)

import FlatBuffers.Dl.StringStringEntry
try:
    from typing import List
except:
    pass

class TensorAnnotationT(object):

    # TensorAnnotationT
    def __init__(self):
        self.tensorName = None  # type: str
        self.quantParameterTensorNames = None  # type: List[FlatBuffers.Dl.StringStringEntry.StringStringEntryT]

    @classmethod
    def InitFromBuf(cls, buf, pos):
        tensorAnnotation = TensorAnnotation()
        tensorAnnotation.Init(buf, pos)
        return cls.InitFromObj(tensorAnnotation)

    @classmethod
    def InitFromPackedBuf(cls, buf, pos=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
        return cls.InitFromBuf(buf, pos+n)

    @classmethod
    def InitFromObj(cls, tensorAnnotation):
        x = TensorAnnotationT()
        x._UnPack(tensorAnnotation)
        return x

    # TensorAnnotationT
    def _UnPack(self, tensorAnnotation):
        if tensorAnnotation is None:
            return
        self.tensorName = tensorAnnotation.TensorName()
        if not tensorAnnotation.QuantParameterTensorNamesIsNone():
            self.quantParameterTensorNames = []
            for i in range(tensorAnnotation.QuantParameterTensorNamesLength()):
                if tensorAnnotation.QuantParameterTensorNames(i) is None:
                    self.quantParameterTensorNames.append(None)
                else:
                    stringStringEntry_ = FlatBuffers.Dl.StringStringEntry.StringStringEntryT.InitFromObj(tensorAnnotation.QuantParameterTensorNames(i))
                    self.quantParameterTensorNames.append(stringStringEntry_)

    # TensorAnnotationT
    def Pack(self, builder):
        if self.tensorName is not None:
            tensorName = builder.CreateString(self.tensorName)
        if self.quantParameterTensorNames is not None:
            quantParameterTensorNameslist = []
            for i in range(len(self.quantParameterTensorNames)):
                quantParameterTensorNameslist.append(self.quantParameterTensorNames[i].Pack(builder))
            TensorAnnotationStartQuantParameterTensorNamesVector(builder, len(self.quantParameterTensorNames))
            for i in reversed(range(len(self.quantParameterTensorNames))):
                builder.PrependUOffsetTRelative(quantParameterTensorNameslist[i])
            quantParameterTensorNames = builder.EndVector()
        TensorAnnotationStart(builder)
        if self.tensorName is not None:
            TensorAnnotationAddTensorName(builder, tensorName)
        if self.quantParameterTensorNames is not None:
            TensorAnnotationAddQuantParameterTensorNames(builder, quantParameterTensorNames)
        tensorAnnotation = TensorAnnotationEnd(builder)
        return tensorAnnotation
