Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Fix C++ issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Feb 14, 2020
1 parent 8ade30b commit 2e43a31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
36 changes: 18 additions & 18 deletions mlprodict/onnxrt/ops_cpu/op_svm_classifier_.cpp
Expand Up @@ -101,22 +101,22 @@ void RuntimeSVMClassifier<NTYPE>::Initialize() {
this->feature_count_ = 0;
class_count_ = 0;
for (int64_t i = 0; i < static_cast<int64_t>(vectors_per_class_.size()); ++i) {
starting_vector_.push_back(vector_count_);
starting_vector_.push_back(this->vector_count_);
this->vector_count_ += vectors_per_class_[i];
}

class_count_ = classlabels_ints_.size() > 0 ? classlabels_ints_.size() : class_count_ = 1;
if (this->vector_count_ > 0) {
this->feature_count_ = support_vectors_.size() / vector_count_; //length of each support vector
mode_ = SVM_TYPE::SVM_SVC;
this->feature_count_ = this->support_vectors_.size() / this->vector_count_; //length of each support vector
this->mode_ = SVM_TYPE::SVM_SVC;
} else {
this->feature_count_ = coefficients_.size() / class_count_; //liblinear mode
this->feature_count_ = this->coefficients_.size() / class_count_; //liblinear mode
this->mode_ = SVM_TYPE::SVM_LINEAR;
this->kernel_type_ = KERNEL::LINEAR;
}
weights_are_all_positive_ = true;
for (int64_t i = 0; i < static_cast<int64_t>(coefficients_.size()); i++) {
if (coefficients_[i] >= 0)
for (int64_t i = 0; i < static_cast<int64_t>(this->coefficients_.size()); i++) {
if (this->coefficients_[i] >= 0)
continue;
weights_are_all_positive_ = false;
break;
Expand All @@ -126,13 +126,13 @@ void RuntimeSVMClassifier<NTYPE>::Initialize() {

template<typename NTYPE>
int _set_score_svm(int64_t* output_data, NTYPE max_weight, const int64_t maxclass,
const int64_t n, POST_EVAL_TRANSFORM post_transform_,
const int64_t n, POST_EVAL_TRANSFORM post_transform,
const std::vector<NTYPE>& proba_, bool weights_are_all_positive_,
const std::vector<int64_t>& classlabels, int64_t posclass,
int64_t negclass) {
int write_additional_scores = -1;
if (classlabels.size() == 2) {
write_additional_scores = post_transform_ == POST_EVAL_TRANSFORM::NONE ? 2 : 0;
write_additional_scores = post_transform == POST_EVAL_TRANSFORM::NONE ? 2 : 0;
if (proba_.size() == 0) {
if (weights_are_all_positive_ && max_weight >= 0.5)
output_data[n] = classlabels[1];
Expand Down Expand Up @@ -168,7 +168,7 @@ py::tuple RuntimeSVMClassifier<NTYPE>::compute(py::array_t<NTYPE> X) const {
int64_t N = x_dims.size() == 1 ? 1 : x_dims[0];

int64_t nb_columns = class_count_;
if (proba_.size() == 0 && vector_count_ > 0) {
if (proba_.size() == 0 && this->vector_count_ > 0) {
nb_columns = class_count_ > 2
? class_count_ * (class_count_ - 1) / 2
: 2;
Expand Down Expand Up @@ -264,12 +264,12 @@ void RuntimeSVMClassifier<NTYPE>::compute_gil_free_loop(
std::vector<NTYPE> kernels;
std::vector<int64_t> votes;

if (vector_count_ == 0 && mode_ == SVM_TYPE::SVM_LINEAR) {
if (vector_count_ == 0 && this->mode_ == SVM_TYPE::SVM_LINEAR) {
scores.resize(class_count_);
for (int64_t j = 0; j < class_count_; j++) { //for each class
scores[j] = rho_[0] + this->kernel_dot_gil_free(x_data, current_weight_0, coefficients_,
scores[j] = this->rho_[0] + this->kernel_dot_gil_free(x_data, current_weight_0, this->coefficients_,
this->feature_count_ * j,
this->feature_count_, kernel_type_);
this->feature_count_, this->kernel_type_);
}
}
else {
Expand All @@ -278,7 +278,7 @@ void RuntimeSVMClassifier<NTYPE>::compute_gil_free_loop(
int evals = 0;

kernels.resize(vector_count_);
for (int64_t j = 0; j < vector_count_; j++) {
for (int64_t j = 0; j < this->vector_count_; j++) {
kernels[j] = this->kernel_dot_gil_free(x_data, current_weight_0, this->support_vectors_,
this->feature_count_ * j,
this->feature_count_, this->kernel_type_);
Expand All @@ -304,15 +304,15 @@ void RuntimeSVMClassifier<NTYPE>::compute_gil_free_loop(
for (int64_t m = 0; m < class_j_support_count; ++m, ++val1, ++val2)
sum += *val1 * *val2;

sum += rho_[evals];
sum += this->rho_[evals];
scores.push_back((NTYPE)sum);
++(votes[sum > 0 ? i : j]);
++evals; //index into rho
}
}
}

if (proba_.size() > 0 && mode_ == SVM_TYPE::SVM_SVC) {
if (proba_.size() > 0 && this->mode_ == SVM_TYPE::SVM_SVC) {
//compute probabilities from the scores
int64_t num = class_count_ * class_count_;
std::vector<NTYPE> probsp2(num, 0.f);
Expand Down Expand Up @@ -350,7 +350,7 @@ void RuntimeSVMClassifier<NTYPE>::compute_gil_free_loop(
// write top class
// onnx specs expects one column per class.
int write_additional_scores = -1;
if (rho_.size() == 1) {
if (this->rho_.size() == 1) {
write_additional_scores = _set_score_svm(
y_data, max_weight, maxclass, n, post_transform_, proba_,
weights_are_all_positive_, classlabels_ints_, 1, 0);
Expand All @@ -362,7 +362,7 @@ void RuntimeSVMClassifier<NTYPE>::compute_gil_free_loop(
y_data[n] = maxclass;
}

write_scores(scores, post_transform_, z_data + zindex, write_additional_scores);
write_scores(scores, this->post_transform_, z_data + zindex, write_additional_scores);
}


Expand All @@ -377,7 +377,7 @@ void RuntimeSVMClassifier<NTYPE>::compute_gil_free(
int64_t* y_data = (int64_t*)Y_.data(0);
NTYPE* z_data = (NTYPE*)Z_.data(0);

if (N <= omp_N_) {
if (N <= this->omp_N_) {
for (int64_t n = 0; n < N; ++n) {
compute_gil_free_loop(n, x_data, y_data, z_data, stride);
}
Expand Down
12 changes: 6 additions & 6 deletions mlprodict/onnxrt/ops_cpu/op_svm_regressor_.cpp
Expand Up @@ -76,7 +76,7 @@ void RuntimeSVMRegressor<NTYPE>::Initialize() {
this->mode_ = SVM_TYPE::SVM_SVC;
}
else {
this->feature_count_ = coefficients_.size();
this->feature_count_ = this->coefficients_.size();
this->mode_ = SVM_TYPE::SVM_LINEAR;
this->kernel_type_ = KERNEL::LINEAR;
}
Expand Down Expand Up @@ -107,17 +107,17 @@ py::array_t<NTYPE> RuntimeSVMRegressor<NTYPE>::compute(py::array_t<NTYPE> X) con
#define COMPUTE_LOOP() \
current_weight_0 = n * stride; \
sum = (NTYPE)0; \
if (mode_ == SVM_TYPE::SVM_SVC) { \
if (this->mode_ == SVM_TYPE::SVM_SVC) { \
for (j = 0; j < this->vector_count_; ++j) { \
sum += this->coefficients_[j] * this->kernel_dot_gil_free( \
x_data, current_weight_0, this->support_vectors_, \
this->feature_count_ * j, this->feature_count_, this->kernel_type_); \
} \
sum += rho_[0]; \
} else if (mode_ == SVM_TYPE::SVM_LINEAR) { \
sum += this->rho_[0]; \
} else if (this->mode_ == SVM_TYPE::SVM_LINEAR) { \
sum = this->kernel_dot_gil_free(x_data, current_weight_0, this->coefficients_, 0, \
this->feature_count_, this->kernel_type_); \
sum += rho_[0]; \
sum += this->rho_[0]; \
} \
z_data[n] = one_class_ ? (sum > 0 ? 1 : -1) : sum;

Expand All @@ -133,7 +133,7 @@ void RuntimeSVMRegressor<NTYPE>::compute_gil_free(
int64_t current_weight_0, j;
NTYPE sum;

if (N <= omp_N_) {
if (N <= this->omp_N_) {
for (int64_t n = 0; n < N; ++n) {
COMPUTE_LOOP()
}
Expand Down

0 comments on commit 2e43a31

Please sign in to comment.