From 988d9af0a76426cb30b4c19554ef5e6b1dfafa8e Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@cnes.fr> Date: Mon, 29 Aug 2016 09:49:37 +0200 Subject: [PATCH] STY: Try to avoid construction in 2 steps --- .../otbSharkRandomForestsMachineLearningModel.txx | 2 +- .../Supervised/include/otbMachineLearningModel.txx | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Modules/Learning/SharkLearning/include/otbSharkRandomForestsMachineLearningModel.txx b/Modules/Learning/SharkLearning/include/otbSharkRandomForestsMachineLearningModel.txx index 24f604baf0..5d92cea948 100644 --- a/Modules/Learning/SharkLearning/include/otbSharkRandomForestsMachineLearningModel.txx +++ b/Modules/Learning/SharkLearning/include/otbSharkRandomForestsMachineLearningModel.txx @@ -112,7 +112,7 @@ typename SharkRandomForestsMachineLearningModel<TInputValue,TOutputValue> SharkRandomForestsMachineLearningModel<TInputValue,TOutputValue> ::DoPredict(const InputSampleType & value, ConfidenceValueType *quality) const { - shark::RealVector samples; + shark::RealVector samples(value.Size()); for(size_t i = 0; i < value.Size();i++) { samples.push_back(value[i]); diff --git a/Modules/Learning/Supervised/include/otbMachineLearningModel.txx b/Modules/Learning/Supervised/include/otbMachineLearningModel.txx index 4e790c23a9..d051481ac9 100644 --- a/Modules/Learning/Supervised/include/otbMachineLearningModel.txx +++ b/Modules/Learning/Supervised/include/otbMachineLearningModel.txx @@ -154,19 +154,18 @@ MachineLearningModel<TInputValue,TOutputValue,TConfidenceValue> for(unsigned int id = startIndex;id<startIndex+size;++id) { - TargetSampleType target; - ConfidenceValueType confidence; - if(quality!=ITK_NULLPTR) { - target = this->DoPredict(input->GetMeasurementVector(id),&confidence); + ConfidenceValueType confidence = 0; + const TargetSampleType target = this->DoPredict(input->GetMeasurementVector(id),&confidence); quality->SetMeasurementVector(id,confidence); + targets->SetMeasurementVector(id,target); } else { - target = this->DoPredict(input->GetMeasurementVector(id)); + const TargetSampleType target = this->DoPredict(input->GetMeasurementVector(id)); + targets->SetMeasurementVector(id,target); } - targets->SetMeasurementVector(id,target); } } -- GitLab