Skip to content

Commit

Permalink
Drop indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
adityagoel4512 committed Jan 4, 2024
1 parent 42858bb commit 2b7638c
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions onnxruntime/core/providers/cpu/nn/string_concat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,44 @@ Status StringConcat::Compute(OpKernelContext* context) const {
ProcessBroadcastSpanFuncs broadcast_funcs{
[](BroadcastHelper& broadcast_helper) {
auto x = broadcast_helper.ScalarInput0<std::string>();
auto Y = broadcast_helper.SpanInput1<std::string>();
auto output = broadcast_helper.OutputSpan<std::string>();
auto y = broadcast_helper.SpanInput1<std::string>();
auto y_iter = y.begin();
auto output_iter = broadcast_helper.OutputSpan<std::string>().begin();
const auto x_size = x.length();
for (size_t i = 0; i < Y.size(); ++i) {
output[i].reserve(x_size + Y[i].length());
output[i].append(x);
output[i].append(Y[i]);
while (y_iter != y.end()) {
output_iter->reserve(x_size + y_iter->length());
output_iter->append(x);
output_iter->append(*y_iter);
y_iter++;
output_iter++;
}
},
[](BroadcastHelper& broadcast_helper) {
auto X = broadcast_helper.SpanInput0<std::string>();
auto x = broadcast_helper.SpanInput0<std::string>();
auto x_iter = x.begin();
auto y = broadcast_helper.ScalarInput1<std::string>();
auto output = broadcast_helper.OutputSpan<std::string>();
auto output_iter = broadcast_helper.OutputSpan<std::string>().begin();
const auto y_size = y.length();
for (size_t i = 0; i < X.size(); ++i) {
output[i].reserve(y_size + X[i].length());
output[i].append(X[i]);
output[i].append(y);
while (x_iter != x.end()) {
output_iter->reserve(y_size + x_iter->length());
output_iter->append(*x_iter);
output_iter->append(y);
x_iter++;
output_iter++;
}
},
[](BroadcastHelper& broadcast_helper) {
auto X = broadcast_helper.SpanInput0<std::string>();
auto Y = broadcast_helper.SpanInput1<std::string>();
auto x_iter = broadcast_helper.SpanInput0<std::string>().begin();
auto y_iter = broadcast_helper.SpanInput1<std::string>().begin();
auto output = broadcast_helper.OutputSpan<std::string>();
for (size_t i = 0; i < X.size(); ++i) {
output[i].reserve(X[i].length() + Y[i].length());
output[i].append(X[i]);
output[i].append(Y[i]);
auto output_iter = output.begin();
while (output_iter != output.end()) {
output_iter->reserve(x_iter->length() + y_iter->length());
output_iter->append(*x_iter);
output_iter->append(*y_iter);
x_iter++;
y_iter++;
output_iter++;
}
}};
UntypedBroadcastTwo(*context, broadcast_funcs);
Expand Down

0 comments on commit 2b7638c

Please sign in to comment.