From fde99cce7735a7362f458a8592e4662965734482 Mon Sep 17 00:00:00 2001 From: Rob Hess Date: Thu, 19 Jun 2014 15:12:56 -0700 Subject: [PATCH] Use vectors instead of arrays. --- src/caffe/layers/accuracy_layer.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/caffe/layers/accuracy_layer.cpp b/src/caffe/layers/accuracy_layer.cpp index a284f6b..4099655 100644 --- a/src/caffe/layers/accuracy_layer.cpp +++ b/src/caffe/layers/accuracy_layer.cpp @@ -37,12 +37,12 @@ Dtype AccuracyLayer::Forward_cpu(const vector*>& bottom, const Dtype* bottom_label = bottom[1]->cpu_data(); int num = bottom[0]->num(); int dim = bottom[0]->count() / bottom[0]->num(); - Dtype* maxval = new Dtype[top_k_+1]; - int* max_id = new int[top_k_+1]; + vector maxval(top_k_+1); + vector max_id(top_k_+1); for (int i = 0; i < num; ++i) { // Top-k accuracy - std::fill_n(maxval, top_k_, -FLT_MAX); - std::fill_n(max_id, top_k_, 0); + std::fill_n(maxval.begin(), top_k_, -FLT_MAX); + std::fill_n(max_id.begin(), top_k_, 0); for (int j = 0, k; j < dim; ++j) { // insert into (reverse-)sorted top-k array Dtype val = bottom_data[i * dim + j]; @@ -60,8 +60,6 @@ Dtype AccuracyLayer::Forward_cpu(const vector*>& bottom, break; } } - delete[] maxval; - delete[] max_id; // LOG(INFO) << "Accuracy: " << accuracy; (*top)[0]->mutable_cpu_data()[0] = accuracy / num; -- 2.7.4