Unverified Commit 3400e389 authored by Qiwei Ye's avatar Qiwei Ye Committed by GitHub
Browse files

remove unnecessary std::move & unused capture (#1596)

* remove unnecessary  std::move

* remove unused-lambda-capture

* remove unused-lambda-capture

* fix unused parameter

* minor fix

*  invalid capture of lambda function
parent 1b53fa07
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
while (read_cnt > 0) { while (read_cnt > 0) {
// start read thread // start read thread
std::thread read_worker = std::thread( std::thread read_worker = std::thread(
[&reader, &buffer_read, buffer_size, &last_read_cnt] { [&] {
last_read_cnt = reader->Read(buffer_read.data(), buffer_size); last_read_cnt = reader->Read(buffer_read.data(), buffer_size);
} }
); );
......
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
last_line_ = ""; last_line_ = "";
INDEX_T total_cnt = 0; INDEX_T total_cnt = 0;
PipelineReader::Read(filename_, skip_bytes_, PipelineReader::Read(filename_, skip_bytes_,
[this, &total_cnt, &process_fun] [&]
(const char* buffer_process, size_t read_cnt) { (const char* buffer_process, size_t read_cnt) {
size_t cnt = 0; size_t cnt = 0;
size_t i = 0; size_t i = 0;
...@@ -136,7 +136,7 @@ public: ...@@ -136,7 +136,7 @@ public:
*/ */
INDEX_T ReadAllLines() { INDEX_T ReadAllLines() {
return ReadAllAndProcess( return ReadAllAndProcess(
[this](INDEX_T, const char* buffer, size_t size) { [=](INDEX_T, const char* buffer, size_t size) {
lines_.emplace_back(buffer, size); lines_.emplace_back(buffer, size);
}); });
} }
...@@ -162,7 +162,7 @@ public: ...@@ -162,7 +162,7 @@ public:
INDEX_T SampleFromFile(Random& random, INDEX_T sample_cnt, std::vector<std::string>* out_sampled_data) { INDEX_T SampleFromFile(Random& random, INDEX_T sample_cnt, std::vector<std::string>* out_sampled_data) {
INDEX_T cur_sample_cnt = 0; INDEX_T cur_sample_cnt = 0;
return ReadAllAndProcess( return ReadAllAndProcess(
[this, &random, &cur_sample_cnt, &sample_cnt, &out_sampled_data] [&]
(INDEX_T line_idx, const char* buffer, size_t size) { (INDEX_T line_idx, const char* buffer, size_t size) {
if (cur_sample_cnt < sample_cnt) { if (cur_sample_cnt < sample_cnt) {
out_sampled_data->emplace_back(buffer, size); out_sampled_data->emplace_back(buffer, size);
...@@ -185,7 +185,7 @@ public: ...@@ -185,7 +185,7 @@ public:
INDEX_T ReadAndFilterLines(const std::function<bool(INDEX_T)>& filter_fun, std::vector<INDEX_T>* out_used_data_indices) { INDEX_T ReadAndFilterLines(const std::function<bool(INDEX_T)>& filter_fun, std::vector<INDEX_T>* out_used_data_indices) {
out_used_data_indices->clear(); out_used_data_indices->clear();
INDEX_T total_cnt = ReadAllAndProcess( INDEX_T total_cnt = ReadAllAndProcess(
[this, &out_used_data_indices, &filter_fun] [&]
(INDEX_T line_idx , const char* buffer, size_t size) { (INDEX_T line_idx , const char* buffer, size_t size) {
bool is_used = filter_fun(line_idx); bool is_used = filter_fun(line_idx);
if (is_used) { out_used_data_indices->push_back(line_idx); } if (is_used) { out_used_data_indices->push_back(line_idx); }
...@@ -199,7 +199,7 @@ public: ...@@ -199,7 +199,7 @@ public:
INDEX_T cur_sample_cnt = 0; INDEX_T cur_sample_cnt = 0;
out_used_data_indices->clear(); out_used_data_indices->clear();
INDEX_T total_cnt = ReadAllAndProcess( INDEX_T total_cnt = ReadAllAndProcess(
[this, &out_used_data_indices, &filter_fun, &random, &cur_sample_cnt, &sample_cnt, &out_sampled_data] [&]
(INDEX_T line_idx, const char* buffer, size_t size) { (INDEX_T line_idx, const char* buffer, size_t size) {
bool is_used = filter_fun(line_idx); bool is_used = filter_fun(line_idx);
if (is_used) { out_used_data_indices->push_back(line_idx); } if (is_used) { out_used_data_indices->push_back(line_idx); }
...@@ -221,7 +221,7 @@ public: ...@@ -221,7 +221,7 @@ public:
INDEX_T CountLine() { INDEX_T CountLine() {
return ReadAllAndProcess( return ReadAllAndProcess(
[this](INDEX_T, const char*, size_t) { [=](INDEX_T, const char*, size_t) {
}); });
} }
...@@ -230,7 +230,7 @@ public: ...@@ -230,7 +230,7 @@ public:
INDEX_T total_cnt = 0; INDEX_T total_cnt = 0;
INDEX_T used_cnt = 0; INDEX_T used_cnt = 0;
PipelineReader::Read(filename_, skip_bytes_, PipelineReader::Read(filename_, skip_bytes_,
[this, &total_cnt, &process_fun,&used_cnt, &filter_fun] [&]
(const char* buffer_process, size_t read_cnt) { (const char* buffer_process, size_t read_cnt) {
size_t cnt = 0; size_t cnt = 0;
size_t i = 0; size_t i = 0;
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
const int kFeatureThreshold = 100000; const int kFeatureThreshold = 100000;
const size_t KSparseThreshold = static_cast<size_t>(0.01 * num_feature_); const size_t KSparseThreshold = static_cast<size_t>(0.01 * num_feature_);
if (predict_leaf_index) { if (predict_leaf_index) {
predict_fun_ = [this, kFeatureThreshold, KSparseThreshold](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) { if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) {
auto buf = CopyToPredictMap(features); auto buf = CopyToPredictMap(features);
...@@ -76,16 +76,16 @@ public: ...@@ -76,16 +76,16 @@ public:
} }
}; };
} else if (predict_contrib) { } else if (predict_contrib) {
predict_fun_ = [this](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
CopyToPredictBuffer(predict_buf_[tid].data(), features); CopyToPredictBuffer(predict_buf_[tid].data(), features);
// get result for leaf index // get result for leaf index
boosting_->PredictContrib(predict_buf_[tid].data(), output, &early_stop_); boosting_->PredictContrib(predict_buf_[tid].data(), output, &early_stop_);
ClearPredictBuffer(predict_buf_[tid].data(), predict_buf_[tid].size(), features); ClearPredictBuffer(predict_buf_[tid].data(), predict_buf_[tid].size(), features);
}; };
} else { } else {
if (is_raw_score) { if (is_raw_score) {
predict_fun_ = [this, kFeatureThreshold, KSparseThreshold](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) { if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) {
auto buf = CopyToPredictMap(features); auto buf = CopyToPredictMap(features);
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
} }
}; };
} else { } else {
predict_fun_ = [this, kFeatureThreshold, KSparseThreshold](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) { if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) {
auto buf = CopyToPredictMap(features); auto buf = CopyToPredictMap(features);
...@@ -163,7 +163,7 @@ public: ...@@ -163,7 +163,7 @@ public:
// function for parse data // function for parse data
std::function<void(const char*, std::vector<std::pair<int, double>>*)> parser_fun; std::function<void(const char*, std::vector<std::pair<int, double>>*)> parser_fun;
double tmp_label; double tmp_label;
parser_fun = [this, &parser, &tmp_label, &need_adjust, &feature_names_map_] parser_fun = [&]
(const char* buffer, std::vector<std::pair<int, double>>* feature) { (const char* buffer, std::vector<std::pair<int, double>>* feature) {
parser->ParseOneLine(buffer, feature, &tmp_label); parser->ParseOneLine(buffer, feature, &tmp_label);
if (need_adjust) { if (need_adjust) {
...@@ -181,9 +181,8 @@ public: ...@@ -181,9 +181,8 @@ public:
} }
}; };
std::function<void(data_size_t, const std::vector<std::string>&)> process_fun = std::function<void(data_size_t, const std::vector<std::string>&)> process_fun = [&]
[this, &parser_fun, &writer] (data_size_t, const std::vector<std::string>& lines) {
(data_size_t, const std::vector<std::string>& lines) {
std::vector<std::pair<int, double>> oneline_features; std::vector<std::pair<int, double>> oneline_features;
std::vector<std::string> result_to_write(lines.size()); std::vector<std::string> result_to_write(lines.size());
OMP_INIT_EX(); OMP_INIT_EX();
...@@ -241,7 +240,7 @@ private: ...@@ -241,7 +240,7 @@ private:
buf[features[i].first] = features[i].second; buf[features[i].first] = features[i].second;
} }
} }
return std::move(buf); return buf;
} }
/*! \brief Boosting model */ /*! \brief Boosting model */
......
...@@ -1298,7 +1298,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_ ...@@ -1298,7 +1298,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_
if (data_type == C_API_DTYPE_FLOAT32) { if (data_type == C_API_DTYPE_FLOAT32) {
const float* data_ptr = reinterpret_cast<const float*>(data); const float* data_ptr = reinterpret_cast<const float*>(data);
if (is_row_major) { if (is_row_major) {
return [data_ptr, num_col, num_row] (int row_idx) { return [=] (int row_idx) {
std::vector<double> ret(num_col); std::vector<double> ret(num_col);
auto tmp_ptr = data_ptr + static_cast<size_t>(num_col) * row_idx; auto tmp_ptr = data_ptr + static_cast<size_t>(num_col) * row_idx;
for (int i = 0; i < num_col; ++i) { for (int i = 0; i < num_col; ++i) {
...@@ -1307,7 +1307,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_ ...@@ -1307,7 +1307,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_
return ret; return ret;
}; };
} else { } else {
return [data_ptr, num_col, num_row] (int row_idx) { return [=] (int row_idx) {
std::vector<double> ret(num_col); std::vector<double> ret(num_col);
for (int i = 0; i < num_col; ++i) { for (int i = 0; i < num_col; ++i) {
ret[i] = static_cast<double>(*(data_ptr + static_cast<size_t>(num_row) * i + row_idx)); ret[i] = static_cast<double>(*(data_ptr + static_cast<size_t>(num_row) * i + row_idx));
...@@ -1318,7 +1318,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_ ...@@ -1318,7 +1318,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_
} else if (data_type == C_API_DTYPE_FLOAT64) { } else if (data_type == C_API_DTYPE_FLOAT64) {
const double* data_ptr = reinterpret_cast<const double*>(data); const double* data_ptr = reinterpret_cast<const double*>(data);
if (is_row_major) { if (is_row_major) {
return [data_ptr, num_col, num_row] (int row_idx) { return [=] (int row_idx) {
std::vector<double> ret(num_col); std::vector<double> ret(num_col);
auto tmp_ptr = data_ptr + static_cast<size_t>(num_col) * row_idx; auto tmp_ptr = data_ptr + static_cast<size_t>(num_col) * row_idx;
for (int i = 0; i < num_col; ++i) { for (int i = 0; i < num_col; ++i) {
...@@ -1327,7 +1327,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_ ...@@ -1327,7 +1327,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_
return ret; return ret;
}; };
} else { } else {
return [data_ptr, num_col, num_row] (int row_idx) { return [=] (int row_idx) {
std::vector<double> ret(num_col); std::vector<double> ret(num_col);
for (int i = 0; i < num_col; ++i) { for (int i = 0; i < num_col; ++i) {
ret[i] = static_cast<double>(*(data_ptr + static_cast<size_t>(num_row) * i + row_idx)); ret[i] = static_cast<double>(*(data_ptr + static_cast<size_t>(num_row) * i + row_idx));
...@@ -1358,12 +1358,12 @@ RowPairFunctionFromDenseMatric(const void* data, int num_row, int num_col, int d ...@@ -1358,12 +1358,12 @@ RowPairFunctionFromDenseMatric(const void* data, int num_row, int num_col, int d
} }
std::function<std::vector<std::pair<int, double>>(int idx)> std::function<std::vector<std::pair<int, double>>(int idx)>
RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, const void* data, int data_type, int64_t nindptr, int64_t nelem) { RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, const void* data, int data_type, int64_t , int64_t ) {
if (data_type == C_API_DTYPE_FLOAT32) { if (data_type == C_API_DTYPE_FLOAT32) {
const float* data_ptr = reinterpret_cast<const float*>(data); const float* data_ptr = reinterpret_cast<const float*>(data);
if (indptr_type == C_API_DTYPE_INT32) { if (indptr_type == C_API_DTYPE_INT32) {
const int32_t* ptr_indptr = reinterpret_cast<const int32_t*>(indptr); const int32_t* ptr_indptr = reinterpret_cast<const int32_t*>(indptr);
return [ptr_indptr, indices, data_ptr, nindptr, nelem] (int idx) { return [=] (int idx) {
std::vector<std::pair<int, double>> ret; std::vector<std::pair<int, double>> ret;
int64_t start = ptr_indptr[idx]; int64_t start = ptr_indptr[idx];
int64_t end = ptr_indptr[idx + 1]; int64_t end = ptr_indptr[idx + 1];
...@@ -1374,7 +1374,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, ...@@ -1374,7 +1374,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
}; };
} else if (indptr_type == C_API_DTYPE_INT64) { } else if (indptr_type == C_API_DTYPE_INT64) {
const int64_t* ptr_indptr = reinterpret_cast<const int64_t*>(indptr); const int64_t* ptr_indptr = reinterpret_cast<const int64_t*>(indptr);
return [ptr_indptr, indices, data_ptr, nindptr, nelem] (int idx) { return [=] (int idx) {
std::vector<std::pair<int, double>> ret; std::vector<std::pair<int, double>> ret;
int64_t start = ptr_indptr[idx]; int64_t start = ptr_indptr[idx];
int64_t end = ptr_indptr[idx + 1]; int64_t end = ptr_indptr[idx + 1];
...@@ -1388,7 +1388,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, ...@@ -1388,7 +1388,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
const double* data_ptr = reinterpret_cast<const double*>(data); const double* data_ptr = reinterpret_cast<const double*>(data);
if (indptr_type == C_API_DTYPE_INT32) { if (indptr_type == C_API_DTYPE_INT32) {
const int32_t* ptr_indptr = reinterpret_cast<const int32_t*>(indptr); const int32_t* ptr_indptr = reinterpret_cast<const int32_t*>(indptr);
return [ptr_indptr, indices, data_ptr, nindptr, nelem] (int idx) { return [=] (int idx) {
std::vector<std::pair<int, double>> ret; std::vector<std::pair<int, double>> ret;
int64_t start = ptr_indptr[idx]; int64_t start = ptr_indptr[idx];
int64_t end = ptr_indptr[idx + 1]; int64_t end = ptr_indptr[idx + 1];
...@@ -1399,7 +1399,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, ...@@ -1399,7 +1399,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
}; };
} else if (indptr_type == C_API_DTYPE_INT64) { } else if (indptr_type == C_API_DTYPE_INT64) {
const int64_t* ptr_indptr = reinterpret_cast<const int64_t*>(indptr); const int64_t* ptr_indptr = reinterpret_cast<const int64_t*>(indptr);
return [ptr_indptr, indices, data_ptr, nindptr, nelem] (int idx) { return [=] (int idx) {
std::vector<std::pair<int, double>> ret; std::vector<std::pair<int, double>> ret;
int64_t start = ptr_indptr[idx]; int64_t start = ptr_indptr[idx];
int64_t end = ptr_indptr[idx + 1]; int64_t end = ptr_indptr[idx + 1];
...@@ -1414,7 +1414,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, ...@@ -1414,7 +1414,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
} }
std::function<std::pair<int, double>(int idx)> std::function<std::pair<int, double>(int idx)>
IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* indices, const void* data, int data_type, int64_t ncol_ptr, int64_t nelem, int col_idx) { IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* indices, const void* data, int data_type, int64_t ncol_ptr, int64_t , int col_idx) {
CHECK(col_idx < ncol_ptr && col_idx >= 0); CHECK(col_idx < ncol_ptr && col_idx >= 0);
if (data_type == C_API_DTYPE_FLOAT32) { if (data_type == C_API_DTYPE_FLOAT32) {
const float* data_ptr = reinterpret_cast<const float*>(data); const float* data_ptr = reinterpret_cast<const float*>(data);
...@@ -1422,7 +1422,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind ...@@ -1422,7 +1422,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind
const int32_t* ptr_col_ptr = reinterpret_cast<const int32_t*>(col_ptr); const int32_t* ptr_col_ptr = reinterpret_cast<const int32_t*>(col_ptr);
int64_t start = ptr_col_ptr[col_idx]; int64_t start = ptr_col_ptr[col_idx];
int64_t end = ptr_col_ptr[col_idx + 1]; int64_t end = ptr_col_ptr[col_idx + 1];
return [ptr_col_ptr, indices, data_ptr, ncol_ptr, nelem, start, end] (int bias) { return [=] (int bias) {
int64_t i = static_cast<int64_t>(start + bias); int64_t i = static_cast<int64_t>(start + bias);
if (i >= end) { if (i >= end) {
return std::make_pair(-1, 0.0); return std::make_pair(-1, 0.0);
...@@ -1435,7 +1435,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind ...@@ -1435,7 +1435,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind
const int64_t* ptr_col_ptr = reinterpret_cast<const int64_t*>(col_ptr); const int64_t* ptr_col_ptr = reinterpret_cast<const int64_t*>(col_ptr);
int64_t start = ptr_col_ptr[col_idx]; int64_t start = ptr_col_ptr[col_idx];
int64_t end = ptr_col_ptr[col_idx + 1]; int64_t end = ptr_col_ptr[col_idx + 1];
return [ptr_col_ptr, indices, data_ptr, ncol_ptr, nelem, start, end] (int bias) { return [=] (int bias) {
int64_t i = static_cast<int64_t>(start + bias); int64_t i = static_cast<int64_t>(start + bias);
if (i >= end) { if (i >= end) {
return std::make_pair(-1, 0.0); return std::make_pair(-1, 0.0);
...@@ -1451,7 +1451,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind ...@@ -1451,7 +1451,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind
const int32_t* ptr_col_ptr = reinterpret_cast<const int32_t*>(col_ptr); const int32_t* ptr_col_ptr = reinterpret_cast<const int32_t*>(col_ptr);
int64_t start = ptr_col_ptr[col_idx]; int64_t start = ptr_col_ptr[col_idx];
int64_t end = ptr_col_ptr[col_idx + 1]; int64_t end = ptr_col_ptr[col_idx + 1];
return [ptr_col_ptr, indices, data_ptr, ncol_ptr, nelem, start, end] (int bias) { return [=] (int bias) {
int64_t i = static_cast<int64_t>(start + bias); int64_t i = static_cast<int64_t>(start + bias);
if (i >= end) { if (i >= end) {
return std::make_pair(-1, 0.0); return std::make_pair(-1, 0.0);
...@@ -1464,7 +1464,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind ...@@ -1464,7 +1464,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind
const int64_t* ptr_col_ptr = reinterpret_cast<const int64_t*>(col_ptr); const int64_t* ptr_col_ptr = reinterpret_cast<const int64_t*>(col_ptr);
int64_t start = ptr_col_ptr[col_idx]; int64_t start = ptr_col_ptr[col_idx];
int64_t end = ptr_col_ptr[col_idx + 1]; int64_t end = ptr_col_ptr[col_idx + 1];
return [ptr_col_ptr, indices, data_ptr, ncol_ptr, nelem, start, end] (int bias) { return [=] (int bias) {
int64_t i = static_cast<int64_t>(start + bias); int64_t i = static_cast<int64_t>(start + bias);
if (i >= end) { if (i >= end) {
return std::make_pair(-1, 0.0); return std::make_pair(-1, 0.0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment