tensor.cpp 2.79 KB
Newer Older
1
//*****************************************************************************
2
// Copyright 2017-2019 Intel Corporation
3 4 5 6 7 8 9 10 11 12 13 14 15
//
// 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.
//*****************************************************************************
Robert Kimball's avatar
Robert Kimball committed
16

17
#include <algorithm>
Robert Kimball's avatar
Robert Kimball committed
18
#include <memory>
19 20 21
#include <sstream>
#include <string>
#include <vector>
Robert Kimball's avatar
Robert Kimball committed
22 23

#include "gtest/gtest.h"
24
#include "ngraph/function.hpp"
25
#include "ngraph/ngraph.hpp"
26
#include "ngraph/pass/liveness.hpp"
27
#include "ngraph/pass/manager.hpp"
28
#include "util/test_tools.hpp"
Robert Kimball's avatar
Robert Kimball committed
29 30

using namespace std;
31
using namespace ngraph;
Robert Kimball's avatar
Robert Kimball committed
32

33
TEST(tensor, size)
Robert Kimball's avatar
Robert Kimball committed
34
{
35
    pass::Manager pass_manager;
36 37

    pass_manager.register_pass<pass::Liveness>();
38 39

    {
40
        auto arg0 = make_shared<op::Parameter>(element::f32, Shape{2, 3});
41
        auto add = make_shared<op::Add>(arg0, arg0);
42
        auto f0 = make_shared<Function>(add, ParameterVector{arg0});
43 44 45

        pass_manager.run_passes(f0);

46 47
        ASSERT_EQ(1, arg0->get_output_size());
        descriptor::Tensor& output = arg0->output(0).get_tensor();
48 49 50
        EXPECT_EQ(2 * 3 * 4, output.size());
    }

Robert Kimball's avatar
Robert Kimball committed
51
    {
52
        auto arg0 = make_shared<op::Parameter>(element::f32, Shape{});
53
        auto add = make_shared<op::Add>(arg0, arg0);
54
        auto f0 = make_shared<Function>(add, ParameterVector{arg0});
55 56

        pass_manager.run_passes(f0);
Robert Kimball's avatar
Robert Kimball committed
57

58 59
        ASSERT_EQ(1, arg0->get_output_size());
        descriptor::Tensor& output = arg0->output(0).get_tensor();
60 61 62 63
        EXPECT_EQ(1 * 4, output.size());
    }

    {
64
        auto arg0 = make_shared<op::Parameter>(element::f32, Shape{1});
65
        auto add = make_shared<op::Add>(arg0, arg0);
66
        auto f0 = make_shared<Function>(add, ParameterVector{arg0});
Robert Kimball's avatar
Robert Kimball committed
67

68
        pass_manager.run_passes(f0);
Robert Kimball's avatar
Robert Kimball committed
69

70 71
        ASSERT_EQ(1, arg0->get_output_size());
        descriptor::Tensor& output = arg0->output(0).get_tensor();
72 73
        EXPECT_EQ(1 * 4, output.size());
    }
Robert Kimball's avatar
Robert Kimball committed
74
}
75

76 77 78 79 80
TEST(tensor, output_flag)
{
    pass::Manager pass_manager;
    pass_manager.register_pass<pass::Liveness>();

81
    auto arg0 = make_shared<op::Parameter>(element::f32, Shape{1});
82
    auto add = make_shared<op::Add>(arg0, arg0);
83
    auto f0 = make_shared<Function>(add, ParameterVector{arg0});
84 85 86

    pass_manager.run_passes(f0);

87
    for (size_t i = 0; i < f0->get_output_size(); ++i)
88
    {
89
        EXPECT_TRUE(f0->get_output_op(i)->is_output());
90 91
    }
}