Caffe2 - C++ API
A deep learning, cross platform ML framework
string_ops.h
1 #ifndef CAFFE2_OPERATORS_STRING_OPS_H_
2 #define CAFFE2_OPERATORS_STRING_OPS_H_
3 
4 #include "caffe2/core/operator.h"
5 #include "caffe2/operators/elementwise_op.h"
6 
7 namespace caffe2 {
8 
17 template <typename Functor>
18 struct ForEach {
19  explicit ForEach(OperatorBase& op) : functor(op) {}
20 
21  template <typename In, typename Out, typename Context>
22  void operator()(int n, const In* in, Out* out, Context* /*c*/) {
23  for (int i = 0; i < n; ++i) {
24  out[i] = functor(in[i]);
25  }
26  }
27  Functor functor;
28 };
29 
30 template <typename ScalarFunctor, typename TypeMap = FixedType<std::string>>
33  CPUContext,
35  TypeMap>;
36 
37 template <class Context>
38 class StringJoinOp final : public Operator<Context> {
39  public:
40  USE_OPERATOR_CONTEXT_FUNCTIONS;
41 
42  StringJoinOp(const OperatorDef& operator_def, Workspace* ws)
43  : Operator<Context>(operator_def, ws),
44  delimiter_(
45  OperatorBase::GetSingleArgument<std::string>("delimiter", ",")),
46  axis_(OperatorBase::GetSingleArgument<int>("axis", 0)) {
47  CAFFE_ENFORCE(axis_ == 0 || axis_ == 1);
48  }
49 
50  bool RunOnDevice() override {
52  float,
53  double,
54  int8_t,
55  uint8_t,
56  int16_t,
57  uint16_t,
58  int32_t,
59  int64_t,
60  std::string,
61  bool>>::call(this, Input(0));
62  }
63 
64  template <typename T>
65  bool DoRunWithType();
66 
67  protected:
68  std::string delimiter_;
69  int axis_;
70 };
71 
72 } // namespace caffe2
73 
74 #endif // CAFFE2_OPERATORS_STRING_OPS_H_
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition: context.h:66
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
ForEach is a unary functor that forwards each element of the input array into the elementwise Functor...
Definition: string_ops.h:18