diff options
Diffstat (limited to 'nn/runtime/test/specs/V1_3')
-rw-r--r-- | nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py | 43 | ||||
-rw-r--r-- | nn/runtime/test/specs/V1_3/if_simple.mod.py | 29 | ||||
-rw-r--r-- | nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py | 30 | ||||
-rw-r--r-- | nn/runtime/test/specs/V1_3/while_fib.mod.py | 27 | ||||
-rw-r--r-- | nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py | 29 |
5 files changed, 99 insertions, 59 deletions
diff --git a/nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py b/nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py new file mode 100644 index 000000000..189b67c6f --- /dev/null +++ b/nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py @@ -0,0 +1,43 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +# + +# Test with multiple references to the same referenced model. +# Model: z = if (x) then (y + 100) else (y + 100) + +input_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] +output_add = [y + 100 for y in input_data] + +ValueType = ["TENSOR_FLOAT32", [3, 4]] +BoolType = ["TENSOR_BOOL8", [1]] + +def MakeBranchModel(operation_name): + y = Input("y", ValueType) + z = Output("z", ValueType) + return Model().Operation(operation_name, y, [100.0], 0).To(z) + +def Test(x, y, z, name): + x_data, y_data, z_data = x, y, z + x = Input("x", BoolType) + y = Input("y", ValueType) + z = Output("z", ValueType) + then_model = MakeBranchModel("ADD") + else_model = then_model + model = Model().Operation("IF", x, then_model, else_model, y).To(z) + example = Example({x: [x_data], y: y_data, z: z_data}, name=name) + example.AddVariations(AllOutputsAsInternalCoverter()) + +Test(x=True, y=input_data, z=output_add, name="true") +Test(x=False, y=input_data, z=output_add, name="false") diff --git a/nn/runtime/test/specs/V1_3/if_simple.mod.py b/nn/runtime/test/specs/V1_3/if_simple.mod.py index c13446588..1cc717374 100644 --- a/nn/runtime/test/specs/V1_3/if_simple.mod.py +++ b/nn/runtime/test/specs/V1_3/if_simple.mod.py @@ -28,19 +28,16 @@ def MakeBranchModel(operation_name): z = Output("z", ValueType) return Model().Operation(operation_name, y, [100.0], 0).To(z) -x = Input("x", BoolType) -y = Input("y", ValueType) -z = Output("z", ValueType) -then_model = MakeBranchModel("ADD") -else_model = MakeBranchModel("SUB") -model = Model().Operation("IF", x, then_model, else_model, y).To(z) - -Example({x: [True], y: input_data, z: output_add}, name="true", model=model) -Example({x: [False], y: input_data, z: output_sub}, name="false", model=model) - -# Test with multiple references to the same referenced model. -model = Model(name="same_branch_model") -model.Operation("IF", x, then_model, then_model, y).To(z) - -Example({x: [True], y: input_data, z: output_add}, name="true", model=model) -Example({x: [False], y: input_data, z: output_add}, name="false", model=model) +def Test(x, y, z, name): + x_data, y_data, z_data = x, y, z + x = Input("x", BoolType) + y = Input("y", ValueType) + z = Output("z", ValueType) + then_model = MakeBranchModel("ADD") + else_model = MakeBranchModel("SUB") + model = Model().Operation("IF", x, then_model, else_model, y).To(z) + example = Example({x: [x_data], y: y_data, z: z_data}, name=name) + example.AddVariations(AllOutputsAsInternalCoverter()) + +Test(x=True, y=input_data, z=output_add, name="true") +Test(x=False, y=input_data, z=output_sub, name="false") diff --git a/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py b/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py index e4fcb72e8..fac9bea89 100644 --- a/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py +++ b/nn/runtime/test/specs/V1_3/squeeze_quant8_signed.mod.py @@ -21,24 +21,16 @@ output = Output("output", "TENSOR_QUANT8_ASYMM_SIGNED", "{1, 24}, 1.0, -128") model = model.Operation("SQUEEZE", i1, squeezeDims).To(output) -# Example 1. Input in operand 0, -input0 = { - i1: # input 0 - [ - -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, - -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, - -105, -104 - ] -} - -output0 = { - output: # output 0 - [ - -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, - -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, - -105, -104 - ] -} +data = [ + -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, + -111, -110, -109, -108, -107, -106, -105, -104 +] # Instantiate an example -Example((input0, output0)) +Example({i1: data, output: data}) + +# Test with omitted squeeze dims +squeezeDims = Parameter("squeezeDims", ["TENSOR_INT32", [0]], value=None) +output = Output("output", "TENSOR_QUANT8_ASYMM_SIGNED", "{24}, 1.0, -128") +Model("omitted").Operation("SQUEEZE", i1, squeezeDims).To(output) +Example({i1: data, output: data}) diff --git a/nn/runtime/test/specs/V1_3/while_fib.mod.py b/nn/runtime/test/specs/V1_3/while_fib.mod.py index 9f36b06b2..f8f058133 100644 --- a/nn/runtime/test/specs/V1_3/while_fib.mod.py +++ b/nn/runtime/test/specs/V1_3/while_fib.mod.py @@ -53,17 +53,20 @@ def MakeBodyModel(): model.Operation("FULLY_CONNECTED", fib, matrix, zero_bias, 0).To(fib_out) return model -n = Input("n", CounterType) -fib_out = Output("fib_out", FibType) -cond = MakeConditionModel() -body = MakeBodyModel() -fib_init = Parameter("fib_init", FibType, [1, 1]) -i_init = [1] -model = Model().Operation("WHILE", cond, body, fib_init, i_init, n).To(fib_out) +def Test(n, fib): + n_ = Input("n", CounterType) + fib_out = Output("fib_out", FibType) + cond = MakeConditionModel() + body = MakeBodyModel() + fib_init = Parameter("fib_init", FibType, [1, 1]) + i_init = [1] + model = Model().Operation("WHILE", cond, body, fib_init, i_init, n_).To(fib_out) + example = Example({n_: [n], fib_out: fib}, name=str(n), model=model) + example.AddVariations(AllOutputsAsInternalCoverter()) # Fibonacci numbers: 1 1 2 3 5 8 -Example({n: [1], fib_out: [1, 1]}, name="1", model=model) -Example({n: [2], fib_out: [1, 2]}, name="2", model=model) -Example({n: [3], fib_out: [2, 3]}, name="3", model=model) -Example({n: [4], fib_out: [3, 5]}, name="4", model=model) -Example({n: [5], fib_out: [5, 8]}, name="5", model=model) +Test(n=1, fib=[1, 1]) +Test(n=2, fib=[1, 2]) +Test(n=3, fib=[2, 3]) +Test(n=4, fib=[3, 5]) +Test(n=5, fib=[5, 8]) diff --git a/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py b/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py index 3f8a6344f..0adaec476 100644 --- a/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py +++ b/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py @@ -89,16 +89,21 @@ def MakeOuterBodyModel(): model.Operation("ADD", sum, xi, 0).To(sum_out) return model -x = Input("x", DataType) -n = Input("n", CounterType) -sum = Output("sum", DataType) -cond = MakeOuterConditionModel() -body = MakeOuterBodyModel() -sum_init = Parameter("sum_init", DataType, [1, 1]) -i_init = [1] -model = Model().Operation("WHILE", cond, body, sum_init, i_init, n, x).To(sum) +def Test(x, n, sum): + x_data, n_data, sum_data = x, n, sum + x = Input("x", DataType) + n = Input("n", CounterType) + sum = Output("sum", DataType) + cond = MakeOuterConditionModel() + body = MakeOuterBodyModel() + sum_init = Parameter("sum_init", DataType, [1, 1]) + i_init = [1] + model = Model().Operation("WHILE", cond, body, sum_init, i_init, n, x).To(sum) + example = Example({x: x_data, n: [n_data], sum: sum_data}, name=str(n_data)) + example.AddVariations(AllOutputsAsInternalCoverter()) -Example({x: [2, 3], n: [1], sum: [1 + 2, 1 + 3]}, name="1", model=model) -Example({x: [2, 3], n: [2], sum: [1 + 2 + 4, 1 + 3 + 9]}, name="2", model=model) -Example({x: [2, 3], n: [3], sum: [1 + 2 + 4 + 8, 1 + 3 + 9 + 27]}, name="3", model=model) -Example({x: [2, 3], n: [4], sum: [1 + 2 + 4 + 8 + 16, 1 + 3 + 9 + 27 + 81]}, name="4", model=model) +Test(x=[2, 3], n=1, sum=[1 + 2, 1 + 3]) +Test(x=[2, 3], n=1, sum=[1 + 2, 1 + 3]) +Test(x=[2, 3], n=2, sum=[1 + 2 + 4, 1 + 3 + 9]) +Test(x=[2, 3], n=3, sum=[1 + 2 + 4 + 8, 1 + 3 + 9 + 27]) +Test(x=[2, 3], n=4, sum=[1 + 2 + 4 + 8 + 16, 1 + 3 + 9 + 27 + 81]) |