'convert_string' superfluous after cl/318933001
PiperOrigin-RevId: 327255887 Change-Id: Ia6d88299ee30caf961408c6afcc6fda19fbaefa2
This commit is contained in:
parent
00be61c8dd
commit
44396f47f6
@ -57,15 +57,10 @@ class ImmediateExecutionContext : public AbstractContext {
|
||||
|
||||
// Create a tensor instance from the given data buffer and description.
|
||||
// `memory_releaser` will be called on destruction, and it's responsible for
|
||||
// cleaning up the underlying buffer. `convert_string` indicates whether it
|
||||
// has to handle tstring conversion. Expected to be removed once tstring
|
||||
// migration is done.
|
||||
virtual AbstractTensorInterface* CreateTensor(DataType dtype,
|
||||
const int64_t* dims,
|
||||
int num_dims, void* data,
|
||||
size_t len, bool convert_string,
|
||||
MemoryReleaser memory_releaser,
|
||||
void* memory_releaser_arg) = 0;
|
||||
// cleaning up the underlying buffer.
|
||||
virtual AbstractTensorInterface* CreateTensor(
|
||||
DataType dtype, const int64_t* dims, int num_dims, void* data, size_t len,
|
||||
MemoryReleaser memory_releaser, void* memory_releaser_arg) = 0;
|
||||
|
||||
// Create a handle to wrap and manage a Tensor
|
||||
virtual ImmediateExecutionTensorHandle* CreateLocalHandle(
|
||||
|
@ -170,24 +170,15 @@ AbstractTensorInterface* EagerContext::CreateTensor(
|
||||
|
||||
AbstractTensorInterface* EagerContext::CreateTensor(
|
||||
DataType dtype, const int64_t* dims, int num_dims, void* data, size_t len,
|
||||
bool convert_string, MemoryReleaser memory_releaser,
|
||||
void* memory_releaser_arg) {
|
||||
MemoryReleaser memory_releaser, void* memory_releaser_arg) {
|
||||
TF_Tensor* tensor_wrapper =
|
||||
TF_NewTensor(static_cast<TF_DataType>(dtype), dims, num_dims, data, len,
|
||||
memory_releaser, memory_releaser_arg);
|
||||
|
||||
if (convert_string) {
|
||||
tensorflow::Tensor tensor;
|
||||
Status status = TF_TensorToTensor(tensor_wrapper, &tensor);
|
||||
TF_DeleteTensor(tensor_wrapper);
|
||||
if (!status.ok()) return nullptr;
|
||||
return new TensorInterface(std::move(tensor));
|
||||
} else {
|
||||
AbstractTensorInterface* result = nullptr;
|
||||
std::swap(result, tensor_wrapper->tensor);
|
||||
TF_DeleteTensor(tensor_wrapper);
|
||||
return result;
|
||||
}
|
||||
AbstractTensorInterface* result = nullptr;
|
||||
std::swap(result, tensor_wrapper->tensor);
|
||||
TF_DeleteTensor(tensor_wrapper);
|
||||
return result;
|
||||
}
|
||||
|
||||
void EagerContext::ResetPFLR(const DeviceMgr* device_mgr, Env* env,
|
||||
|
@ -174,7 +174,6 @@ class EagerContext : public ImmediateExecutionContext, public core::RefCounted {
|
||||
DataType dtype, absl::Span<const int64> dim_sizes) override;
|
||||
AbstractTensorInterface* CreateTensor(DataType dtype, const int64_t* dims,
|
||||
int num_dims, void* data, size_t len,
|
||||
bool convert_string,
|
||||
MemoryReleaser memory_releaser,
|
||||
void* memory_releaser_arg) override;
|
||||
|
||||
|
@ -89,8 +89,7 @@ void TF_Run_wrapper_helper(TF_DeprecatedSession* session, const char* handle,
|
||||
input_names.push_back(key_string);
|
||||
|
||||
inputs_safe.emplace_back(make_safe(static_cast<TF_Tensor*>(nullptr)));
|
||||
s = NdarrayToTensor(nullptr /*ctx*/, value, &inputs_safe.back(),
|
||||
true /*convert_to_string*/);
|
||||
s = NdarrayToTensor(nullptr /*ctx*/, value, &inputs_safe.back());
|
||||
if (!s.ok()) {
|
||||
Set_TF_Status_from_Status(out_status, s);
|
||||
return;
|
||||
@ -383,7 +382,7 @@ void TF_SessionRun_wrapper_helper(TF_Session* session, const char* handle,
|
||||
std::vector<Safe_TF_TensorPtr> input_vals_safe;
|
||||
for (PyObject* ndarray : input_ndarrays) {
|
||||
input_vals_safe.emplace_back(make_safe(static_cast<TF_Tensor*>(nullptr)));
|
||||
s = NdarrayToTensor(nullptr, ndarray, &input_vals_safe.back(), true);
|
||||
s = NdarrayToTensor(nullptr, ndarray, &input_vals_safe.back());
|
||||
if (!s.ok()) {
|
||||
Set_TF_Status_from_Status(out_status, s);
|
||||
return;
|
||||
|
@ -470,7 +470,7 @@ Status TF_TensorToPyArray(Safe_TF_TensorPtr tensor, PyObject** out_ndarray) {
|
||||
}
|
||||
|
||||
Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray,
|
||||
Safe_TF_TensorPtr* ret, bool convert_string) {
|
||||
Safe_TF_TensorPtr* ret) {
|
||||
DCHECK(ret != nullptr);
|
||||
|
||||
// Make sure we dereference this array object in case of error, etc.
|
||||
@ -501,7 +501,7 @@ Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray,
|
||||
if (ctx) {
|
||||
*ret = make_safe(new TF_Tensor{tensorflow::unwrap(ctx)->CreateTensor(
|
||||
static_cast<tensorflow::DataType>(dtype), {}, 0, PyArray_DATA(array),
|
||||
size, convert_string, &DelayedNumpyDecref, array)});
|
||||
size, &DelayedNumpyDecref, array)});
|
||||
} else {
|
||||
*ret = make_safe(TF_NewTensor(dtype, {}, 0, PyArray_DATA(array), size,
|
||||
&DelayedNumpyDecref, array));
|
||||
@ -513,8 +513,7 @@ Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray,
|
||||
if (ctx) {
|
||||
*ret = make_safe(new TF_Tensor{tensorflow::unwrap(ctx)->CreateTensor(
|
||||
static_cast<tensorflow::DataType>(dtype), dims.data(), dims.size(),
|
||||
PyArray_DATA(array), size, convert_string, &DelayedNumpyDecref,
|
||||
array)});
|
||||
PyArray_DATA(array), size, &DelayedNumpyDecref, array)});
|
||||
} else {
|
||||
*ret = make_safe(TF_NewTensor(dtype, dims.data(), dims.size(),
|
||||
PyArray_DATA(array), size,
|
||||
@ -528,7 +527,7 @@ Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray,
|
||||
if (ctx) {
|
||||
*ret = make_safe(new TF_Tensor{tensorflow::unwrap(ctx)->CreateTensor(
|
||||
static_cast<tensorflow::DataType>(dtype), dims.data(), dims.size(),
|
||||
encoded, size, convert_string,
|
||||
encoded, size,
|
||||
[](void* data, size_t len, void* arg) {
|
||||
delete[] reinterpret_cast<tensorflow::tstring*>(data);
|
||||
},
|
||||
@ -551,8 +550,7 @@ TF_Tensor* TF_TensorFromTensor(const tensorflow::Tensor& src, Status* status);
|
||||
|
||||
Status NdarrayToTensor(PyObject* obj, Tensor* ret) {
|
||||
Safe_TF_TensorPtr tf_tensor = make_safe(static_cast<TF_Tensor*>(nullptr));
|
||||
Status s = NdarrayToTensor(nullptr /*ctx*/, obj, &tf_tensor,
|
||||
false /*convert_string*/);
|
||||
Status s = NdarrayToTensor(nullptr /*ctx*/, obj, &tf_tensor);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ Status TF_TensorToPyArray(Safe_TF_TensorPtr tensor, PyObject** out_ndarray);
|
||||
// Expected to be removed once tstring migration is done.
|
||||
ABSL_MUST_USE_RESULT
|
||||
Status NdarrayToTensor(TFE_Context* ctx, PyObject* ndarray,
|
||||
Safe_TF_TensorPtr* ret, bool convert_string);
|
||||
Safe_TF_TensorPtr* ret);
|
||||
|
||||
// Creates a tensor in 'ret' from the input Ndarray.
|
||||
// TODO(kkb): This is an old conversion function that does not support TFRT.
|
||||
|
@ -686,8 +686,7 @@ typedef Converter<bool> BoolConverter;
|
||||
// other.
|
||||
TFE_TensorHandle* NumpyToTFE_TensorHandle(TFE_Context* ctx, PyObject* obj) {
|
||||
Safe_TF_TensorPtr tf_tensor = make_safe(static_cast<TF_Tensor*>(nullptr));
|
||||
Status status = tensorflow::NdarrayToTensor(ctx, obj, &tf_tensor,
|
||||
true /*convert_string*/);
|
||||
Status status = tensorflow::NdarrayToTensor(ctx, obj, &tf_tensor);
|
||||
|
||||
if (TF_PREDICT_FALSE(!status.ok())) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
Loading…
Reference in New Issue
Block a user