microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
ocos/utils.h
38lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | #pragma once |
| 4 | #include <iostream> |
| 5 | #include <sstream> |
| 6 | |
| 7 | template <typename T> |
| 8 | inline void MakeStringInternal(std::ostringstream& ss, const T& t) noexcept { |
| 9 | ss << t; |
| 10 | } |
| 11 | |
| 12 | template <> |
| 13 | inline void MakeStringInternal(std::ostringstream& ss, const std::vector<int64_t>& t) noexcept { |
| 14 | for (auto it = t.begin(); it != t.end(); ++it) { |
| 15 | ss << *it << "x"; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | template <typename T, typename... Args> |
| 20 | void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept { |
| 21 | MakeStringInternal(ss, t); |
| 22 | MakeStringInternal(ss, args...); |
| 23 | } |
| 24 | |
| 25 | template <typename... Args> |
| 26 | std::string MakeString(const Args&... args) { |
| 27 | std::ostringstream ss; |
| 28 | MakeStringInternal(ss, args...); |
| 29 | return std::string(ss.str()); |
| 30 | } |
| 31 | |
| 32 | inline int64_t Size(const std::vector<int64_t>& shape) { |
| 33 | int64_t res = 1; |
| 34 | for (auto it = shape.begin(); it != shape.end(); ++it) { |
| 35 | res *= *it; |
| 36 | } |
| 37 | return res; |
| 38 | } |
| 39 | |