Caffe2 - C++ API
A deep learning, cross platform ML framework
string_ops.h
1 
17 #ifndef CAFFE2_OPERATORS_STRING_OPS_H_
18 #define CAFFE2_OPERATORS_STRING_OPS_H_
19 
20 #include "caffe2/core/operator.h"
21 #include "caffe2/operators/elementwise_op.h"
22 
23 namespace caffe2 {
24 
33 template <typename Functor>
34 struct ForEach {
35  explicit ForEach(OperatorBase& op) : functor(op) {}
36 
37  template <typename In, typename Out, typename Context>
38  void operator()(int n, const In* in, Out* out, Context* /*c*/) {
39  for (int i = 0; i < n; ++i) {
40  out[i] = functor(in[i]);
41  }
42  }
43  Functor functor;
44 };
45 
46 template <typename ScalarFunctor, typename TypeMap = FixedType<std::string>>
49  CPUContext,
51  TypeMap>;
52 
53 template <class Context>
54 class StringJoinOp final : public Operator<Context> {
55  public:
56  USE_OPERATOR_CONTEXT_FUNCTIONS;
57 
58  StringJoinOp(const OperatorDef& operator_def, Workspace* ws)
59  : Operator<Context>(operator_def, ws),
60  delimiter_(
61  OperatorBase::GetSingleArgument<std::string>("delimiter", ",")),
62  axis_(OperatorBase::GetSingleArgument<int>("axis", 0)) {
63  CAFFE_ENFORCE(axis_ == 0 || axis_ == 1);
64  }
65 
66  bool RunOnDevice() override {
68  float,
69  double,
70  int8_t,
71  uint8_t,
72  int16_t,
73  uint16_t,
74  int32_t,
75  int64_t,
76  std::string,
77  bool>>::call(this, Input(0));
78  }
79 
80  template <typename T>
81  bool DoRunWithType();
82 
83  protected:
84  std::string delimiter_;
85  int axis_;
86 };
87 
88 } // namespace caffe2
89 
90 #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:82
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:63
Copyright (c) 2016-present, Facebook, Inc.
ForEach is a unary functor that forwards each element of the input array into the elementwise Functor...
Definition: string_ops.h:34