--- /dev/null
+/*
+ * 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 __LOCOP_FORMATTED_TENSOR_SHAPE_H__
+#define __LOCOP_FORMATTED_TENSOR_SHAPE_H__
+
+#include "locop/Interfaces.h"
+
+#include <loco/IR/TensorShape.h>
+
+namespace locop
+{
+
+enum class TensorShapeFormat
+{
+ // [ D_0 x D_1 x D_2 x ... ]
+ Bracket,
+};
+
+template <TensorShapeFormat Format> class FormattedTensorShape;
+
+template <>
+class FormattedTensorShape<TensorShapeFormat::Bracket> final : public Spec<Interface::Formatted>
+{
+public:
+ FormattedTensorShape(const loco::TensorShape *ptr) : _ptr{ptr}
+ {
+ // DO NOTHING
+ }
+
+public:
+ void dump(std::ostream &os) const final;
+
+private:
+ const loco::TensorShape *_ptr = nullptr;
+};
+
+template <TensorShapeFormat F> FormattedTensorShape<F> fmt(loco::TensorShape *ptr)
+{
+ return FormattedTensorShape<F>{ptr};
+}
+
+} // namespace locop
+
+#endif // __LOCOP_FORMATTED_TENSOR_SHAPE_H__
--- /dev/null
+/*
+ * 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 __LOCOP_INTERFACES_H__
+#define __LOCOP_INTERFACES_H__
+
+#include <ostream>
+
+namespace locop
+{
+
+enum class Interface
+{
+ Formatted,
+};
+
+template <Interface I> struct Spec;
+
+template <> struct Spec<Interface::Formatted>
+{
+ virtual ~Spec() = default;
+
+ virtual void dump(std::ostream &os) const = 0;
+};
+
+std::ostream &operator<<(std::ostream &, const Spec<Interface::Formatted> &);
+
+} // namespace locop
+
+#endif // __LOCOP_INTERFACES_H__
--- /dev/null
+/*
+ * 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 "locop/FormattedTensorShape.h"
+
+namespace loco
+{
+
+std::ostream &operator<<(std::ostream &os, const loco::Dimension &d)
+{
+ os << (d.known() ? std::to_string(d.value()) : std::string{"?"});
+ return os;
+}
+
+} // namespace
+
+namespace locop
+{
+
+void FormattedTensorShape<TensorShapeFormat::Bracket>::dump(std::ostream &os) const
+{
+ os << "[";
+
+ if (_ptr->rank() > 0)
+ {
+ os << " " << _ptr->dim(0);
+
+ for (uint32_t axis = 1; axis < _ptr->rank(); ++axis)
+ {
+ os << " x " << _ptr->dim(axis);
+ }
+ }
+
+ os << " ]";
+}
+
+} // namespace locop
--- /dev/null
+/*
+ * 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 "locop/FormattedTensorShape.h"
+
+#include <stdex/Memory.h>
+
+#include <gtest/gtest.h>
+
+using namespace locop;
+
+TEST(FormattedTensorShapeTest, BracketFormat)
+{
+ auto tensor_shape = stdex::make_unique<loco::TensorShape>();
+
+ tensor_shape->rank(2);
+ tensor_shape->dim(0) = 4;
+
+ std::cout << fmt<TensorShapeFormat::Bracket>(tensor_shape.get()) << std::endl;
+}
--- /dev/null
+/*
+ * 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 "locop/Interfaces.h"
+
+namespace locop
+{
+
+std::ostream &operator<<(std::ostream &os, const Spec<Interface::Formatted> &formatted)
+{
+ formatted.dump(os);
+ return os;
+}
+
+} // namespace locop