1# model
2model = Model()
3sparseData = Input("sparseData", "TENSOR_FLOAT32", "{4}")
4traversalOrder = Parameter("traversalOrder", "TENSOR_INT32", "{4}", [0, 1, 2, 3])
5blockMap = Parameter("blockMap", "TENSOR_INT32", "{2}", [0, 1])
6dimFormat = Parameter("dimFormat", "TENSOR_INT32", "{4}", [0, 0, 1, 1])
7dimensions = Parameter("dimensions", "TENSOR_INT32", "{4}", [2, 3, 5, 7])
8d0ArrSegments = Parameter("d0ArrSegments", "TENSOR_INT32", "{0}", [])
9d0ArrIndices = Parameter("d0ArrIndices", "TENSOR_INT32", "{0}", [])
10d1ArrSegments = Parameter("d1ArrSegments", "TENSOR_INT32", "{0}", [])
11d1ArrIndices = Parameter("d1ArrIndices", "TENSOR_INT32", "{0}", [])
12d2ArrSegments = Parameter("d2ArrSegments", "TENSOR_INT32", "{7}", [0, 1, 2, 3, 4, 4, 4])
13d2ArrIndices = Parameter("d2ArrIndices", "TENSOR_INT32", "{4}", [1, 2, 3, 1])
14d3ArrSegments = Parameter("d3ArrSegments", "TENSOR_INT32", "{5}", [0, 1, 2, 3, 4])
15d3ArrIndices = Parameter("d3ArrIndices", "TENSOR_INT32", "{4}", [1, 2, 3, 3])
16denseOut = Output("denseOut", "TENSOR_FLOAT32", "{10, 21}")
17model = model.Operation("DENSIFY", sparseData, traversalOrder, blockMap,
18                        dimFormat, dimensions, d0ArrSegments, d0ArrIndices, d1ArrSegments,
19                        d1ArrIndices, d2ArrSegments, d2ArrIndices, d3ArrSegments,
20                        d3ArrIndices).To(denseOut)
21
22# Example 1. Input in operand 0,
23input0 = {sparseData: # input 0
24          [11.0, 13.0, 17.0, 19.0]}
25
26outputData = [0.0] * 210
27outputData[22] = 11.0
28outputData[51] = 13.0
29outputData[80] = 17.0
30outputData[129] = 19.0
31output0 = {denseOut: # output 0
32           outputData}
33
34quant8_symm = DataTypeConverter().Identify({
35    sparseData: ("TENSOR_QUANT8_SYMM", 3.0),
36    denseOut: ("TENSOR_QUANT8_SYMM", 3.0)
37})
38
39quant8_asymm = DataTypeConverter().Identify({
40    sparseData: ("TENSOR_QUANT8_ASYMM", 2.25, 3),
41    denseOut: ("TENSOR_QUANT8_ASYMM", 2.25, 3)
42})
43
44quant8_asymm_signed = DataTypeConverter().Identify({
45    sparseData: ("TENSOR_QUANT8_ASYMM_SIGNED", 2.875, -4),
46    denseOut: ("TENSOR_QUANT8_ASYMM_SIGNED", 2.875, -4)
47})
48
49quant16_symm = DataTypeConverter().Identify({
50    sparseData: ("TENSOR_QUANT16_SYMM", 3.25),
51    denseOut: ("TENSOR_QUANT16_SYMM", 3.25)
52})
53
54quant16_asymm = DataTypeConverter().Identify({
55    sparseData: ("TENSOR_QUANT16_ASYMM", 6.0, 14),
56    denseOut: ("TENSOR_QUANT16_ASYMM", 6.0, 14)
57})
58
59# Instantiate an example
60Example((input0, output0)).AddVariations("relaxed", "float16", "int32", quant8_symm,
61                                        quant8_asymm, quant8_asymm_signed, quant16_symm,
62                                        quant16_asymm)
63