From a962c2031508654b90ee7fd4842de645fba143cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 6 Nov 2018 18:31:01 +0900 Subject: [PATCH] [enco.caffe] Introduce RawPadding and SpatialPadding (#2134) This commit introduces RawPadding/SpatialPadding classes as the first step toward unifying Padding-related routines. Signed-off-by: Jonghyun Park --- contrib/enco/frontend/caffe/src/Padding.h | 69 ++++++++++++++++++++++++ contrib/enco/frontend/caffe/src/Padding.test.cpp | 48 +++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 contrib/enco/frontend/caffe/src/Padding.h create mode 100644 contrib/enco/frontend/caffe/src/Padding.test.cpp diff --git a/contrib/enco/frontend/caffe/src/Padding.h b/contrib/enco/frontend/caffe/src/Padding.h new file mode 100644 index 0000000..98b0181 --- /dev/null +++ b/contrib/enco/frontend/caffe/src/Padding.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018 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. + */ + +/** + * @file Padding.h + * @brief This file declares padding-related data structures. + */ +#ifndef __PADDING_H__ +#define __PADDING_H__ + +#include +#include + +/** + * @brief A PaddingBase encapsulates common implementation for derived Padding classes + */ +template class PaddingBase +{ +public: + virtual ~PaddingBase() = default; + +public: + uint32_t count(void) const { return _values.size(); } + +public: + uint32_t &value(uint32_t n) { return _values.at(n); } + const uint32_t &value(uint32_t n) const { return _values.at(n); } + +public: + void resize(uint32_t len) { return _values.resize(len); } + +private: + std::vector _values; +}; + +/** + * @brief A RawPadding denotes padding values stored in Caffe model + * + * @note There may be a mismatch between the number of values in RawPadding and spatial rank + */ +struct RawPadding final : public PaddingBase +{ + // Empty +}; + +/** + * @brief A SpatialPadding denotes padding values for each "spatial" dimension + * + * @note The number of values in SpatialPadding should be matched with spatial rank + */ +struct SpatialPadding final : public PaddingBase +{ + // Empty +}; + +#endif // __PADDING_H__ diff --git a/contrib/enco/frontend/caffe/src/Padding.test.cpp b/contrib/enco/frontend/caffe/src/Padding.test.cpp new file mode 100644 index 0000000..cb2495d --- /dev/null +++ b/contrib/enco/frontend/caffe/src/Padding.test.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018 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 "Padding.h" + +#include + +namespace +{ + +struct DerivedPadding : PaddingBase +{ + // Empty +}; + +} // namespace + +TEST(PaddingTest, PaddingBase) +{ + DerivedPadding pad; + + ASSERT_EQ(pad.count(), 0); + + pad.resize(2); + + ASSERT_EQ(pad.count(), 2); + ASSERT_EQ(pad.value(0), 0); + ASSERT_EQ(pad.value(1), 0); + + pad.value(1) = 4; + + ASSERT_EQ(pad.count(), 2); + ASSERT_EQ(pad.value(0), 0); + ASSERT_EQ(pad.value(1), 4); +} -- 2.7.4