Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taking address of temporary array #459

Open
jdubz93 opened this issue Sep 7, 2021 · 5 comments
Open

taking address of temporary array #459

jdubz93 opened this issue Sep 7, 2021 · 5 comments

Comments

@jdubz93
Copy link

jdubz93 commented Sep 7, 2021

XGBoost Classifier generated code for objective = 'binary:logistic', does not compile in c++

The last line that copies the prediction to what i am assuming to be a 0 or 1 sigmoid output value.

memcpy(output, (const double[]){(1.0) - (var1000), var1000}, 2 * sizeof(double));

gives this error:

error: taking address of temporary array
     memcpy(output, (double[]){(1.0) - (var1000), var1000}, 2 * sizeof(double));
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

it highlights this part:

{(1.0) - (var1000), var1000}

does anyone know how I can fix this error? And what if I just returned the raw values from var1000 could that work also?

Compiler:

g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

CXX_FLAGS

-std=c++11
@StrikerRUS
Copy link
Member

Hey @jdubz93 !

Thanks for raising this issue! Is it possible to share your model? If not, could you please reproduce the error with a model trained on a random data?

Also, I see the const qualifier, but m2cgen doesn't use it. Did you modify a generated code?

memcpy(output, (const double[]){ ...
         ---------^---------

@jdubz93
Copy link
Author

jdubz93 commented Sep 8, 2021

I have no problem sharing the model but you should know it’s 1 million lines of code. What method should I use to deliver it? Would google drive be best? Also I will try with random data just to rule out a dependency version issue.

@jdubz93
Copy link
Author

jdubz93 commented Sep 8, 2021

Also yes I added const to the last line because of a stack overflow suggestion. The error still was the same. The rest of the code is untouched.

Note the line I posted above the error and the error itself came from two different attempts. The error was from the first attempt untouched code then I added the const on a second attempt. Which did not resolve the issue either.

@jdubz93
Copy link
Author

jdubz93 commented Sep 8, 2021

import xgboost as xgb
​
xgb.__version__
'1.4.2'
m2c.__version__
'0.9.0'

When trying on random data I get:

RecursionError: maximum recursion depth exceeded while calling a Python object

When I use:

import sys

sys.setrecursionlimit(2147483647)

the error goes away

Model Used + Random Data:

from sklearn.datasets import load_breast_cancer
from xgboost import XGBClassifier

import m2cgen as m2c

X, y = load_breast_cancer(return_X_y=True)
xgb_model_random = XGBClassifier(
        use_label_encoder=False,
        objective = 'reg:logistic',
        colsample_bytree = 1,
        eta = 0.01,
        grow_policy = 'lossguide',
        max_depth = 8,
        min_child_weight = 0.15,
        n_estimators = 1000,
        subsample = 0.75)

xgb_model_random.fit(X, y, verbose=False)

And the model used with the random data has the same exact output / issue:

#include <math.h>
#include <string.h>
void score(double * input, double * output) {
    double var0;
# top of file ^
  ..........
# near end of file
    double var1000;
    var1000 = (1.0) / ((1.0) + (exp((0.0) - ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((var0) + (var1)) + (var2)) + (var3)) .... etc
    memcpy(output, (double[]){(1.0) - (var1000), var1000}, 2 * sizeof(double));

Here is my entire conda environment:
conda_environment.txt

Here is the random model (which is the same as the other model minus the data, but same issue.
random_model_test.txt

G++ Compiler used:

https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz

@StrikerRUS
Copy link
Member

OK, thanks for sharing the code with random data to reproduce the error! I'll try it on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants