!38992 clean code
Merge pull request !38992 from 于振华/clean_code_master_0727
This commit is contained in:
commit
bc7ce1124c
|
@ -550,11 +550,11 @@ bool IrExportBuilder::SetCSRTensorToProto(const AbstractBasePtr &abstract, mind_
|
|||
mind_ir::AttributeProto *indptr = attr_proto->add_values();
|
||||
bool res = SetAbstractToNodeProto(csr_tensor_abs->indptr(), indptr);
|
||||
mind_ir::AttributeProto *indices = attr_proto->add_values();
|
||||
res &= SetAbstractToNodeProto(csr_tensor_abs->indices(), indices);
|
||||
res = res && SetAbstractToNodeProto(csr_tensor_abs->indices(), indices);
|
||||
mind_ir::AttributeProto *values = attr_proto->add_values();
|
||||
res &= SetAbstractToNodeProto(csr_tensor_abs->values(), values);
|
||||
res = res && SetAbstractToNodeProto(csr_tensor_abs->values(), values);
|
||||
mind_ir::AttributeProto *shape = attr_proto->add_values();
|
||||
res &= SetAbstractToNodeProto(csr_tensor_abs->shape(), shape);
|
||||
res = res && SetAbstractToNodeProto(csr_tensor_abs->shape(), shape);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -565,9 +565,9 @@ bool IrExportBuilder::SetCOOTensorToProto(const AbstractBasePtr &abstract, mind_
|
|||
mind_ir::AttributeProto *indices = attr_proto->add_values();
|
||||
bool res = SetAbstractToNodeProto(coo_tensor_abs->indices(), indices);
|
||||
mind_ir::AttributeProto *values = attr_proto->add_values();
|
||||
res &= SetAbstractToNodeProto(coo_tensor_abs->values(), values);
|
||||
res = res && SetAbstractToNodeProto(coo_tensor_abs->values(), values);
|
||||
mind_ir::AttributeProto *shape = attr_proto->add_values();
|
||||
res &= SetAbstractToNodeProto(coo_tensor_abs->shape(), shape);
|
||||
res = res && SetAbstractToNodeProto(coo_tensor_abs->shape(), shape);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -3039,8 +3039,8 @@ void OnnxExporter::ExportPrimTensorCopySlices(const FuncGraphPtr &, const CNodeP
|
|||
[](auto x) { return x - 1; });
|
||||
size_t flat_end_index = RavelIndex(end_inclusive, x_shape) + 1;
|
||||
|
||||
size_t x_size = std::accumulate(x_shape.begin(), x_shape.end(), 1UL, std::multiplies<size_t>());
|
||||
size_t value_size = std::accumulate(value_shape.begin(), value_shape.end(), 1UL, std::multiplies<size_t>());
|
||||
int64_t x_size = std::accumulate(x_shape.begin(), x_shape.end(), 1, std::multiplies<int64_t>());
|
||||
size_t value_size = std::accumulate(value_shape.begin(), value_shape.end(), 1, std::multiplies<size_t>());
|
||||
MS_EXCEPTION_IF_CHECK_FAIL(value_size == flat_end_index - flat_begin_index, "Cannot copy 'value' to target slice");
|
||||
|
||||
auto flat_x_name = node_name + "_flat_x";
|
||||
|
@ -3048,8 +3048,7 @@ void OnnxExporter::ExportPrimTensorCopySlices(const FuncGraphPtr &, const CNodeP
|
|||
auto begin_slice_name = node_name + "_begin_slice";
|
||||
AddSliceOp(flat_x_name, begin_slice_name, {0}, {static_cast<int64_t>(flat_begin_index)}, {0}, {1}, graph_proto);
|
||||
auto end_slice_name = node_name + "_end_slice";
|
||||
AddSliceOp(flat_x_name, end_slice_name, {static_cast<int64_t>(flat_end_index)}, {static_cast<int64_t>(x_size)}, {0},
|
||||
{1}, graph_proto);
|
||||
AddSliceOp(flat_x_name, end_slice_name, {static_cast<int64_t>(flat_end_index)}, {x_size}, {0}, {1}, graph_proto);
|
||||
|
||||
auto flat_value_name = node_name + "_flat_value";
|
||||
AddReshapeOp(value_input_name, flat_value_name, {-1}, graph_proto);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "transform/graph_ir/transform_util.h"
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
#include "include/common/utils/convert_utils.h"
|
||||
#include "include/common/utils/utils.h"
|
||||
|
@ -202,9 +203,10 @@ GeTensorPtr ConvertStringTensor(const MeTensorPtr &tensor, const std::string &fo
|
|||
}
|
||||
size_t elements_num = (data_buff_size / single_char_offset) / string_max_length;
|
||||
std::vector<std::string> string_vector;
|
||||
char *string_element = new char[string_max_length];
|
||||
size_t string_length = 0;
|
||||
for (size_t i = 0; i < elements_num; i++) {
|
||||
char *string_element = new char[string_max_length];
|
||||
size_t string_length = 0;
|
||||
std::fill_n(string_element, string_max_length, '\0');
|
||||
for (size_t j = 0; j < string_max_length; j++) {
|
||||
char char_element = data_ptr[i * string_max_length * single_char_offset + single_char_offset * j];
|
||||
if (static_cast<int>(char_element) == 0) {
|
||||
|
@ -217,6 +219,8 @@ GeTensorPtr ConvertStringTensor(const MeTensorPtr &tensor, const std::string &fo
|
|||
std::string string_to_add(string_element, string_length);
|
||||
(void)string_vector.emplace_back(string_to_add);
|
||||
}
|
||||
delete string_element;
|
||||
string_element = nullptr;
|
||||
tensor_ptr = make_shared<GeTensor>(*desc);
|
||||
(void)tensor_ptr->SetData(string_vector);
|
||||
} else {
|
||||
|
@ -232,6 +236,8 @@ GeTensorPtr ConvertStringTensor(const MeTensorPtr &tensor, const std::string &fo
|
|||
std::string string_to_add(string_element, string_length);
|
||||
tensor_ptr = make_shared<GeTensor>(*desc);
|
||||
(void)tensor_ptr->SetData(string_to_add);
|
||||
delete string_element;
|
||||
string_element = nullptr;
|
||||
}
|
||||
return tensor_ptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue