qzhu2017 / CSP_BO

Crystal Structure Prediction with Bayesian Optimization
0 stars 1 forks source link

Kee.cpp #28

Closed yanxon closed 3 years ago

yanxon commented 3 years ago

Hi @macstein

Can you please help me with C++?

I'm having trouble in counting the size of an array. This supposed to return n=5 not n=2: https://github.com/qzhu2017/CSP_BO/blob/f5c0e7ead521a492d640731c50830bfa84e89258/Cpp_code/kee.cpp#L69

macstein commented 3 years ago

Hi @yanxon I think there should be some confusing on pointer of array, which python doesn't have.

int main(){
    double itest[2];
    cout << sizeof(double) << " " << sizeof(itest) << " " << sizeof(itest[0]) << endl;
    double *ptest=new double[2];
    cout << sizeof(double) << " " << sizeof(ptest) << " " << sizeof(ptest[0]) << endl;
    return 0;
}

if your run above code, you will get this: 8 16 8 8 4 8 sizof(itest) is not same with sizeof(ptest), because sizeof(ptest) mean size of pointer ptest. You may look at some article about pointer in C and test with it. It would not be too difficult.

yanxon commented 3 years ago

@macstein

Thank you for the explanation. I'm still not sure how to get the length of n due to the pointer issue.

However I fixed the code by declaring the n outside the kee_single() function.

I'm going to close this now.