Commit 6c8abad7 authored by Cédric Traizet's avatar Cédric Traizet

ENH: template specialization, use GetFieldAsInteger instead of double is the classification case

parent 94069744
Pipeline #1279 passed with stages
in 31 minutes and 20 seconds
......@@ -186,6 +186,12 @@ protected:
void DoUpdateParameters() override;
void DoExecute() override;
private:
/**
* Get the field of the input feature corresponding to the input field
*/
inline TOutputValue GetFeatureField(const ogr::Feature & feature, int field);
};
}
......
......@@ -245,6 +245,23 @@ TrainVectorBase<TInputValue, TOutputValue>
return measurement;
}
// Template specialization for the integer case (i.e.classification), to avoid a cast from double to integer
template <>
inline int
TrainVectorBase<float, int>
::GetFeatureField(const ogr::Feature & feature, int fieldIndex)
{
return(feature.ogr().GetFieldAsInteger( fieldIndex ));
}
template <class TInputValue, class TOutputValue>
inline TOutputValue
TrainVectorBase<TInputValue, TOutputValue>
::GetFeatureField(const ogr::Feature & feature, int fieldIndex)
{
return(feature.ogr().GetFieldAsDouble( fieldIndex ));
}
template <class TInputValue, class TOutputValue>
typename TrainVectorBase<TInputValue, TOutputValue>::SamplesWithLabel
TrainVectorBase<TInputValue, TOutputValue>
......@@ -306,7 +323,7 @@ TrainVectorBase<TInputValue, TOutputValue>
input->PushBack( mv );
if(cFieldIndex>=0 && ogr::Field(feature,cFieldIndex).HasBeenSet())
target->PushBack( feature.ogr().GetFieldAsDouble( cFieldIndex ) );
target->PushBack(GetFeatureField(feature,cFieldIndex));
else
target->PushBack( 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