From 7cb3d32c6637a163f77aefc91ee5738ad316d767 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 9 May 2019 09:24:25 +0900 Subject: [PATCH] [loco] Introduce DataTypeImpl trait (#3399) This commit introduces DataTypeImpl traits which returns C++ type corresponding to each DataType enum value. Signed-off-by: Jonghyun Park --- contrib/loco/include/loco/IR/DataTypeTraits.h | 42 +++++++++++++++++++++++++++ contrib/loco/src/IR/DataTypeTraits.test.cpp | 29 ++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 contrib/loco/include/loco/IR/DataTypeTraits.h create mode 100644 contrib/loco/src/IR/DataTypeTraits.test.cpp diff --git a/contrib/loco/include/loco/IR/DataTypeTraits.h b/contrib/loco/include/loco/IR/DataTypeTraits.h new file mode 100644 index 0000000..660d5d5 --- /dev/null +++ b/contrib/loco/include/loco/IR/DataTypeTraits.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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. + */ + +#ifndef __LOCO_IR_DATA_TYPE_TRAITS_H__ +#define __LOCO_IR_DATA_TYPE_TRAITS_H__ + +#include "loco/IR/DataType.h" + +namespace loco +{ + +/** + * @brief C++ scalar type corresponding to each DataType + */ +template struct DataTypeImpl +{ + // using Type = ... +}; + +// TODO Support other enum values +template <> struct DataTypeImpl +{ + // Use C++ float type for IEEE 32-bit floating-point numbers + using Type = float; +}; + +} // namespace loco + +#endif // __LOCO_IR_DATA_TYPE_TRAITS_H__ diff --git a/contrib/loco/src/IR/DataTypeTraits.test.cpp b/contrib/loco/src/IR/DataTypeTraits.test.cpp new file mode 100644 index 0000000..76d2515 --- /dev/null +++ b/contrib/loco/src/IR/DataTypeTraits.test.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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 "loco/IR/DataTypeTraits.h" + +#include + +#include + +TEST(DataTypeTraitsTest, FLOAT32) +{ + auto obtained = std::type_index(typeid(loco::DataTypeImpl::Type)); + auto expected = std::type_index(typeid(float)); + + ASSERT_EQ(obtained, expected); +} -- 2.7.4