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_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
>>
31
using
StringElementwiseOp
=
UnaryElementwiseWithArgsOp
<
32
TensorTypes<std::string>
,
33
CPUContext
,
34
ForEach<ScalarFunctor>
,
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
{
51
return
DispatchHelper
<
TensorTypes
<
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_
caffe2::StringJoinOp
Definition:
string_ops.h:38
caffe2::CPUContext
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition:
context.h:66
caffe2::Workspace
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition:
workspace.h:47
caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition:
convert_encoded_to_raw_leveldb.cc:47
caffe2::TensorTypes
Definition:
operator.h:547
caffe2::UnaryElementwiseWithArgsOp
Definition:
elementwise_op.h:36
caffe2::DispatchHelper
Definition:
operator.h:560
caffe2::Operator
Definition:
operator.h:325
caffe2::OperatorBase
Definition:
operator.h:30
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 Apr 19 2018 13:03:56 for Caffe2 - C++ API by
1.8.11