101 lines
3.9 KiB
Python
101 lines
3.9 KiB
Python
# /* ******************************************************************************
|
|
# *
|
|
# *
|
|
# * This program and the accompanying materials are made available under the
|
|
# * terms of the Apache License, Version 2.0 which is available at
|
|
# * https://www.apache.org/licenses/LICENSE-2.0.
|
|
# *
|
|
# * See the NOTICE file distributed with this work for additional
|
|
# * information regarding copyright ownership.
|
|
# * Unless required by applicable law or agreed to in writing, software
|
|
# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# * License for the specific language governing permissions and limitations
|
|
# * under the License.
|
|
# *
|
|
# * SPDX-License-Identifier: Apache-2.0
|
|
# ******************************************************************************/
|
|
|
|
import flatbuffers
|
|
|
|
class FlatArray(object):
|
|
__slots__ = ['_tab']
|
|
|
|
@classmethod
|
|
def GetRootAsFlatArray(cls, buf, offset):
|
|
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
|
x = FlatArray()
|
|
x.Init(buf, n + offset)
|
|
return x
|
|
|
|
# FlatArray
|
|
def Init(self, buf, pos):
|
|
self._tab = flatbuffers.table.Table(buf, pos)
|
|
|
|
# FlatArray
|
|
def Shape(self, j):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
|
if o != 0:
|
|
a = self._tab.Vector(o)
|
|
return self._tab.Get(flatbuffers.number_types.Int64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
|
|
return 0
|
|
|
|
# FlatArray
|
|
def ShapeAsNumpy(self):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
|
if o != 0:
|
|
return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int64Flags, o)
|
|
return 0
|
|
|
|
# FlatArray
|
|
def ShapeLength(self):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
|
if o != 0:
|
|
return self._tab.VectorLen(o)
|
|
return 0
|
|
|
|
# FlatArray
|
|
def Buffer(self, j):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
|
if o != 0:
|
|
a = self._tab.Vector(o)
|
|
return self._tab.Get(flatbuffers.number_types.Int8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1))
|
|
return 0
|
|
|
|
# FlatArray
|
|
def BufferAsNumpy(self):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
|
if o != 0:
|
|
return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int8Flags, o)
|
|
return 0
|
|
|
|
# FlatArray
|
|
def BufferLength(self):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
|
if o != 0:
|
|
return self._tab.VectorLen(o)
|
|
return 0
|
|
|
|
# FlatArray
|
|
def Dtype(self):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
|
|
if o != 0:
|
|
return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
|
|
return 0
|
|
|
|
# FlatArray
|
|
def ByteOrder(self):
|
|
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
|
|
if o != 0:
|
|
return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
|
|
return 0
|
|
|
|
def FlatArrayStart(builder): builder.StartObject(4)
|
|
def FlatArrayAddShape(builder, shape): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(shape), 0)
|
|
def FlatArrayStartShapeVector(builder, numElems): return builder.StartVector(8, numElems, 8)
|
|
def FlatArrayAddBuffer(builder, buffer): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(buffer), 0)
|
|
def FlatArrayStartBufferVector(builder, numElems): return builder.StartVector(1, numElems, 1)
|
|
def FlatArrayAddDtype(builder, dtype): builder.PrependInt8Slot(2, dtype, 0)
|
|
def FlatArrayAddByteOrder(builder, byteOrder): builder.PrependInt8Slot(3, byteOrder, 0)
|
|
def FlatArrayEnd(builder): return builder.EndObject()
|