Caffe2 - C++ API
A deep learning, cross platform ML framework
string_utils.h
1 #pragma once
2 
3 #include <sstream>
4 #include <string>
5 
6 namespace c10 {
7 
8 // to_string, stoi and stod implementation for Android related stuff.
9 // Note(jiayq): Do not use the CAFFE2_TESTONLY_FORCE_STD_STRING_TEST macro
10 // outside testing code that lives under common_test.cc
11 #if defined(__ANDROID__) || defined(CAFFE2_TESTONLY_FORCE_STD_STRING_TEST)
12 #define CAFFE2_TESTONLY_WE_ARE_USING_CUSTOM_STRING_FUNCTIONS 1
13 template <typename T>
14 std::string to_string(T value) {
15  std::ostringstream os;
16  os << value;
17  return os.str();
18 }
19 
20 inline int stoi(const std::string& str) {
21  std::stringstream ss;
22  int n = 0;
23  ss << str;
24  ss >> n;
25  return n;
26 }
27 
28 inline uint64_t stoull(const std::string& str) {
29  std::stringstream ss;
30  uint64_t n = 0;
31  ss << str;
32  ss >> n;
33  return n;
34 }
35 
36 inline double stod(const std::string& str, std::size_t* pos = 0) {
37  std::stringstream ss;
38  ss << str;
39  double val = 0;
40  ss >> val;
41  if (pos) {
42  if (ss.tellg() == std::streampos(-1)) {
43  *pos = str.size();
44  } else {
45  *pos = ss.tellg();
46  }
47  }
48  return val;
49 }
50 #else
51 #define CAFFE2_TESTONLY_WE_ARE_USING_CUSTOM_STRING_FUNCTIONS 0
52 using std::stod;
53 using std::stoi;
54 using std::stoull;
55 using std::to_string;
56 #endif // defined(__ANDROID__) || defined(CAFFE2_FORCE_STD_STRING_FALLBACK_TEST)
57 
58 } // namespace c10
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
Definition: alias_info.h:7