Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coverity] fix coverity issues #2518

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions nntrainer/dataset/iteration_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ ScopedView<Sample> IterationQueue::requestEmptySlot() {
current_iterator++;
}

auto view =
ScopedView<Sample>(&(*current_iterator),
[current_being_filed = this->being_filled] {
current_being_filed->markSampleFilled();
},
[this, current_being_filled = this->being_filled] {
std::unique_lock lg(empty_mutex);
this->markEmpty(current_being_filled);
num_being_filled--;
notify_emptied_cv.notify_all();
});
auto view = ScopedView<Sample>(
&(*current_iterator),
[current_being_filed = this->being_filled] {
current_being_filed->markSampleFilled();
},
[this, current_being_filled = this->being_filled] {
std::unique_lock lg(empty_mutex);
this->markEmpty(current_being_filled);
num_being_filled--;
notify_emptied_cv.notify_all();
});
return view;
}

Expand Down Expand Up @@ -168,23 +168,22 @@ void IterationQueue::markEmpty(MarkableIteration *iteration) {
IterationQueue::MarkableIteration::MarkableIteration(
const std::vector<ml::train::TensorDim> &input_dims,
const std::vector<ml::train::TensorDim> &label_dims, IterationQueue *iq) :
num_observed(0),
iteration(input_dims, label_dims),
iq(iq) {}
num_observed(0), iteration(input_dims, label_dims), iq(iq) {}

IterationQueue::MarkableIteration::MarkableIteration(MarkableIteration &&rhs) :
num_observed(rhs.num_observed),
iteration(std::move(rhs.iteration)),
iq(rhs.iq) {}
iteration(std::move(rhs.iteration)), iq(rhs.iq) {
std::lock_guard notify_lock_guard(notify_mutex);
num_observed = rhs.num_observed;
}

void IterationQueue::MarkableIteration::reset() {
std::lock_guard notify_lock_guard(notify_mutex);
num_observed = 0;
iteration.setEndSample();
}

IterationQueue::MarkableIteration &IterationQueue::MarkableIteration::
operator=(MarkableIteration &&rhs) {
IterationQueue::MarkableIteration &
IterationQueue::MarkableIteration::operator=(MarkableIteration &&rhs) {
if (this == &rhs) {
return *this;
}
Expand Down
12 changes: 5 additions & 7 deletions test/unittest/models/models_test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ class IterationForGolden {
auto to_tensors = [](sharedConstTensors &sts) {
std::vector<Tensor> ts;
ts.reserve(sts.size());
std::transform(sts.begin(), sts.end(), std::back_inserter(ts),
[](const auto &ts) { return *ts; });
std::transform(
sts.begin(), sts.end(), std::back_inserter(ts),
[](const auto &ts) -> const auto & { return *ts; });
return ts;
};

Expand Down Expand Up @@ -303,17 +304,14 @@ void NodeWatcher::backward(int iteration, bool verify_deriv, bool verify_grad) {
}

GraphWatcher::GraphWatcher(const std::string &config, const bool opt) :
nn(new nntrainer::NeuralNetwork()),
expected_losses{},
optimize(opt) {
nn(new nntrainer::NeuralNetwork()), expected_losses{}, optimize(opt) {
nn->loadFromConfig(config);
initialize();
}

GraphWatcher::GraphWatcher(std::unique_ptr<nntrainer::NeuralNetwork> &&net,
const bool opt) :
nn(std::move(net)),
optimize(opt) {
nn(std::move(net)), optimize(opt) {
initialize();
}

Expand Down