aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/sparse_tensors_map_ops.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/kernels/sparse_tensors_map_ops.cc')
-rw-r--r--tensorflow/core/kernels/sparse_tensors_map_ops.cc36
1 files changed, 24 insertions, 12 deletions
diff --git a/tensorflow/core/kernels/sparse_tensors_map_ops.cc b/tensorflow/core/kernels/sparse_tensors_map_ops.cc
index 2aadd92475..74fa3a15f0 100644
--- a/tensorflow/core/kernels/sparse_tensors_map_ops.cc
+++ b/tensorflow/core/kernels/sparse_tensors_map_ops.cc
@@ -93,8 +93,9 @@ class SparseTensorsMap : public ResourceBase {
const Tensor* ix = sp_iter->second.indices.AccessTensor(ctx);
const Tensor* values = sp_iter->second.values.AccessTensor(ctx);
const auto& shape = sp_iter->second.shape;
- sparse_tensors->emplace_back(*ix, *values, shape);
-
+ SparseTensor tensor;
+ TF_RETURN_IF_ERROR(SparseTensor::Create(*ix, *values, shape, &tensor));
+ sparse_tensors->push_back(std::move(tensor));
sp_tensors_.erase(sp_iter);
}
}
@@ -195,7 +196,9 @@ class AddSparseToTensorsMapOp : public SparseTensorAccessingOp {
TensorShapeUtils::MakeShape(input_shape->vec<int64>().data(),
input_shape->NumElements(),
&input_shape_object));
- SparseTensor st(*input_indices, *input_values, input_shape_object);
+ SparseTensor st;
+ OP_REQUIRES_OK(context, SparseTensor::Create(*input_indices, *input_values,
+ input_shape_object, &st));
int64 handle;
OP_REQUIRES_OK(context, map->AddSparseTensor(context, st, &handle));
@@ -253,8 +256,10 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp {
TensorShape tensor_input_shape(input_shape->vec<int64>());
gtl::InlinedVector<int64, 8> std_order(rank);
std::iota(std_order.begin(), std_order.end(), 0);
- SparseTensor input_st(*input_indices, *input_values, tensor_input_shape,
- std_order);
+ SparseTensor input_st;
+ OP_REQUIRES_OK(context, SparseTensor::Create(*input_indices, *input_values,
+ tensor_input_shape, std_order,
+ &input_st));
auto input_shape_t = input_shape->vec<int64>();
const int64 N = input_shape_t(0);
@@ -300,7 +305,10 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp {
output_values_t(i) = values(i);
}
- SparseTensor st_i(output_indices, output_values, output_shape);
+ SparseTensor st_i;
+ OP_REQUIRES_OK(context,
+ SparseTensor::Create(output_indices, output_values,
+ output_shape, &st_i));
int64 handle;
OP_REQUIRES_OK(context, map->AddSparseTensor(context, st_i, &handle));
sparse_handles_t(b) = handle;
@@ -311,7 +319,9 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp {
if (visited.size() < N) {
Tensor empty_indices(DT_INT64, {0, rank - 1});
Tensor empty_values(DataTypeToEnum<T>::value, {0});
- SparseTensor empty_st(empty_indices, empty_values, output_shape);
+ SparseTensor empty_st;
+ OP_REQUIRES_OK(context, SparseTensor::Create(empty_indices, empty_values,
+ output_shape, &empty_st));
for (int64 b = 0; b < N; ++b) {
// We skipped this batch entry.
@@ -466,13 +476,15 @@ class TakeManySparseFromTensorsMapOp : public SparseTensorAccessingOp {
std::vector<SparseTensor> tensors_to_concat;
tensors_to_concat.reserve(N);
for (int i = 0; i < N; ++i) {
- tensors_to_concat.emplace_back(std::move(indices_to_concat[i]),
- std::move(values_to_concat[i]),
- preconcat_shape, std_order);
+ SparseTensor tensor;
+ OP_REQUIRES_OK(context,
+ SparseTensor::Create(std::move(indices_to_concat[i]),
+ std::move(values_to_concat[i]),
+ preconcat_shape, std_order, &tensor));
+ tensors_to_concat.push_back(std::move(tensor));
}
- SparseTensor output(SparseTensor::Concat<T>(tensors_to_concat));
-
+ auto output = SparseTensor::Concat<T>(tensors_to_concat);
Tensor final_output_shape(DT_INT64, TensorShape({output.dims()}));
std::copy_n(output.shape().data(), output.dims(),