| 75 | } |
| 76 | |
| 77 | TfLiteStatus CopyFromBufferHandle(TfLiteContext* context, |
| 78 | TfLiteDelegate* delegate, |
| 79 | TfLiteBufferHandle buffer_handle, |
| 80 | TfLiteTensor* output) { |
| 81 | BufferMap* buffer_map = |
| 82 | reinterpret_cast<DelegateData*>(delegate->data_)->GetBufferMap(context); |
| 83 | |
| 84 | if (!buffer_map->HasTensor(buffer_handle)) { |
| 85 | context->ReportError(context, "Invalid tensor index %d.", buffer_handle); |
| 86 | return kTfLiteError; |
| 87 | } |
| 88 | |
| 89 | tensorflow::Tensor t = buffer_map->GetTensor(buffer_handle); |
| 90 | |
| 91 | if (output->type == kTfLiteString) { |
| 92 | if (t.dtype() != tensorflow::DT_STRING) { |
| 93 | context->ReportError(context, |
| 94 | "Inconsistent type for TF string tensor index %d.", |
| 95 | buffer_handle); |
| 96 | return kTfLiteError; |
| 97 | } |
| 98 | DynamicBuffer dynamic_buffer; |
| 99 | |
| 100 | auto tf_data = t.flat<tensorflow::tstring>(); |
| 101 | for (int i = 0; i < t.NumElements(); ++i) { |
| 102 | dynamic_buffer.AddString(tf_data(i).data(), tf_data(i).size()); |
| 103 | } |
| 104 | |
| 105 | dynamic_buffer.WriteToTensor(output, /*new_shape=*/nullptr); |
| 106 | return kTfLiteOk; |
| 107 | } |
| 108 | |
| 109 | tensorflow::StringPiece t_data = t.tensor_data(); |
| 110 | |
| 111 | if (output->bytes != t_data.size()) { |
| 112 | context->ReportError(context, |
| 113 | absl::StrCat("The given ", output->bytes, |
| 114 | " bytes are not enough to store " |
| 115 | "TensorFlow's aligned buffer of size ", |
| 116 | t_data.size(), " bytes.") |
| 117 | .c_str()); |
| 118 | return kTfLiteError; |
| 119 | } |
| 120 | |
| 121 | memcpy(output->data.raw, t_data.data(), t_data.size()); |
| 122 | return kTfLiteOk; |
| 123 | } |
| 124 | |
| 125 | } // namespace delegate |
| 126 | } // namespace flex |
no test coverage detected