1 #ifndef CAFFE2_OPERATORS_ASSERT_OP_H_ 2 #define CAFFE2_OPERATORS_ASSERT_OP_H_ 4 #include "caffe2/core/context.h" 5 #include "caffe2/core/operator.h" 9 template <
class Context>
12 template <
class... Args>
16 this->
template GetSingleArgument<std::string>(
"error_msg",
"")) {}
18 USE_OPERATOR_CONTEXT_FUNCTIONS;
21 bool DoRunWithType() {
23 cmp_tensor_.CopyFrom(
Input(0));
24 auto* cmp_data = cmp_tensor_.template data<T>();
26 for (int64_t i = 0; i < cmp_tensor_.numel(); ++i) {
27 CAFFE_ENFORCE((
bool)cmp_data[i], [&]() {
29 ss <<
"Assert failed for element " << i
30 <<
" in tensor, value: " << cmp_data[i] <<
"\n";
31 if (!error_msg_.empty()) {
32 ss <<
"Error message: " << error_msg_;
40 bool RunOnDevice()
override {
46 std::string error_msg_;
const Tensor & Input(int idx, DeviceType type=Context::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...