Update attr name for Dense version Bincount.

PiperOrigin-RevId: 311423709
Change-Id: Ief7c901477be8e06b1d3f98613c7390c12e9680b
This commit is contained in:
Zhenyu Tan 2020-05-13 16:08:29 -07:00 committed by TensorFlower Gardener
parent 0ac3572e8d
commit 0c9e56e931
8 changed files with 34 additions and 34 deletions

View File

@ -28,7 +28,7 @@ The counts or summed weights for each value in the range [0, size).
END END
} }
attr { attr {
name: "binary_count" name: "binary_output"
description: <<END description: <<END
bool; Whether the kernel should count the appearance or number of occurrences. bool; Whether the kernel should count the appearance or number of occurrences.
END END

View File

@ -34,7 +34,7 @@ The counts or summed weights for each value in the range [0, size).
END END
} }
attr { attr {
name: "binary_count" name: "binary_output"
description: <<END description: <<END
bool; Whether the kernel should count the appearance or number of occurrences. bool; Whether the kernel should count the appearance or number of occurrences.
END END

View File

@ -40,7 +40,7 @@ The counts or summed weights for each value in the range [0, size).
END END
} }
attr { attr {
name: "binary_count" name: "binary_output"
description: <<END description: <<END
bool; Whether the kernel should count the appearance or number of occurrences. bool; Whether the kernel should count the appearance or number of occurrences.
END END

View File

@ -130,8 +130,8 @@ struct BincountFunctor<CPUDevice, Tidx, T, false> {
} }
}; };
template <typename Tidx, typename T, bool binary_count> template <typename Tidx, typename T, bool binary_output>
struct BincountReduceFunctor<CPUDevice, Tidx, T, binary_count> { struct BincountReduceFunctor<CPUDevice, Tidx, T, binary_output> {
static Status Compute(OpKernelContext* context, static Status Compute(OpKernelContext* context,
const typename TTypes<Tidx, 2>::ConstTensor& in, const typename TTypes<Tidx, 2>::ConstTensor& in,
const typename TTypes<T, 2>::ConstTensor& weights, const typename TTypes<T, 2>::ConstTensor& weights,
@ -148,7 +148,7 @@ struct BincountReduceFunctor<CPUDevice, Tidx, T, binary_count> {
for (int64 j = 0; j < num_cols; ++j) { for (int64 j = 0; j < num_cols; ++j) {
Tidx value = in(i, j); Tidx value = in(i, j);
if (value < num_bins) { if (value < num_bins) {
if (binary_count) { if (binary_output) {
out(i, value) = T(1); out(i, value) = T(1);
} else { } else {
if (weights.size()) { if (weights.size()) {
@ -221,7 +221,7 @@ template <typename Device, typename Tidx, typename T>
class DenseBincountOp : public OpKernel { class DenseBincountOp : public OpKernel {
public: public:
explicit DenseBincountOp(OpKernelConstruction* ctx) : OpKernel(ctx) { explicit DenseBincountOp(OpKernelConstruction* ctx) : OpKernel(ctx) {
OP_REQUIRES_OK(ctx, ctx->GetAttr("binary_count", &binary_count_)); OP_REQUIRES_OK(ctx, ctx->GetAttr("binary_output", &binary_output_));
} }
void Compute(OpKernelContext* ctx) override { void Compute(OpKernelContext* ctx) override {
@ -240,7 +240,7 @@ class DenseBincountOp : public OpKernel {
OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({size}), &out_t)); OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({size}), &out_t));
auto out = out_t->flat<T>(); auto out = out_t->flat<T>();
fill(ctx->eigen_device<Device>(), out); fill(ctx->eigen_device<Device>(), out);
if (binary_count_) { if (binary_output_) {
OP_REQUIRES_OK( OP_REQUIRES_OK(
ctx, functor::BincountFunctor<Device, Tidx, T, true>::Compute( ctx, functor::BincountFunctor<Device, Tidx, T, true>::Compute(
ctx, data.flat<Tidx>(), weights.flat<T>(), out, size)); ctx, data.flat<Tidx>(), weights.flat<T>(), out, size));
@ -259,7 +259,7 @@ class DenseBincountOp : public OpKernel {
ctx, ctx->allocate_output(0, TensorShape({num_rows, size}), &out_t)); ctx, ctx->allocate_output(0, TensorShape({num_rows, size}), &out_t));
auto out = out_t->matrix<T>(); auto out = out_t->matrix<T>();
fill(ctx->eigen_device<Device>(), out_t->flat<T>()); fill(ctx->eigen_device<Device>(), out_t->flat<T>());
if (binary_count_) { if (binary_output_) {
OP_REQUIRES_OK( OP_REQUIRES_OK(
ctx, functor::BincountReduceFunctor<Device, Tidx, T, true>::Compute( ctx, functor::BincountReduceFunctor<Device, Tidx, T, true>::Compute(
ctx, data.matrix<Tidx>(), weight_matrix, out, size)); ctx, data.matrix<Tidx>(), weight_matrix, out, size));
@ -273,7 +273,7 @@ class DenseBincountOp : public OpKernel {
} }
private: private:
bool binary_count_; bool binary_output_;
}; };
#define REGISTER_KERNELS(Tidx, T) \ #define REGISTER_KERNELS(Tidx, T) \
@ -314,7 +314,7 @@ template <typename Device, typename Tidx, typename T>
class SparseBincountOp : public OpKernel { class SparseBincountOp : public OpKernel {
public: public:
explicit SparseBincountOp(OpKernelConstruction* ctx) : OpKernel(ctx) { explicit SparseBincountOp(OpKernelConstruction* ctx) : OpKernel(ctx) {
OP_REQUIRES_OK(ctx, ctx->GetAttr("binary_count", &binary_count_)); OP_REQUIRES_OK(ctx, ctx->GetAttr("binary_output", &binary_output_));
} }
void Compute(OpKernelContext* ctx) override { void Compute(OpKernelContext* ctx) override {
@ -338,7 +338,7 @@ class SparseBincountOp : public OpKernel {
OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({size}), &out_t)); OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({size}), &out_t));
auto out = out_t->flat<T>(); auto out = out_t->flat<T>();
fill(ctx->eigen_device<Device>(), out); fill(ctx->eigen_device<Device>(), out);
if (binary_count_) { if (binary_output_) {
OP_REQUIRES_OK(ctx, OP_REQUIRES_OK(ctx,
functor::BincountFunctor<Device, Tidx, T, true>::Compute( functor::BincountFunctor<Device, Tidx, T, true>::Compute(
ctx, values, weights, out, size)); ctx, values, weights, out, size));
@ -359,7 +359,7 @@ class SparseBincountOp : public OpKernel {
const int64 batch = indices_mat(i, 0); const int64 batch = indices_mat(i, 0);
const Tidx bin = values(i); const Tidx bin = values(i);
if (bin < size) { if (bin < size) {
if (binary_count_) { if (binary_output_) {
out(batch, bin) = T(1); out(batch, bin) = T(1);
} else { } else {
if (weights_size) { if (weights_size) {
@ -374,7 +374,7 @@ class SparseBincountOp : public OpKernel {
} }
private: private:
bool binary_count_; bool binary_output_;
}; };
#define REGISTER_KERNELS(Tidx, T) \ #define REGISTER_KERNELS(Tidx, T) \
@ -395,7 +395,7 @@ template <typename Device, typename Tidx, typename T>
class RaggedBincountOp : public OpKernel { class RaggedBincountOp : public OpKernel {
public: public:
explicit RaggedBincountOp(OpKernelConstruction* ctx) : OpKernel(ctx) { explicit RaggedBincountOp(OpKernelConstruction* ctx) : OpKernel(ctx) {
OP_REQUIRES_OK(ctx, ctx->GetAttr("binary_count", &binary_count_)); OP_REQUIRES_OK(ctx, ctx->GetAttr("binary_output", &binary_output_));
} }
void Compute(OpKernelContext* ctx) override { void Compute(OpKernelContext* ctx) override {
@ -429,7 +429,7 @@ class RaggedBincountOp : public OpKernel {
OP_REQUIRES(ctx, bin >= 0, OP_REQUIRES(ctx, bin >= 0,
errors::InvalidArgument("Input must be non-negative")); errors::InvalidArgument("Input must be non-negative"));
if (bin < size) { if (bin < size) {
if (binary_count_) { if (binary_output_) {
out(batch_idx - 1, bin) = T(1); out(batch_idx - 1, bin) = T(1);
} else { } else {
T value = (weights_size > 0) ? weights(idx) : T(1); T value = (weights_size > 0) ? weights(idx) : T(1);
@ -440,7 +440,7 @@ class RaggedBincountOp : public OpKernel {
} }
private: private:
bool binary_count_; bool binary_output_;
}; };
#define REGISTER_KERNELS(Tidx, T) \ #define REGISTER_KERNELS(Tidx, T) \

View File

@ -1657,7 +1657,7 @@ REGISTER_OP("DenseBincount")
.Input("weights: T") .Input("weights: T")
.Attr("Tidx: {int32, int64}") .Attr("Tidx: {int32, int64}")
.Attr("T: {int32, int64, float32, float64}") .Attr("T: {int32, int64, float32, float64}")
.Attr("binary_count: bool = false") .Attr("binary_output: bool = false")
.Output("output: T") .Output("output: T")
.SetShapeFn([](InferenceContext* c) { .SetShapeFn([](InferenceContext* c) {
ShapeHandle unused; ShapeHandle unused;
@ -1704,7 +1704,7 @@ REGISTER_OP("SparseBincount")
.Input("weights: T") .Input("weights: T")
.Attr("Tidx: {int32, int64}") .Attr("Tidx: {int32, int64}")
.Attr("T: {int32, int64, float32, float64}") .Attr("T: {int32, int64, float32, float64}")
.Attr("binary_count: bool = false") .Attr("binary_output: bool = false")
.Output("output: T") .Output("output: T")
.SetShapeFn([](InferenceContext* c) { .SetShapeFn([](InferenceContext* c) {
const Tensor* size_tensor = c->input_tensor(3); const Tensor* size_tensor = c->input_tensor(3);
@ -1754,7 +1754,7 @@ REGISTER_OP("RaggedBincount")
.Input("weights: T") .Input("weights: T")
.Attr("Tidx: {int32, int64}") .Attr("Tidx: {int32, int64}")
.Attr("T: {int32, int64, float32, float64}") .Attr("T: {int32, int64, float32, float64}")
.Attr("binary_count: bool = false") .Attr("binary_output: bool = false")
.Output("output: T") .Output("output: T")
.SetShapeFn([](InferenceContext* c) { .SetShapeFn([](InferenceContext* c) {
c->set_output(0, c->UnknownShape()); c->set_output(0, c->UnknownShape());

View File

@ -183,7 +183,7 @@ class BincountOpTest(test_util.TensorFlowTestCase, parameterized.TestCase):
np_out, np_out,
self.evaluate( self.evaluate(
gen_math_ops.dense_bincount( gen_math_ops.dense_bincount(
input=inp, weights=[], size=size, binary_count=True))) input=inp, weights=[], size=size, binary_output=True)))
@parameterized.parameters([{ @parameterized.parameters([{
"dtype": np.int32, "dtype": np.int32,
@ -201,7 +201,7 @@ class BincountOpTest(test_util.TensorFlowTestCase, parameterized.TestCase):
np_out, np_out,
self.evaluate( self.evaluate(
gen_math_ops.dense_bincount( gen_math_ops.dense_bincount(
input=inp, weights=np_weight, size=size, binary_count=True))) input=inp, weights=np_weight, size=size, binary_output=True)))
def _test_bincount_col_count(self, num_rows, num_cols, size, dtype): def _test_bincount_col_count(self, num_rows, num_cols, size, dtype):
np.random.seed(42) np.random.seed(42)
@ -230,7 +230,7 @@ class BincountOpTest(test_util.TensorFlowTestCase, parameterized.TestCase):
np_out, np_out,
self.evaluate( self.evaluate(
gen_math_ops.dense_bincount( gen_math_ops.dense_bincount(
input=inp, weights=[], size=size, binary_count=True))) input=inp, weights=[], size=size, binary_output=True)))
def _test_bincount_col_count_with_weights(self, num_rows, num_cols, size, def _test_bincount_col_count_with_weights(self, num_rows, num_cols, size,
dtype): dtype):
@ -401,7 +401,7 @@ class SparseBincountOpTest(test_util.TensorFlowTestCase,
dense_shape=[num_rows], dense_shape=[num_rows],
size=size, size=size,
weights=[], weights=[],
binary_count=True))) binary_output=True)))
@parameterized.parameters([{ @parameterized.parameters([{
"dtype": np.int32, "dtype": np.int32,
@ -427,7 +427,7 @@ class SparseBincountOpTest(test_util.TensorFlowTestCase,
dense_shape=[num_rows], dense_shape=[num_rows],
size=size, size=size,
weights=inp_weight, weights=inp_weight,
binary_count=True))) binary_output=True)))
@parameterized.parameters([{ @parameterized.parameters([{
"dtype": np.int32, "dtype": np.int32,
@ -490,7 +490,7 @@ class SparseBincountOpTest(test_util.TensorFlowTestCase,
dense_shape=inp_sparse.dense_shape, dense_shape=inp_sparse.dense_shape,
size=size, size=size,
weights=[], weights=[],
binary_count=True))) binary_output=True)))
class RaggedBincountOpTest(test_util.TensorFlowTestCase, class RaggedBincountOpTest(test_util.TensorFlowTestCase,
@ -530,7 +530,7 @@ class RaggedBincountOpTest(test_util.TensorFlowTestCase,
values=x.values, values=x.values,
weights=[], weights=[],
size=6, size=6,
binary_count=True))) binary_output=True)))
@parameterized.parameters([{ @parameterized.parameters([{
"dtype": np.int32, "dtype": np.int32,
@ -629,7 +629,7 @@ class RaggedBincountOpTest(test_util.TensorFlowTestCase,
values=x.values, values=x.values,
weights=[], weights=[],
size=size, size=size,
binary_count=True))) binary_output=True)))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1074,7 +1074,7 @@ tf_module {
} }
member_method { member_method {
name: "DenseBincount" name: "DenseBincount"
argspec: "args=[\'input\', \'size\', \'weights\', \'binary_count\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], " argspec: "args=[\'input\', \'size\', \'weights\', \'binary_output\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], "
} }
member_method { member_method {
name: "DenseCountSparseOutput" name: "DenseCountSparseOutput"
@ -3070,7 +3070,7 @@ tf_module {
} }
member_method { member_method {
name: "RaggedBincount" name: "RaggedBincount"
argspec: "args=[\'splits\', \'values\', \'size\', \'weights\', \'binary_count\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], " argspec: "args=[\'splits\', \'values\', \'size\', \'weights\', \'binary_output\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], "
} }
member_method { member_method {
name: "RaggedCountSparseOutput" name: "RaggedCountSparseOutput"
@ -4082,7 +4082,7 @@ tf_module {
} }
member_method { member_method {
name: "SparseBincount" name: "SparseBincount"
argspec: "args=[\'indices\', \'values\', \'dense_shape\', \'size\', \'weights\', \'binary_count\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], " argspec: "args=[\'indices\', \'values\', \'dense_shape\', \'size\', \'weights\', \'binary_output\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], "
} }
member_method { member_method {
name: "SparseConcat" name: "SparseConcat"

View File

@ -1074,7 +1074,7 @@ tf_module {
} }
member_method { member_method {
name: "DenseBincount" name: "DenseBincount"
argspec: "args=[\'input\', \'size\', \'weights\', \'binary_count\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], " argspec: "args=[\'input\', \'size\', \'weights\', \'binary_output\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], "
} }
member_method { member_method {
name: "DenseCountSparseOutput" name: "DenseCountSparseOutput"
@ -3070,7 +3070,7 @@ tf_module {
} }
member_method { member_method {
name: "RaggedBincount" name: "RaggedBincount"
argspec: "args=[\'splits\', \'values\', \'size\', \'weights\', \'binary_count\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], " argspec: "args=[\'splits\', \'values\', \'size\', \'weights\', \'binary_output\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], "
} }
member_method { member_method {
name: "RaggedCountSparseOutput" name: "RaggedCountSparseOutput"
@ -4082,7 +4082,7 @@ tf_module {
} }
member_method { member_method {
name: "SparseBincount" name: "SparseBincount"
argspec: "args=[\'indices\', \'values\', \'dense_shape\', \'size\', \'weights\', \'binary_count\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], " argspec: "args=[\'indices\', \'values\', \'dense_shape\', \'size\', \'weights\', \'binary_output\', \'name\'], varargs=None, keywords=None, defaults=[\'False\', \'None\'], "
} }
member_method { member_method {
name: "SparseConcat" name: "SparseConcat"