Skip to content

Commit f250f0a

Browse files
GooglerSung Jin Hwang
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 247700859 Change-Id: Ieb1ae0ae40ea282dbc6cabca37ac76c28fa34804
1 parent 1baba84 commit f250f0a

9 files changed

+37
-48
lines changed

tensorflow_compression/cc/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ cc_binary(
1313
"-pthread",
1414
"-std=c++11",
1515
"-D_GLIBCXX_USE_CXX11_ABI=0",
16-
"-Wno-sign-compare",
17-
"-Wno-maybe-uninitialized",
1816
],
1917
linkshared = 1,
2018
linkstatic = 0,

tensorflow_compression/cc/kernels/range_coder.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ limitations under the License.
2424
#include <limits>
2525
#include <string>
2626

27-
#include "tensorflow/core/lib/gtl/array_slice.h"
27+
#include "absl/types/span.h"
2828
#include "tensorflow/core/platform/logging.h"
2929
#include "tensorflow/core/platform/types.h"
3030

3131
namespace tensorflow_compression {
32-
namespace gtl = tensorflow::gtl;
3332
using tensorflow::int32;
3433
using tensorflow::string;
3534
using tensorflow::uint32;
@@ -307,7 +306,7 @@ RangeDecoder::RangeDecoder(const string& source)
307306
Read16BitValue();
308307
}
309308

310-
int32 RangeDecoder::Decode(gtl::ArraySlice<int32> cdf, int precision) {
309+
int32 RangeDecoder::Decode(absl::Span<const int32> cdf, int precision) {
311310
// Input requirement: 0 < precision < 16.
312311
DCHECK_GT(precision, 0);
313312
DCHECK_LE(precision, 16);

tensorflow_compression/cc/kernels/range_coder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
#include <limits>
2020
#include <string>
2121

22-
#include "tensorflow/core/lib/gtl/array_slice.h"
22+
#include "absl/types/span.h"
2323
#include "tensorflow/core/platform/types.h"
2424

2525
namespace tensorflow_compression {
@@ -85,7 +85,7 @@ class RangeDecoder {
8585
// REQUIRES: 0 < precision <= 16.
8686
//
8787
// In practice the last element of `cdf` should equal to 2^precision.
88-
tensorflow::int32 Decode(tensorflow::gtl::ArraySlice<tensorflow::int32> cdf,
88+
tensorflow::int32 Decode(absl::Span<const tensorflow::int32> cdf,
8989
int precision);
9090

9191
private:

tensorflow_compression/cc/kernels/range_coding_helper_kernels.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ limitations under the License.
2121
#include <numeric>
2222
#include <vector>
2323

24+
#include "absl/types/span.h"
2425
#include "tensorflow/core/framework/op_kernel.h"
2526
#include "tensorflow/core/framework/tensor.h"
2627
#include "tensorflow/core/framework/tensor_shape.h"
2728
#include "tensorflow/core/framework/tensor_types.h"
2829
#include "tensorflow/core/lib/core/errors.h"
2930
#include "tensorflow/core/lib/core/threadpool.h"
30-
#include "tensorflow/core/lib/gtl/array_slice.h"
3131
#include "tensorflow/core/platform/logging.h"
3232
#include "tensorflow/core/platform/macros.h"
3333
#include "tensorflow/core/platform/types.h"
3434
#include "external/farmhash_archive/src/farmhash.h"
3535

3636
namespace tensorflow_compression {
3737
namespace {
38-
namespace gtl = tensorflow::gtl;
3938
namespace thread = tensorflow::thread;
4039
using tensorflow::DEVICE_CPU;
4140
using tensorflow::int32;
@@ -87,7 +86,7 @@ class PmfToCdfOp : public OpKernel {
8786
thread_pool->ParallelFor(
8887
pmf.dimension(0), cost_per_unit,
8988
[this, pmf, &cdf](int64 start, int64 limit) {
90-
const gtl::ArraySlice<float>::size_type pmf_size = pmf.dimension(1);
89+
const absl::Span<const float>::size_type pmf_size = pmf.dimension(1);
9190
for (int64 i = start; i < limit; ++i) {
9291
cdf(i, 0) = 0;
9392
PerShard({&pmf(i, 0), pmf_size}, {&cdf(i, 1), pmf_size});
@@ -151,8 +150,7 @@ class PmfToCdfOp : public OpKernel {
151150
double gain;
152151
};
153152

154-
void PerShard(gtl::ArraySlice<float> pmf,
155-
gtl::MutableArraySlice<int32> cdf) const {
153+
void PerShard(absl::Span<const float> pmf, absl::Span<int32> cdf) const {
156154
CHECK_EQ(pmf.size(), cdf.size());
157155

158156
const int32 normalizer = 1 << precision_;
@@ -168,7 +166,7 @@ class PmfToCdfOp : public OpKernel {
168166
if (sum > normalizer) {
169167
std::vector<PenaltyItem> queue;
170168
queue.reserve(cdf.size());
171-
for (int i = 0; i < cdf.size(); ++i) {
169+
for (absl::Span<int32>::size_type i = 0; i < cdf.size(); ++i) {
172170
queue.emplace_back(&cdf[i], pmf[i]);
173171
}
174172

@@ -185,7 +183,7 @@ class PmfToCdfOp : public OpKernel {
185183
} else if (sum < normalizer) {
186184
std::vector<GainItem> queue;
187185
queue.reserve(cdf.size());
188-
for (int i = 0; i < cdf.size(); ++i) {
186+
for (absl::Span<int32>::size_type i = 0; i < cdf.size(); ++i) {
189187
queue.emplace_back(&cdf[i], pmf[i]);
190188
}
191189

tensorflow_compression/cc/kernels/range_coding_helper_kernels_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
#include <limits>
1818
#include <random>
1919

20+
#include "absl/types/span.h"
2021
#include "tensorflow/core/framework/fake_input.h"
2122
#include "tensorflow/core/framework/node_def.proto.h"
2223
#include "tensorflow/core/framework/node_def_builder.h"
@@ -25,15 +26,13 @@ limitations under the License.
2526
#include "tensorflow/core/framework/types.proto.h"
2627
#include "tensorflow/core/kernels/ops_testutil.h"
2728
#include "tensorflow/core/lib/core/status_test_util.h"
28-
#include "tensorflow/core/lib/gtl/array_slice.h"
2929
#include "tensorflow/core/lib/random/philox_random.h"
3030
#include "tensorflow/core/lib/random/simple_philox.h"
3131
#include "tensorflow/core/platform/stacktrace_handler.h"
3232
#include "tensorflow/core/platform/test.h"
3333

3434
namespace tensorflow_compression {
3535
namespace {
36-
namespace gtl = tensorflow::gtl;
3736
namespace random = tensorflow::random;
3837
using tensorflow::DT_FLOAT;
3938
using tensorflow::NodeDefBuilder;
@@ -56,8 +55,7 @@ class PmfToQuantizedCdfOpTest : public OpsTestBase {
5655
inputs_.emplace_back(input);
5756
}
5857

59-
void GenerateData(random::SimplePhilox* rand,
60-
gtl::MutableArraySlice<float> slice) {
58+
void GenerateData(random::SimplePhilox* rand, absl::Span<float> slice) {
6159
constexpr float minimum = std::numeric_limits<float>::epsilon();
6260
float sum = 0;
6361
for (float& value : slice) {

tensorflow_compression/cc/kernels/range_coding_kernels.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ limitations under the License.
2121
#include <type_traits>
2222
#include <vector>
2323

24+
#include "absl/types/span.h"
2425
#include "tensorflow/core/framework/op_kernel.h"
2526
#include "tensorflow/core/framework/tensor.h"
2627
#include "tensorflow/core/framework/tensor_shape.h"
2728
#include "tensorflow/core/framework/tensor_types.h"
2829
#include "tensorflow/core/lib/core/errors.h"
2930
#include "tensorflow/core/lib/core/status.h"
30-
#include "tensorflow/core/lib/gtl/array_slice.h"
3131
#include "tensorflow/core/platform/logging.h"
3232
#include "tensorflow/core/platform/macros.h"
3333
#include "tensorflow/core/platform/types.h"
@@ -37,7 +37,6 @@ limitations under the License.
3737
namespace tensorflow_compression {
3838
namespace {
3939
namespace errors = tensorflow::errors;
40-
namespace gtl = tensorflow::gtl;
4140
using tensorflow::DEVICE_CPU;
4241
using tensorflow::int16;
4342
using tensorflow::int32;
@@ -63,8 +62,8 @@ using tensorflow::uint8;
6362
template <typename T, typename U, int N>
6463
class BroadcastRange {
6564
public:
66-
BroadcastRange(T* data_pointer, gtl::ArraySlice<int64> data_shape,
67-
const U* cdf_pointer, gtl::ArraySlice<int64> cdf_shape)
65+
BroadcastRange(T* data_pointer, absl::Span<const int64> data_shape,
66+
const U* cdf_pointer, absl::Span<const int64> cdf_shape)
6867
: data_pointer_(data_pointer), cdf_pointer_(cdf_pointer) {
6968
CHECK(!data_shape.empty());
7069
CHECK_EQ(data_shape.size(), N);
@@ -160,7 +159,7 @@ tensorflow::Status CheckCdfValues(int precision,
160159

161160
const int32 upper_bound = 1 << precision;
162161
for (int64 i = 0; i < cdf.dimension(0); ++i) {
163-
auto slice = tensorflow::gtl::ArraySlice<int32>(&cdf(i, 0), size);
162+
auto slice = absl::Span<const int32>(&cdf(i, 0), size);
164163
if (slice[0] != 0 || slice[size - 1] != upper_bound) {
165164
return errors::InvalidArgument("CDF should start from 0 and end at ",
166165
upper_bound, ": cdf[0]=", slice[0],
@@ -233,9 +232,9 @@ class RangeEncodeOp : public OpKernel {
233232
private:
234233
template <int N>
235234
tensorflow::Status RangeEncodeImpl(TTypes<int16>::ConstFlat data,
236-
gtl::ArraySlice<int64> data_shape,
235+
absl::Span<const int64> data_shape,
237236
TTypes<int32>::ConstMatrix cdf,
238-
gtl::ArraySlice<int64> cdf_shape,
237+
absl::Span<const int64> cdf_shape,
239238
string* output) const {
240239
const int64 data_size = data.size();
241240
const int64 cdf_size = cdf.size();
@@ -345,9 +344,9 @@ class RangeDecodeOp : public OpKernel {
345344
private:
346345
template <int N>
347346
tensorflow::Status RangeDecodeImpl(TTypes<int16>::Flat output,
348-
gtl::ArraySlice<int64> output_shape,
347+
absl::Span<const int64> output_shape,
349348
TTypes<int32>::ConstMatrix cdf,
350-
gtl::ArraySlice<int64> cdf_shape,
349+
absl::Span<const int64> cdf_shape,
351350
const string& encoded) const {
352351
BroadcastRange<int16, int32, N> view{output.data(), output_shape,
353352
cdf.data(), cdf_shape};
@@ -357,7 +356,7 @@ class RangeDecodeOp : public OpKernel {
357356
const int64 output_size = output.size();
358357
const int64 cdf_size = cdf.size();
359358
const auto chip_size =
360-
static_cast<gtl::ArraySlice<int32>::size_type>(cdf.dimension(1));
359+
static_cast<absl::Span<const int32>::size_type>(cdf.dimension(1));
361360

362361
for (int64 i = 0; i < output_size; ++i) {
363362
const auto pair = view.Next();

tensorflow_compression/cc/kernels/range_coding_kernels_test.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
#include <random>
1818
#include <vector>
1919

20+
#include "absl/types/span.h"
2021
#include "tensorflow/core/common_runtime/shape_refiner.h"
2122
#include "tensorflow/core/framework/fake_input.h"
2223
#include "tensorflow/core/framework/node_def.proto.h"
@@ -31,7 +32,6 @@ limitations under the License.
3132
#include "tensorflow/core/kernels/ops_testutil.h"
3233
#include "tensorflow/core/lib/core/bits.h"
3334
#include "tensorflow/core/lib/core/status_test_util.h"
34-
#include "tensorflow/core/lib/gtl/array_slice.h"
3535
#include "tensorflow/core/lib/random/simple_philox.h"
3636
#include "tensorflow/core/platform/stacktrace_handler.h"
3737
#include "tensorflow/core/platform/test.h"
@@ -41,7 +41,6 @@ limitations under the License.
4141

4242
namespace tensorflow_compression {
4343
namespace {
44-
namespace gtl = tensorflow::gtl;
4544
namespace random = tensorflow::random;
4645
namespace test = tensorflow::test;
4746
using tensorflow::DT_INT16;
@@ -97,17 +96,17 @@ std::vector<int64> ComputeStrides(const TensorShape& shape) {
9796

9897
class RangeCoderOpsTest : public OpsTestBase {
9998
protected:
100-
Status RunEncodeOp(int precision, gtl::ArraySlice<Tensor> input,
99+
Status RunEncodeOp(int precision, absl::Span<const Tensor> input,
101100
Tensor* output) {
102101
return RunEncodeOpImpl(precision, input, 0, output);
103102
}
104103

105-
Status RunEncodeOpDebug(int precision, gtl::ArraySlice<Tensor> input,
104+
Status RunEncodeOpDebug(int precision, absl::Span<const Tensor> input,
106105
Tensor* output) {
107106
return RunEncodeOpImpl(precision, input, 1, output);
108107
}
109108

110-
Status RunEncodeOpImpl(int precision, gtl::ArraySlice<Tensor> input,
109+
Status RunEncodeOpImpl(int precision, absl::Span<const Tensor> input,
111110
int debug_level, Tensor* output) {
112111
TF_RETURN_IF_ERROR(NodeDefBuilder("encode", "RangeEncode")
113112
.Input(tensorflow::FakeInput(DT_INT16))
@@ -132,17 +131,17 @@ class RangeCoderOpsTest : public OpsTestBase {
132131
return Status::OK();
133132
}
134133

135-
Status RunDecodeOp(int precision, gtl::ArraySlice<Tensor> input,
134+
Status RunDecodeOp(int precision, absl::Span<const Tensor> input,
136135
Tensor* output) {
137136
return RunDecodeOpImpl(precision, input, 0, output);
138137
}
139138

140-
Status RunDecodeOpDebug(int precision, gtl::ArraySlice<Tensor> input,
139+
Status RunDecodeOpDebug(int precision, absl::Span<const Tensor> input,
141140
Tensor* output) {
142141
return RunDecodeOpImpl(precision, input, 1, output);
143142
}
144143

145-
Status RunDecodeOpImpl(int precision, gtl::ArraySlice<Tensor> input,
144+
Status RunDecodeOpImpl(int precision, absl::Span<const Tensor> input,
146145
int debug_level, Tensor* output) {
147146
TF_RETURN_IF_ERROR(NodeDefBuilder("decode", "RangeDecode")
148147
.Input(tensorflow::FakeInput(DT_STRING))

tensorflow_compression/cc/kernels/unbounded_index_range_coding_kernels.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ limitations under the License.
2222

2323
#define EIGEN_USE_THREADS
2424

25+
#include "absl/types/span.h"
2526
#include "tensorflow/core/framework/op_kernel.h"
2627
#include "tensorflow/core/framework/tensor.h"
2728
#include "tensorflow/core/framework/tensor_shape.h"
2829
#include "tensorflow/core/framework/tensor_types.h"
2930
#include "tensorflow/core/lib/core/errors.h"
3031
#include "tensorflow/core/lib/core/status.h"
31-
#include "tensorflow/core/lib/gtl/array_slice.h"
3232
#include "tensorflow/core/platform/logging.h"
3333
#include "tensorflow/core/platform/macros.h"
3434
#include "tensorflow/core/platform/types.h"
@@ -37,7 +37,6 @@ limitations under the License.
3737
namespace tensorflow_compression {
3838
namespace {
3939
namespace errors = tensorflow::errors;
40-
namespace gtl = tensorflow::gtl;
4140
using tensorflow::DEVICE_CPU;
4241
using tensorflow::int16;
4342
using tensorflow::int32;
@@ -215,7 +214,7 @@ class UnboundedIndexRangeEncodeOp : public OpKernel {
215214
value -= offset(cdf_index);
216215
// If outside of this range, map value to non-negative integer overflow.
217216
// NOTE: It might be a good idea to check overflow is within uint32 range.
218-
uint32 overflow;
217+
uint32 overflow = 0;
219218
if (value < 0) {
220219
overflow = -2 * value - 1;
221220
value = max_value;
@@ -334,7 +333,7 @@ class UnboundedIndexRangeDecodeOp : public OpKernel {
334333

335334
const int32* cdf_slice = &cdf(cdf_index, 0);
336335
int32 value = decoder.Decode(
337-
gtl::ArraySlice<int32>(cdf_slice, max_value + 2), precision_);
336+
absl::Span<const int32>(cdf_slice, max_value + 2), precision_);
338337

339338
// Decode overflow using variable length code.
340339
if (value == max_value) {

tensorflow_compression/cc/kernels/unbounded_index_range_coding_kernels_test.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
#include <random>
2020
#include <vector>
2121

22+
#include "absl/types/span.h"
2223
#include "tensorflow/core/common_runtime/shape_refiner.h"
2324
#include "tensorflow/core/framework/fake_input.h"
2425
#include "tensorflow/core/framework/node_def.proto.h"
@@ -33,7 +34,6 @@ limitations under the License.
3334
#include "tensorflow/core/kernels/ops_testutil.h"
3435
#include "tensorflow/core/lib/core/bits.h"
3536
#include "tensorflow/core/lib/core/status_test_util.h"
36-
#include "tensorflow/core/lib/gtl/array_slice.h"
3737
#include "tensorflow/core/lib/random/distribution_sampler.h"
3838
#include "tensorflow/core/lib/random/simple_philox.h"
3939
#include "tensorflow/core/platform/stacktrace_handler.h"
@@ -44,7 +44,6 @@ limitations under the License.
4444

4545
namespace tensorflow_compression {
4646
namespace {
47-
namespace gtl = tensorflow::gtl;
4847
namespace random = tensorflow::random;
4948
namespace test = tensorflow::test;
5049
using tensorflow::DT_INT32;
@@ -141,18 +140,18 @@ void BuildDataAndCdf(random::SimplePhilox* gen, Tensor* data_tensor,
141140
class UnboundedIndexRangeCoderOpsTest : public OpsTestBase {
142141
protected:
143142
Status RunEncodeOpDebug(int precision, int overflow_width,
144-
gtl::ArraySlice<Tensor> input) {
143+
absl::Span<const Tensor> input) {
145144
Tensor unused;
146145
return RunEncodeOpImpl(precision, overflow_width, 1, input, &unused);
147146
}
148147

149148
Status RunEncodeOp(int precision, int overflow_width,
150-
gtl::ArraySlice<Tensor> input, Tensor* output) {
149+
absl::Span<const Tensor> input, Tensor* output) {
151150
return RunEncodeOpImpl(precision, overflow_width, 0, input, output);
152151
}
153152

154153
Status RunEncodeOpImpl(int precision, int overflow_width, int debug_level,
155-
gtl::ArraySlice<Tensor> input, Tensor* output) {
154+
absl::Span<const Tensor> input, Tensor* output) {
156155
NodeDefBuilder builder("encode", "UnboundedIndexRangeEncode");
157156
for (const Tensor& tensor : input) {
158157
builder.Input(tensorflow::FakeInput(tensor.dtype()));
@@ -179,18 +178,18 @@ class UnboundedIndexRangeCoderOpsTest : public OpsTestBase {
179178
}
180179

181180
Status RunDecodeOpDebug(int precision, int overflow_width,
182-
gtl::ArraySlice<Tensor> input) {
181+
absl::Span<const Tensor> input) {
183182
Tensor unused;
184183
return RunDecodeOpImpl(precision, overflow_width, 1, input, &unused);
185184
}
186185

187186
Status RunDecodeOp(int precision, int overflow_width,
188-
gtl::ArraySlice<Tensor> input, Tensor* output) {
187+
absl::Span<const Tensor> input, Tensor* output) {
189188
return RunDecodeOpImpl(precision, overflow_width, 0, input, output);
190189
}
191190

192191
Status RunDecodeOpImpl(int precision, int overflow_width, int debug_level,
193-
gtl::ArraySlice<Tensor> input, Tensor* output) {
192+
absl::Span<const Tensor> input, Tensor* output) {
194193
NodeDefBuilder builder("decode", "UnboundedIndexRangeDecode");
195194
for (const Tensor& tensor : input) {
196195
builder.Input(tensorflow::FakeInput(tensor.dtype()));

0 commit comments

Comments
 (0)