Skip to content

Commit 3971d7a

Browse files
No public description
PiperOrigin-RevId: 880612638
1 parent 99eabff commit 3971d7a

25 files changed

Lines changed: 343 additions & 343 deletions

tensorflow_text/core/kernels/constrained_sequence.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ScoreAccessor::ScoreAccessor(const Tensor &score_tensor,
3838
data_ = score_tensor.flat<float>().data();
3939
if (lengths_tensor.dtype() == DT_INT64) {
4040
use_long_lengths_ = true;
41-
long_lengths_ = lengths_tensor.flat<int64>().data();
41+
long_lengths_ = lengths_tensor.flat<int64_t>().data();
4242
} else {
4343
use_long_lengths_ = false;
4444
lengths_ = lengths_tensor.flat<int>().data();
@@ -66,7 +66,7 @@ float ScoreAccessor::GetScore(int batch_idx, int step_idx,
6666
return data_[batch_offset_ * batch_idx + step_offset_ * step_idx + score_idx];
6767
}
6868

69-
int64 ScoreAccessor::GetLength(int batch_idx) const {
69+
int64_t ScoreAccessor::GetLength(int batch_idx) const {
7070
DCHECK_LE(batch_idx, batch_size_);
7171
if (use_long_lengths_) {
7272
return long_lengths_[batch_idx];
@@ -82,18 +82,18 @@ bool ScoreAccessor::has_explicit_batch() const { return has_explicit_batch_; }
8282

8383
// Perform Viterbi analysis on a single batch item.
8484
void ViterbiAnalysis(
85-
const ScoreAccessor &scores,
86-
const tensorflow::TTypes<const float>::Matrix &transition_weights,
87-
const tensorflow::TTypes<const bool>::Matrix &allowed_transitions,
85+
const ScoreAccessor& scores,
86+
const tensorflow::TTypes<const float>::Matrix& transition_weights,
87+
const tensorflow::TTypes<const bool>::Matrix& allowed_transitions,
8888
const int batch, bool use_log_space, bool use_start_end_states,
89-
int32 *output_data) {
89+
int32_t* output_data) {
9090
VLOG(2) << "Analyzing batch " << batch;
9191
const bool has_transition_weights = transition_weights.size() != 0;
9292
const bool has_allowed_transitions = allowed_transitions.size() != 0;
9393
const int num_states = scores.num_scores();
9494
const int out_of_bounds_index = num_states;
9595

96-
int64 num_steps = scores.GetLength(batch);
96+
int64_t num_steps = scores.GetLength(batch);
9797

9898
// Create two vectors to hold scores. These will be bound to referents later
9999
// so the names here are somewhat irrelevant.
@@ -344,31 +344,31 @@ void ViterbiAnalysis(
344344
if (best_source_state == kErrorState) {
345345
// If the best source is an error state, the path is unknowable. Report
346346
// error states for the whole sequence.
347-
for (int64 i = 0; i < scores.GetLength(batch); ++i) {
347+
for (int64_t i = 0; i < scores.GetLength(batch); ++i) {
348348
output_data[i] = kErrorState;
349349
}
350350
} else {
351351
// If the best source is a 'real' state, report the state path.
352352
int steps_to_report = scores.GetLength(batch);
353353
int previous_state = best_source_state;
354-
for (int64 i = steps_to_report - 1; i >= 0; --i) {
354+
for (int64_t i = steps_to_report - 1; i >= 0; --i) {
355355
output_data[i] = previous_state;
356356
previous_state = backpointers[i][previous_state];
357357
}
358358
}
359359
}
360360

361361
void GreedyAnalysis(
362-
const ScoreAccessor &scores,
363-
const tensorflow::TTypes<const float>::Matrix &transition_weights,
364-
const tensorflow::TTypes<const bool>::Matrix &allowed_transitions,
362+
const ScoreAccessor& scores,
363+
const tensorflow::TTypes<const float>::Matrix& transition_weights,
364+
const tensorflow::TTypes<const bool>::Matrix& allowed_transitions,
365365
int batch, bool use_log_space, bool use_start_end_states,
366-
int32 *output_data) {
366+
int32_t* output_data) {
367367
const bool has_transition_weights = transition_weights.size() != 0;
368368
const bool has_allowed_transitions = allowed_transitions.size() != 0;
369369
const int num_states = scores.num_scores();
370370
const int out_of_bounds_index = num_states;
371-
int64 num_steps = scores.GetLength(batch);
371+
int64_t num_steps = scores.GetLength(batch);
372372

373373
for (int step = 0; step < num_steps; ++step) {
374374
// Do final step calculations if this is the final step in the sequence

tensorflow_text/core/kernels/constrained_sequence.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ScoreAccessor {
3030
// Get a score out of the data tensor.
3131
float GetScore(int batch_idx, int step_idx, int score_idx) const;
3232

33-
int64 GetLength(int batch_idx) const;
33+
int64_t GetLength(int batch_idx) const;
3434

3535
int batch_size() const;
3636
int num_steps() const;
@@ -43,7 +43,7 @@ class ScoreAccessor {
4343

4444
// A pointer into the underlying data of the lengths tensor. Not owned.
4545
const int *lengths_;
46-
const int64 *long_lengths_;
46+
const int64_t* long_lengths_;
4747

4848
// Whether the passed lengths tensor is int32 or int64.
4949
bool use_long_lengths_;
@@ -72,19 +72,19 @@ class ScoreAccessor {
7272

7373
// Perform Viterbi analysis on a single batch item.
7474
void ViterbiAnalysis(
75-
const ScoreAccessor &scores,
76-
const tensorflow::TTypes<const float>::Matrix &transition_weights,
77-
const tensorflow::TTypes<const bool>::Matrix &allowed_transitions,
75+
const ScoreAccessor& scores,
76+
const tensorflow::TTypes<const float>::Matrix& transition_weights,
77+
const tensorflow::TTypes<const bool>::Matrix& allowed_transitions,
7878
const int batch, bool use_log_space, bool use_start_end_states,
79-
int32 *output_data);
79+
int32_t* output_data);
8080

8181
// Perform a greedy analysis on a single batch item.
8282
void GreedyAnalysis(
83-
const ScoreAccessor &scores,
84-
const tensorflow::TTypes<const float>::Matrix &transition_weights,
85-
const tensorflow::TTypes<const bool>::Matrix &allowed_transitions,
83+
const ScoreAccessor& scores,
84+
const tensorflow::TTypes<const float>::Matrix& transition_weights,
85+
const tensorflow::TTypes<const bool>::Matrix& allowed_transitions,
8686
int batch, bool use_log_space, bool use_start_end_states,
87-
int32 *output_data);
87+
int32_t* output_data);
8888

8989
} // namespace text
9090
} // namespace tensorflow

tensorflow_text/core/kernels/constrained_sequence_kernel.cc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ namespace {
5757

5858
// Validate that a given constraint tensor is the proper shape (dimension
5959
// 2, with shape [num_states + 1, num_states + 1].
60-
absl::Status ValidateConstraintTensor(const Tensor &tensor,
60+
absl::Status ValidateConstraintTensor(const Tensor& tensor,
6161
const int num_states,
6262
const bool use_start_end_states,
63-
const string &name) {
63+
const std::string& name) {
6464
if (tensor.shape().dims() != 2) {
65-
return InvalidArgument(
66-
tensorflow::strings::StrCat(name, " must be of rank 2"));
65+
return InvalidArgument(absl::StrCat(name, " must be of rank 2"));
6766
}
6867
int expected_size = use_start_end_states ? num_states + 1 : num_states;
6968
if (tensor.shape().dim_size(0) != expected_size) {
@@ -110,7 +109,7 @@ class ConstrainedSequence : public OpKernel {
110109
const int num_scores = scores.num_scores();
111110

112111
OP_REQUIRES(context, lengths_tensor.NumElements() == batch_size,
113-
InvalidArgument(tensorflow::strings::StrCat(
112+
InvalidArgument(absl::StrCat(
114113
"There should be exactly one length for every batch "
115114
"element. Found ",
116115
lengths_tensor.NumElements(),
@@ -124,7 +123,7 @@ class ConstrainedSequence : public OpKernel {
124123
int max_length = 0;
125124
int total_length = 0;
126125
for (int i = 0; i < batch_size; ++i) {
127-
int64 length = scores.GetLength(i);
126+
int64_t length = scores.GetLength(i);
128127
total_length += length;
129128
if (length > max_length) {
130129
max_length = length;
@@ -182,7 +181,7 @@ class ConstrainedSequence : public OpKernel {
182181
Tensor *output;
183182
OP_REQUIRES_OK(context, context->allocate_output(
184183
0, TensorShape({total_length}), &output));
185-
int32 *output_data = output->flat<int32>().data();
184+
int32_t* output_data = output->flat<int32_t>().data();
186185

187186
Tensor *offsets;
188187
OP_REQUIRES_OK(context, context->allocate_output(
@@ -192,7 +191,7 @@ class ConstrainedSequence : public OpKernel {
192191

193192
for (int batch = 0; batch < batch_size; ++batch) {
194193
int step_offset = offset_data[batch];
195-
int64 num_steps = scores.GetLength(batch);
194+
int64_t num_steps = scores.GetLength(batch);
196195
offset_data[batch + 1] = step_offset + num_steps;
197196
if (use_viterbi_) {
198197
DoViterbiAnalysis(transition_weights, allowed_transitions, batch,
@@ -207,18 +206,18 @@ class ConstrainedSequence : public OpKernel {
207206
private:
208207
// Perform Viterbi analysis on a single batch item.
209208
void DoViterbiAnalysis(
210-
const tensorflow::TTypes<const float>::Matrix &transition_weights,
211-
const tensorflow::TTypes<const bool>::Matrix &allowed_transitions,
212-
const int batch, const ScoreAccessor &scores, int32 *output_data) {
209+
const tensorflow::TTypes<const float>::Matrix& transition_weights,
210+
const tensorflow::TTypes<const bool>::Matrix& allowed_transitions,
211+
const int batch, const ScoreAccessor& scores, int32_t* output_data) {
213212
ViterbiAnalysis(scores, transition_weights, allowed_transitions, batch,
214213
use_log_space_, use_start_end_states_, output_data);
215214
}
216215

217216
// Perform a greedy analysis on a single batch item.
218217
void DoGreedyAnalysis(
219-
const tensorflow::TTypes<const float>::Matrix &transition_weights,
220-
const tensorflow::TTypes<const bool>::Matrix &allowed_transitions,
221-
int batch, const ScoreAccessor &scores, int32 *output_data) {
218+
const tensorflow::TTypes<const float>::Matrix& transition_weights,
219+
const tensorflow::TTypes<const bool>::Matrix& allowed_transitions,
220+
int batch, const ScoreAccessor& scores, int32_t* output_data) {
222221
GreedyAnalysis(scores, transition_weights, allowed_transitions, batch,
223222
use_log_space_, use_start_end_states_, output_data);
224223
}
@@ -251,8 +250,8 @@ class ConstrainedSequence : public OpKernel {
251250
.TypeConstraint<int64>("Tsplits"), \
252251
ConstrainedSequence<Tin, int64>)
253252

254-
REGISTER_KERNELS(int32);
255-
REGISTER_KERNELS(int64);
253+
REGISTER_KERNELS(int32_t);
254+
REGISTER_KERNELS(int64_t);
256255

257256
#undef REGISTER_KERNELS
258257

tensorflow_text/core/kernels/constrained_sequence_kernel_input_validation_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ TEST_F(ConstrainedSequenceInputValidationTest, WorksWithInt64InputLengths) {
7575
}});
7676

7777
// Add the sequence_lengths input.
78-
std::vector<int64> input_lengths({1, 1, 1});
79-
AddInputFromArray<int64>(TensorShape({3}), input_lengths);
78+
std::vector<int64_t> input_lengths({1, 1, 1});
79+
AddInputFromArray<int64_t>(TensorShape({3}), input_lengths);
8080

8181
// Add the allowed_transitions input.
8282
AddInputFromArray<bool>(TensorShape({5, 5}),
@@ -99,8 +99,8 @@ TEST_F(ConstrainedSequenceInputValidationTest, WorksWithInt64InputLengths) {
9999
// The third sequence's highest score is 0, which is ok.
100100

101101
// Validate the output.
102-
std::vector<int32> expected_transitions({1, 3, 0});
103-
std::vector<int64> expected_offsets({0, 1, 2, 3});
102+
std::vector<int32_t> expected_transitions({1, 3, 0});
103+
std::vector<int64_t> expected_offsets({0, 1, 2, 3});
104104

105105
// Validate the output.
106106
EXPECT_THAT(*GetOutput(0), VectorEq(expected_transitions));

tensorflow_text/core/kernels/disjoint_set_forest_test.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class DisjointSetForestTest : public ::testing::Test {
6262
};
6363

6464
using Forests = ::testing::Types<
65-
DisjointSetForest<uint8, false>, DisjointSetForest<uint8, true>,
66-
DisjointSetForest<uint16, false>, DisjointSetForest<uint16, true>,
67-
DisjointSetForest<uint32, false>, DisjointSetForest<uint32, true>,
68-
DisjointSetForest<uint64, false>, DisjointSetForest<uint64, true>>;
65+
DisjointSetForest<uint8_t, false>, DisjointSetForest<uint8_t, true>,
66+
DisjointSetForest<uint16_t, false>, DisjointSetForest<uint16_t, true>,
67+
DisjointSetForest<uint32_t, false>, DisjointSetForest<uint32_t, true>,
68+
DisjointSetForest<uint64_t, false>, DisjointSetForest<uint64_t, true>>;
6969
TYPED_TEST_SUITE(DisjointSetForestTest, Forests);
7070

7171
TYPED_TEST(DisjointSetForestTest, DefaultEmpty) {
@@ -111,12 +111,13 @@ TYPED_TEST(DisjointSetForestTest, Populated) {
111111
// merged set can be controlled.
112112
class DisjointSetForestNoUnionByRankTest : public ::testing::Test {
113113
protected:
114-
using Forest = DisjointSetForest<uint32, false>;
114+
using Forest = DisjointSetForest<uint32_t, false>;
115115

116116
// Expects that the roots of the |forest| match |expected_roots|.
117-
void ExpectRoots(const std::vector<uint32> &expected_roots, Forest *forest) {
117+
void ExpectRoots(const std::vector<uint32_t>& expected_roots,
118+
Forest* forest) {
118119
ASSERT_EQ(expected_roots.size(), forest->size());
119-
for (uint32 i = 0; i < forest->size(); ++i) {
120+
for (uint32_t i = 0; i < forest->size(); ++i) {
120121
EXPECT_EQ(expected_roots[i], forest->FindRoot(i));
121122
}
122123
}

0 commit comments

Comments
 (0)