Skip to content

Commit 6808589

Browse files
committed
Merge branch 'release_ci' of https://github.com/andife/onnx into release_ci
2 parents ffab226 + 56c8d60 commit 6808589

File tree

22 files changed

+75
-77
lines changed

22 files changed

+75
-77
lines changed

.clang-tidy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Checks: >-
1717
clang-analyzer-alpha.security.*,
1818
cppcoreguidelines-avoid-goto,
1919
cppcoreguidelines-interfaces-global-init,
20+
cppcoreguidelines-init-variables,
2021
cppcoreguidelines-no-malloc,
2122
cppcoreguidelines-prefer-member-initializer,
2223
cppcoreguidelines-pro-type-member-init,
@@ -33,6 +34,13 @@ Checks: >-
3334
google-default-arguments,
3435
google-global-names-in-headers,
3536
google-explicit-constructor,
37+
modernize-make-shared,
38+
modernize-make-unique,
39+
modernize-pass-by-value,
40+
modernize-use-equals-default,
41+
modernize-use-equals-delete,
42+
modernize-use-nullptr,
43+
modernize-use-override,
3644
modernize-use-emplace
3745
3846
CheckOptions:

CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,10 @@ if(ONNX_DISABLE_EXCEPTIONS)
100100
endif()
101101
endif()
102102

103-
# find_package Python has replaced PythonInterp and PythonLibs since cmake 3.12
104-
# Use the following command in the future; now this is only compatible with the latest pybind11
105-
# find_package(Python ${PY_VERSION} COMPONENTS Interpreter Development REQUIRED)
106-
find_package(PythonInterp ${PY_VERSION} REQUIRED)
107103
if(BUILD_ONNX_PYTHON)
108-
find_package(PythonLibs ${PY_VERSION})
104+
find_package(Python ${PY_VERSION} COMPONENTS Interpreter Development REQUIRED)
105+
else()
106+
find_package(Python ${PY_VERSION} COMPONENTS Interpreter REQUIRED)
109107
endif()
110108

111109
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
@@ -360,7 +358,7 @@ function(RELATIVE_PROTOBUF_GENERATE_CPP NAME SRCS HDRS ROOT_DIR DEPEND)
360358
endif()
361359

362360
add_custom_command(OUTPUT "${GENERATED_PROTO}"
363-
COMMAND "${PYTHON_EXECUTABLE}" "${GEN_PROTO_PY}"
361+
COMMAND Python::Interpreter "${GEN_PROTO_PY}"
364362
ARGS ${GEN_PROTO_ARGS}
365363
DEPENDS ${INFILE}
366364
COMMENT "Running gen_proto.py on ${INFILE}"
@@ -587,7 +585,7 @@ if(BUILD_ONNX_PYTHON)
587585
target_link_libraries(onnx_cpp2py_export
588586
PRIVATE "-Wl,--whole-archive" $<TARGET_FILE:onnx>
589587
"-Wl,--no-whole-archive")
590-
# Prevent "undefined symbol: _ZNSt10filesystem7__cxx114path14_M_split_cmptsEv"
588+
# Prevent "undefined symbol: _ZNSt10filesystem7__cxx114path14_M_split_cmptsEv"
591589
# (std::filesystem::__cxx11::path::_M_split_cmpts()) on gcc 8
592590
if (CMAKE_CXX_STANDARD EQUAL 17 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
593591
target_link_libraries(onnx_cpp2py_export PRIVATE "-lstdc++fs")

onnx/checker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
#include <unordered_set>
1111
#include <utility>
1212

13-
#include "onnx/defs/function.h"
1413
#include "onnx/defs/schema.h"
1514
#include "onnx/onnx-data_pb.h"
16-
#include "onnx/onnx-operators_pb.h"
17-
#include "onnx/onnx_pb.h"
1815
#include "onnx/string_utils.h"
1916

2017
namespace ONNX_NAMESPACE {
@@ -107,6 +104,7 @@ class CheckerContext final {
107104
class LexicalScopeContext final {
108105
public:
109106
LexicalScopeContext() = default;
107+
~LexicalScopeContext() = default;
110108

111109
// Construct an instance with the lexical scope from the parent graph to allow
112110
// lookup of names from that scope via this_or_ancestor_graph_has.
@@ -119,6 +117,8 @@ class LexicalScopeContext final {
119117
parent_context_ = &parent_context;
120118
return *this;
121119
}
120+
LexicalScopeContext(LexicalScopeContext&&) = delete;
121+
LexicalScopeContext& operator=(LexicalScopeContext&&) = delete;
122122

123123
void add(const std::string& name) {
124124
output_names.insert(name);

onnx/common/ir.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ struct ScalarAttributeValue final : public AttributeValue {
132132
ValueType& value() {
133133
return value_;
134134
}
135-
virtual Ptr clone() const override {
135+
Ptr clone() const override {
136136
return std::make_unique<ScalarAttributeValue>(name, value_);
137137
}
138-
virtual AttributeKind kind() const override {
138+
AttributeKind kind() const override {
139139
return Kind;
140140
}
141141

@@ -147,14 +147,14 @@ template <typename T, AttributeKind Kind>
147147
struct VectorAttributeValue final : public AttributeValue {
148148
using ConstructorType = const std::vector<T>&&;
149149
using ValueType = std::vector<T>;
150-
VectorAttributeValue(Symbol name, ConstructorType value_) : AttributeValue(name), value_(std::move(value_)) {}
150+
VectorAttributeValue(Symbol name, ValueType value_) : AttributeValue(name), value_(std::move(value_)) {}
151151
ValueType& value() {
152152
return value_;
153153
}
154-
virtual AttributeKind kind() const override {
154+
AttributeKind kind() const override {
155155
return Kind;
156156
}
157-
virtual std::unique_ptr<AttributeValue> clone() const override {
157+
std::unique_ptr<AttributeValue> clone() const override {
158158
return std::make_unique<VectorAttributeValue>(name, ValueType(value_));
159159
}
160160

@@ -181,7 +181,7 @@ using TypeProtosAttr = VectorAttributeValue<TypeProto, AttributeKind::tps>;
181181
// we return Derived* pointers because Nodes are normally held as pointers.
182182
template <typename Derived>
183183
struct Attributes {
184-
Attributes() {}
184+
Attributes() = default;
185185
void copyAttributes(const Attributes& rhs) {
186186
values_.clear();
187187
values_.reserve(rhs.values_.size());
@@ -375,7 +375,7 @@ struct Value final {
375375
Graph* owningGraph();
376376
const Graph* owningGraph() const;
377377
// TODO: make this more const correct
378-
const use_list uses() const;
378+
use_list uses() const;
379379

380380
// Replaces all uses of this node with 'newValue'.
381381
//
@@ -839,7 +839,7 @@ class OpSetID final {
839839
// Default Domain Constructor
840840
explicit OpSetID(const int64_t version) : domain_(""), version_(version) {}
841841

842-
explicit OpSetID(const std::string& domain, int64_t version) : domain_(domain), version_(version) {}
842+
explicit OpSetID(std::string domain, int64_t version) : domain_(std::move(domain)), version_(version) {}
843843

844844
// target must be in the form "<domain>&<version>"
845845
std::string toString() const {
@@ -1425,7 +1425,7 @@ inline const_graph_node_list_iterator Node::reverseIterator() const {
14251425
// nodes in subgraph are also included.
14261426
// This method is usually used to check whether it is
14271427
// safe to delete a Value.
1428-
inline const use_list Value::uses() const {
1428+
inline use_list Value::uses() const {
14291429
use_list all_uses = uses_in_current_graph_;
14301430
owningGraph()->forEachNode([this, &all_uses](const Node* node) {
14311431
if (node->owningGraph() == this->owningGraph()) {

onnx/common/ir_pb_converter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void createDummyValue(
227227
}
228228

229229
std::unique_ptr<Graph> graphProtoToGraph(const ONNX_NAMESPACE::GraphProto& gp, bool nested, const int ir_version) {
230-
std::unique_ptr<Graph> g(new Graph());
230+
auto g = std::make_unique<Graph>();
231231

232232
if (gp.has_name()) {
233233
g->setName(gp.name());

onnx/common/model_helpers.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Common::Status BuildNode(
1414
std::vector<std::string> const& inputs,
1515
std::vector<std::string> const& outputs,
1616
NodeProto* node) {
17-
if (node == NULL) {
17+
if (node == nullptr) {
1818
return Common::Status(Common::CHECKER, Common::INVALID_ARGUMENT, "node_proto should not be nullptr.");
1919
}
2020
node->set_name(name);

onnx/common/status.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88

99
#include <assert.h>
1010

11+
#include <memory>
12+
1113
#include "onnx/string_utils.h"
1214

1315
namespace ONNX_NAMESPACE {
1416
namespace Common {
1517

1618
Status::Status(StatusCategory category, int code, const std::string& msg) {
1719
assert(static_cast<int>(StatusCode::OK) != code);
18-
state_.reset(new State(category, code, msg));
20+
state_ = std::make_unique<State>(category, code, msg);
1921
}
2022

2123
Status::Status(StatusCategory category, int code) : Status(category, code, EmptyString()) {}
2224

2325
bool Status::IsOK() const noexcept {
24-
return (state_ == NULL);
26+
return (state_ == nullptr);
2527
}
2628

2729
StatusCategory Status::Category() const noexcept {

onnx/common/status.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Status {
4444
if (nullptr == other.state_) {
4545
state_.reset();
4646
} else if (state_ != other.state_) {
47-
state_.reset(new State(*other.state_));
47+
state_ = std::make_unique<State>(*other.state_);
4848
}
4949
}
5050
}

onnx/defs/data_type_utils.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ void DataTypeUtils::FromString(const std::string& type_str, TypeProto& type_prot
186186
s.LStrip(key_size);
187187
s.LStrip(",");
188188
StringRange v(s.Data(), s.Size());
189-
int32_t key_type;
190-
FromDataTypeString(key, key_type);
189+
auto key_type = FromDataTypeString(key);
191190
type_proto.mutable_map_type()->set_key_type(key_type);
192191
return FromString(std::string(v.Data(), v.Size()), *type_proto.mutable_map_type()->mutable_value_type());
193192
} else
@@ -211,18 +210,15 @@ void DataTypeUtils::FromString(const std::string& type_str, TypeProto& type_prot
211210
#endif
212211
if (s.LStrip("sparse_tensor")) {
213212
s.ParensWhitespaceStrip();
214-
int32_t e;
215-
FromDataTypeString(std::string(s.Data(), s.Size()), e);
213+
auto e = FromDataTypeString(std::string(s.Data(), s.Size()));
216214
type_proto.mutable_sparse_tensor_type()->set_elem_type(e);
217215
} else if (s.LStrip("tensor")) {
218216
s.ParensWhitespaceStrip();
219-
int32_t e;
220-
FromDataTypeString(std::string(s.Data(), s.Size()), e);
217+
auto e = FromDataTypeString(std::string(s.Data(), s.Size()));
221218
type_proto.mutable_tensor_type()->set_elem_type(e);
222219
} else {
223220
// Scalar
224-
int32_t e;
225-
FromDataTypeString(std::string(s.Data(), s.Size()), e);
221+
auto e = FromDataTypeString(std::string(s.Data(), s.Size()));
226222
TypeProto::Tensor* t = type_proto.mutable_tensor_type();
227223
t->set_elem_type(e);
228224
// Call mutable_shape() to initialize a shape with no dimension.
@@ -236,14 +232,14 @@ bool DataTypeUtils::IsValidDataTypeString(const std::string& type_str) {
236232
return (allowedSet.find(type_str) != allowedSet.end());
237233
}
238234

239-
void DataTypeUtils::FromDataTypeString(const std::string& type_str, int32_t& tensor_data_type) {
235+
int32_t DataTypeUtils::FromDataTypeString(const std::string& type_str) {
240236
if (!IsValidDataTypeString(type_str)) {
241237
ONNX_THROW_EX(std::invalid_argument(
242238
"DataTypeUtils::FromDataTypeString - Received invalid data type string '" + type_str + "'."));
243239
}
244240

245241
TypesWrapper& t = TypesWrapper::GetTypesWrapper();
246-
tensor_data_type = t.TypeStrToTensorDataType()[type_str];
242+
return t.TypeStrToTensorDataType()[type_str];
247243
}
248244

249245
StringRange::StringRange() : data_(""), size_(0), start_(data_), end_(data_) {}

onnx/defs/data_type_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DataTypeUtils final {
5252
private:
5353
static void FromString(const std::string& type_str, TypeProto& type_proto);
5454

55-
static void FromDataTypeString(const std::string& type_str, int32_t& tensor_data_type);
55+
static int32_t FromDataTypeString(const std::string& type_str);
5656

5757
static std::string ToString(const TypeProto& type_proto, const std::string& left = "", const std::string& right = "");
5858

0 commit comments

Comments
 (0)