2 #ifndef _NNDEPLOY_BASE_STRING_H_
3 #define _NNDEPLOY_BASE_STRING_H_
22 const std::string &str,
const std::string &spstr);
26 std::ostringstream os;
37 std::stringstream stream;
39 for (
int i = 0; i < val.size(); ++i) {
41 if (i != val.size() - 1) stream <<
",";
54 return (c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' || c ==
'\f');
63 inline bool isBlank(
char c) {
return (c ==
' ' || c ==
'\t'); }
71 inline bool isDigit(
char c) {
return (c >=
'0' && c <=
'9'); }
81 static_cast<int>(
'A') == 65 &&
static_cast<int>(
'Z' -
'A') == 25,
82 "Only system with ASCII character set is supported");
83 return (c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z');
94 return (c >=
'0' && c <=
'9') || c ==
'+' || c ==
'-' || c ==
'.' ||
100 template <
typename T>
101 void printData(T *data,
size_t size, std::ostream &stream = std::cout) {
102 if (data ==
nullptr) {
107 for (
int i = 0; i < size; ++i) {
109 if (i != size - 1) stream <<
",";
116 template <
typename T>
118 std::ostream &stream = std::cout) {
119 if (data ==
nullptr ||
shape.empty()) {
123 size_t total_size = 1;
124 for (
int dim :
shape) {
128 std::function<void(
size_t,
size_t)> print_recursive = [&](
size_t depth,
130 if (depth ==
shape.size() - 1) {
132 for (
int i = 0; i <
shape[depth]; ++i) {
135 stream << (float)data[offset + i];
137 if (i !=
shape[depth] - 1) stream <<
",";
143 for (
size_t i = depth + 1; i <
shape.size(); ++i) {
146 for (
int i = 0; i <
shape[depth]; ++i) {
147 print_recursive(depth + 1, offset + i * stride);
148 if (i !=
shape[depth] - 1) stream <<
",";
154 print_recursive(0, 0);
#define NNDEPLOY_CC_API
api
std::string vectorToString(std::vector< T > val)
std::vector< int > IntVector
std::vector< std::string > splitString(const std::string &str, const std::string &spstr)
bool isDigit(char c)
Inline implementation of isDigit(). Tests whether the given character is a decimal digit.
std::wstring stringToWstring(const std::string &str)
bool isBlank(char c)
Inline implementation of isBlank(). Tests whether the given character is a space or tab character.
std::string toString(T value)
std::string getUniqueString()
bool isDigitchars(char c)
Tests whether the given character is a valid letter in the string representation of a floating-point ...
std::string ucharToString(const unsigned char *buffer, int length)
bool isNumeric(const std::string &str)
bool isAlpha(char c)
Inline implementation of isAlpha(). Tests whether the given character is an alphabet letter.
std::string wstringToString(const std::wstring &wstr)
bool isSpace(char c)
Inline implementation of isSpace(). Tests whether the given character is a whitespace letter.
void printData(T *data, size_t size, std::ostream &stream=std::cout)
base::Status shape(device::Tensor *input, std::shared_ptr< ir::ShapeParam > param, device::Tensor *output)