MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ToBool

Function ToBool

tensorflow/core/kernels/functional_ops.cc:60–95  ·  view source on GitHub ↗

If "t" is a scalar of a supported type, returns t != 0 in "*v".

Source from the content-addressed store, hash-verified

58
59// If "t" is a scalar of a supported type, returns t != 0 in "*v".
60Status ToBool(gtl::ArraySlice<Tensor> t, bool* v) {
61 if (t.size() != 1) {
62 return errors::InvalidArgument(
63 "Expected a single scalar which can be converted to a boolean, got ",
64 t.size(), " tensors.");
65 }
66 if (TensorShapeUtils::IsScalar(t[0].shape())) {
67 switch (t[0].dtype()) {
68#define CASE(T) \
69 case DataTypeToEnum<T>::value: \
70 *v = t[0].scalar<T>()() != 0; \
71 break;
72
73 CASE(float);
74 CASE(double);
75 CASE(int32);
76 CASE(uint8);
77 CASE(int16);
78 CASE(int8);
79 CASE(int64);
80#undef CASE
81 case DT_BOOL:
82 *v = t[0].scalar<bool>()();
83 break;
84 case DT_STRING:
85 *v = !t[0].scalar<tstring>()().empty();
86 break;
87 default:
88 return errors::InvalidArgument(DataTypeString(t[0].dtype()),
89 " cannot be converted to a boolean");
90 }
91 } else {
92 *v = t[0].NumElements() > 0;
93 }
94 return Status::OK();
95}
96
97// Sets "rets" to be the output of "ctx". Validates rets' types based
98// on "kernel".

Callers 2

ComputeAsyncMethod · 0.85
StartBodyMethod · 0.85

Calls 8

InvalidArgumentFunction · 0.85
IsScalarFunction · 0.50
DataTypeStringFunction · 0.50
sizeMethod · 0.45
shapeMethod · 0.45
dtypeMethod · 0.45
emptyMethod · 0.45
NumElementsMethod · 0.45

Tested by

no test coverage detected