Caffe2 - C++ API
A deep learning, cross platform ML framework
Related Pages
Modules
Data Structures
Files
C++ API
Python API
GitHub
File List
Globals
caffe2
operators
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_ops.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
bool
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
return
true
;
27
}
28
29
Functor functor;
30
};
31
32
template
<
typename
ScalarFunctor,
typename
TypeMap = FixedType<std::
string
>>
33
using
StringElementwiseOp
=
UnaryElementwiseWithArgsOp
<
34
TensorTypes<std::string>
,
35
CPUContext
,
36
ForEach<ScalarFunctor>
,
37
TypeMap>;
38
39
template
<
class
Context>
40
class
StringJoinOp
final :
public
Operator
<Context> {
41
public
:
42
USE_OPERATOR_CONTEXT_FUNCTIONS;
43
44
template
<
class
... Args>
45
explicit
StringJoinOp
(Args&&... args)
46
:
Operator<Context>
(std::forward<Args>(args)...),
47
delimiter_(
48
this->
template
GetSingleArgument<std::string>(
"delimiter"
,
","
)),
49
axis_(this->
template
GetSingleArgument<int>(
"axis"
, 0)) {
50
CAFFE_ENFORCE(axis_ == 0 || axis_ == 1);
51
}
52
53
bool
RunOnDevice()
override
{
54
return
DispatchHelper
<
TensorTypes
<
55
float,
56
double,
57
int8_t,
58
uint8_t,
59
int16_t,
60
uint16_t,
61
int32_t,
62
int64_t,
63
std::string,
64
bool
>>::call(
this
, Input(0));
65
}
66
67
template
<
typename
T>
68
bool
DoRunWithType();
69
70
protected
:
71
std::string delimiter_;
72
int
axis_;
73
};
74
75
}
// namespace caffe2
76
77
#endif // CAFFE2_OPERATORS_STRING_OPS_H_
caffe2::StringJoinOp
Definition:
string_ops.h:40
caffe2::CPUContext
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition:
context.h:40
caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition:
blob.h:13
caffe2::TensorTypes
Definition:
operator.h:1039
caffe2::UnaryElementwiseWithArgsOp
Definition:
elementwise_ops.h:41
caffe2::DispatchHelper
Definition:
operator.h:1052
caffe2::Operator
Definition:
operator.h:677
caffe2::OperatorBase
Definition:
operator.h:38
caffe2::ForEach
ForEach is a unary functor that forwards each element of the input array into the elementwise Functor...
Definition:
string_ops.h:18
Generated on Thu Mar 21 2019 13:06:19 for Caffe2 - C++ API by
1.8.11