Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
element_type cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rkimballn1 committed Dec 17, 2017
1 parent 7b06ae4 commit 43885b5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 49 deletions.
68 changes: 68 additions & 0 deletions src/ngraph/types/element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cmath>
#include <iostream>

#include "ngraph/log.hpp"
#include "ngraph/log.hpp"
#include "ngraph/types/element_type.hpp"

Expand Down Expand Up @@ -86,6 +87,73 @@ size_t element::Type::hash() const
return h1 ^ ((h2 ^ (h3 << 1)) << 1);
}

namespace ngraph
{
namespace element
{
template <>
const Type& from<char>()
{
return boolean;
}
template <>
const Type& from<bool>()
{
return boolean;
}
template <>
const Type& from<float>()
{
return f32;
}
template <>
const Type& from<double>()
{
return f64;
}
template <>
const Type& from<int8_t>()
{
return i8;
}
template <>
const Type& from<int16_t>()
{
return i16;
}
template <>
const Type& from<int32_t>()
{
return i32;
}
template <>
const Type& from<int64_t>()
{
return i64;
}
template <>
const Type& from<uint8_t>()
{
return u8;
}
template <>
const Type& from<uint16_t>()
{
return u16;
}
template <>
const Type& from<uint32_t>()
{
return u32;
}
template <>
const Type& from<uint64_t>()
{
return u64;
}
}
}

std::ostream& element::operator<<(std::ostream& out, const element::Type& obj)
{
out << "element::Type(" << obj.m_bitwidth << ", " << obj.m_is_real << ", " << obj.m_is_signed
Expand Down
74 changes: 26 additions & 48 deletions src/ngraph/types/element_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "ngraph/common.hpp"
#include "ngraph/except.hpp"
#include "ngraph/log.hpp"

namespace ngraph
{
Expand Down Expand Up @@ -76,55 +77,32 @@ namespace ngraph
template <typename T>
const Type& from()
{
if (typeid(T) == typeid(char) || typeid(T) == typeid(bool))
{
return boolean;
}
else if (typeid(T) == typeid(float))
{
return f32;
}
else if (typeid(T) == typeid(double))
{
return f64;
}
else if (typeid(T) == typeid(int8_t))
{
return i8;
}
else if (typeid(T) == typeid(int16_t))
{
return i16;
}
else if (typeid(T) == typeid(int32_t))
{
return i32;
}
else if (typeid(T) == typeid(int64_t))
{
return i64;
}
else if (typeid(T) == typeid(uint8_t))
{
return u8;
}
else if (typeid(T) == typeid(uint16_t))
{
return u16;
}
else if (typeid(T) == typeid(uint32_t))
{
return u32;
}
else if (typeid(T) == typeid(uint64_t))
{
return u64;
}
else
{
throw std::invalid_argument("Unknown type");
}
throw std::invalid_argument("Unknown type");
}
template <>
const Type& from<char>();
template <>
const Type& from<bool>();
template <>
const Type& from<float>();
template <>
const Type& from<double>();
template <>
const Type& from<int8_t>();
template <>
const Type& from<int16_t>();
template <>
const Type& from<int32_t>();
template <>
const Type& from<int64_t>();
template <>
const Type& from<uint8_t>();
template <>
const Type& from<uint16_t>();
template <>
const Type& from<uint32_t>();
template <>
const Type& from<uint64_t>();

std::ostream& operator<<(std::ostream& out, const ngraph::element::Type& obj);

Expand Down
2 changes: 1 addition & 1 deletion test/element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST(element_type, size)
EXPECT_EQ(1, t1.size());
}
{
element::Type t1{2, false, false, ""};
element::Type t1{8, false, false, ""};
EXPECT_EQ(1, t1.size());
}
{
Expand Down

0 comments on commit 43885b5

Please sign in to comment.