1#
2# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17def test(name, input0, alpha, output0, input0_data, output0_data):
18  model = Model().Operation("ELU", input0, alpha).To(output0)
19  example = Example({
20      input0: input0_data,
21      output0: output0_data,
22  }, model=model, name=name).AddVariations("float16", "relaxed")
23
24test(
25    name="alpha_one",
26    input0=Input("input0", "TENSOR_FLOAT32", "{8}"),
27    alpha=Float32Scalar("alpha", 1.0),
28    output0=Output("output0", "TENSOR_FLOAT32", "{8}"),
29    input0_data=[0, -6, 2, -4, 3, -2, 10, -0.1],
30    output0_data=[0.0, -0.997521, 2.0, -0.981684, 3.0, -0.864665, 10.0, -0.0951626],
31)
32
33test(
34    name="alpha01",
35    input0=Input("input0", "TENSOR_FLOAT32", "{2, 2}"),
36    alpha=Float32Scalar("alpha", 0.1),
37    output0=Output("output0", "TENSOR_FLOAT32", "{2, 2}"),
38    input0_data=[-0.2, -0.1, 0.0, 0.1],
39    output0_data=[-0.018127, -0.009516, 0, 0.1],
40)
41
42test(
43    name="alpha10",
44    input0=Input("input0", "TENSOR_FLOAT32", "{2, 1, 1, 1, 2}"),
45    alpha=Float32Scalar("alpha", 10),
46    output0=Output("output0", "TENSOR_FLOAT32", "{2, 1, 1, 1, 2}"),
47    input0_data=[-10, -5, 0, 5],
48    output0_data=[-9.999546, -9.932620, 0, 5],
49)
50