• Adam Procter's avatar
    Partial Shapes and Types, Part 3: Framework for partial shape/element type validation (#1728) · 0563a3cf
    Adam Procter authored
    * Adapt Tensor class to have partial shapes
    
    * Add PartialShapes to Input, Output, Function, Node classes
    
    * Terminological cleanup
    
    * Add PartialShape propagation for Parameter and Result
    
    * Implement partial-shape propagation for elementwise ops
    
    * More comments
    
    * One more comment tweak
    
    * Add tests for the merge functions
    
    * Add merging of undetermined element types
    
    * Fix a goophup in deserializer implementation
    
    * Implement fallback for ops that do not support partial shape/type validation
    
    * Updates for some older unit tests, now that operator[] exists
    
    * Add missing validate_punt_if_incomplete to AllReduce
    
    * Better docstrings for the stuff introduced in #1692; remove prototype for unimplemented, unused PartialShape::append()
    
    * One more docstring thing I forgot to save
    
    * Switch terminology from 'determined/undetermined' to 'static/dynamic'
    
    * Switch terminology from 'complete/incomplete' to 'static/dynamic' for shapes; fix up some mushily worded comments
    
    * Fix overzealous edits from the last commit
    
    * Rename one test that escaped the Great Renaming
    
    * Remove unnecessary validate_punt_if_dynamic from Reshape
    
    * Show argument types/shapes in long NodeDescription; tank unit tests to block merge
    
    * Fix dynamic element type propagation for elementwise ops, add some unit tests for same
    
    * Roll 'Not' back to existing behavior (non-boolean input types allowed)
    
    * Add a TODO tag to a todo item
    0563a3cf
element_type.cpp 3.53 KB
//*****************************************************************************
// Copyright 2017-2018 Intel Corporation
//
// 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.
//*****************************************************************************

#include <map>

#include "gtest/gtest.h"

#include "ngraph/type/element_type.hpp"

using namespace ngraph;

TEST(element_type, from)
{
    EXPECT_EQ(element::from<char>(), element::boolean);
    EXPECT_EQ(element::from<bool>(), element::boolean);
    EXPECT_EQ(element::from<float>(), element::f32);
    EXPECT_EQ(element::from<double>(), element::f64);
    EXPECT_EQ(element::from<int8_t>(), element::i8);
    EXPECT_EQ(element::from<int16_t>(), element::i16);
    EXPECT_EQ(element::from<int32_t>(), element::i32);
    EXPECT_EQ(element::from<int64_t>(), element::i64);
    EXPECT_EQ(element::from<uint8_t>(), element::u8);
    EXPECT_EQ(element::from<uint16_t>(), element::u16);
    EXPECT_EQ(element::from<uint32_t>(), element::u32);
    EXPECT_EQ(element::from<uint64_t>(), element::u64);
}

TEST(element_type, mapable)
{
    std::map<element::Type, std::string> test_map;

    test_map.insert({element::f32, "float"});
}

TEST(element_type, size)
{
    {
        element::Type t1{1, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{2, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{3, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{4, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{5, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{6, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{7, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{8, false, false, false, ""};
        EXPECT_EQ(1, t1.size());
    }
    {
        element::Type t1{9, false, false, false, ""};
        EXPECT_EQ(2, t1.size());
    }
}

TEST(element_type, merge_both_dynamic)
{
    element::Type t;
    ASSERT_TRUE(element::Type::merge(t, element::dynamic, element::dynamic));
    ASSERT_TRUE(t.is_dynamic());
}

TEST(element_type, merge_left_dynamic)
{
    element::Type t;
    ASSERT_TRUE(element::Type::merge(t, element::dynamic, element::u64));
    ASSERT_TRUE(t.is_static());
    ASSERT_EQ(t, element::u64);
}

TEST(element_type, merge_right_dynamic)
{
    element::Type t;
    ASSERT_TRUE(element::Type::merge(t, element::i16, element::dynamic));
    ASSERT_TRUE(t.is_static());
    ASSERT_EQ(t, element::i16);
}

TEST(element_type, merge_both_static_equal)
{
    element::Type t;
    ASSERT_TRUE(element::Type::merge(t, element::f64, element::f64));
    ASSERT_TRUE(t.is_static());
    ASSERT_EQ(t, element::f64);
}

TEST(element_type, merge_both_static_unequal)
{
    element::Type t = element::f32;
    ASSERT_FALSE(element::Type::merge(t, element::i8, element::i16));
    ASSERT_TRUE(t.is_static());
    ASSERT_EQ(t, element::f32);
}