question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

taking address of temporary array

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jdubz93commented, 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
0reactions
StrikerRUScommented, Sep 9, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

C++ error: "taking address of temporary array" - Stack Overflow
This is actually a C++ extension borrowed from "compound literal" in C. In C this is valid code because the temporary has automatic...
Read more >
How to solve 'taking address of temporary array' error ... - Quora
A “taking address of temporary array” error means that you were trying to take the address of a temporary object. That won't do...
Read more >
taking address of temporary array - Arduino Stack Exchange
That trick is to use a string, not an array. After all, a string is just an array, it's just handled slightly differently...
Read more >
normalize_ts.cpp:217:49: error: taking address of temporary ...
In file included from normalize_ts.cpp:37:0: normalize_ts.cpp:217:49: error: taking address of temporary array fprintf(stderr, ...
Read more >
Arduino: Error taking address of temporary array ... - YouTube
Arduino: Error taking address of temporary array when passing compound literal arrayHelpful? Please support me on Patreon: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found