microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b3a300d7bf6f3e99fb907e682f7246ed5ed5805e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
7template <typename T>
8inline void MakeStringInternal(std::ostringstream& ss, const T& t) noexcept {
9 ss << t;
10}
11
12template <>
13inline 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
19template <typename T, typename... Args>
20void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
21 MakeStringInternal(ss, t);
22 MakeStringInternal(ss, args...);
23}
24
25template <typename... Args>
26std::string MakeString(const Args&... args) {
27 std::ostringstream ss;
28 MakeStringInternal(ss, args...);
29 return std::string(ss.str());
30}
31
32inline 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