From 752d74928c2d9a9432bc2d10b0a19338ca733637 Mon Sep 17 00:00:00 2001 From: Prabhat Date: Fri, 21 Feb 2020 13:14:11 +0000 Subject: [PATCH] Improve the efficiency of SVMRegressor code (#3054) --- .../core/providers/cpu/ml/svmregressor.cc | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/onnxruntime/core/providers/cpu/ml/svmregressor.cc b/onnxruntime/core/providers/cpu/ml/svmregressor.cc index 7508698e0e..cfdd8a1298 100644 --- a/onnxruntime/core/providers/cpu/ml/svmregressor.cc +++ b/onnxruntime/core/providers/cpu/ml/svmregressor.cc @@ -45,31 +45,24 @@ Status SVMRegressor::Compute(OpKernelContext* ctx) const { Tensor* Y = ctx->Output(0, TensorShape({N, 1})); // this op outputs for one target only const auto* x_data = X->template Data(); + int64_t current_weight_0; + float sum; for (int64_t n = 0; n < N; n++) { //for each example - int64_t current_weight_0 = n * stride; - std::vector scores; - - float sum = 0.f; + current_weight_0 = n * stride; + sum = 0.f; if (mode_ == SVM_TYPE::SVM_SVC) { for (int64_t j = 0; j < vector_count_; j++) { - float val1 = kernel_dot(x_data, current_weight_0, support_vectors_, feature_count_ * j, feature_count_, get_kernel_type()); - float val2 = coefficients_[j]; - float val3 = val1 * val2; - sum += val3; + sum += kernel_dot(x_data, current_weight_0, support_vectors_, feature_count_ * j, + feature_count_, get_kernel_type()) * coefficients_[j]; } sum += rho_[0]; } else if (mode_ == SVM_TYPE::SVM_LINEAR) { //liblinear - sum = kernel_dot(x_data, current_weight_0, coefficients_, 0, feature_count_, get_kernel_type()); + sum = kernel_dot(x_data, current_weight_0, coefficients_, 0, + feature_count_, get_kernel_type()); sum += rho_[0]; } - if (one_class_ && sum > 0) { - Y->template MutableData()[n] = 1.f; - } else if (one_class_) { - Y->template MutableData()[n] = -1.f; - } else { - Y->template MutableData()[n] = sum; - } + Y->template MutableData()[n] = one_class_ ? (sum > 0 ? 1.f : -1.f) : sum; } return Status::OK();