Cytnx-dev / Cytnx

Project Cytnx, A Cross-section of Python & C++,Tensor network library
Apache License 2.0
35 stars 13 forks source link

Problem with installing on Mac #449

Closed josephinius closed 3 days ago

josephinius commented 3 weeks ago

First, I had to add add_compile_options(-Wno-c++11-narrowing) into CMakeLists.txt to get rid of this error:

error: non-constant-expression cannot be narrowed from type 'value_type' (aka 'int') to 'unsigned long long' in initializer list [-Wc++11-narrowing]
        auto eigTens = P_inv.at({0, maxIdx}) * qs[0];

But I still have the following error while installing:

error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];

I use clang as a compiler.

yingjerkao commented 2 weeks ago

The first one can be resolved by explicit casting.

error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];

Can you tell me where it occurs?

Here is a related fix https://github.com/tfhe/tfhe/issues/213

josephinius commented 2 weeks ago

Here are the whole error messages:

/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:31:36: error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];
                 ~                 ^~~~~~~~~~~~~~~
/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:55:35: error: implicit conversion from '_Complex float' to 'float' is not permitted in C++
        od[0] *= (cytnx_complex64)_Rin[i * N + i];
IvanaGyro commented 2 weeks ago

455 fixed the no-c++11-narrowing problem. For the implicit conversion, I can't reproduce the error while using clang++. @josephinius, does the error still happen?

pcchen commented 2 weeks ago

with commit 0be640dcb08dcfd4de8ed9a2f7da73dec7ddfaf2 and clang version: -- The CXX compiler identification is AppleClang 15.0.0.15000309 -- The C compiler identification is AppleClang 15.0.0.15000309

I still encounter this

[ 83%] Building CXX object CMakeFiles/cytnx.dir/src/backend/linalg_internal_cpu/Ger_internal.cpp.o
/Users/pcchen/github/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:31:36: error: implicit conversion from '_Complex double' to 'double' is not permitted in C++
        od[0] *= (cytnx_complex128)_Rin[i * N + i];
                 ~                 ^~~~~~~~~~~~~~~
/Users/pcchen/github/Cytnx/src/backend/linalg_internal_cpu/Det_internal.cpp:55:35: error: implicit conversion from '_Complex float' to 'float' is not permitted in C++
        od[0] *= (cytnx_complex64)_Rin[i * N + i];
                 ~                ^~~~~~~~~~~~~~~
2 errors generated.
IvanaGyro commented 2 weeks ago

A solution was given in #461. I am not sure if the change really suppress the error of invalid conversion because I cannot reproduce on CentOS with clang and the online clang compiler either.

圖片

Someone who has Mac can try to build the code below with clang++ and see if it can be successfully compiled. If it is not passed, there may be a bug in Mac's clang.

#include <complex.h>
#include <iostream>
#include <complex>

int main() {
    double _Complex c_type_right = 123.4 + 45435.1I;
    std::complex<double> cpp_type_right{23, 23};
    std::complex<double> left{43.4, 2532.1};
    left *= (std::complex<double>)c_type_right;
    left *= (std::complex<double>)cpp_type_right;

    std::cout << std::complex<float>{c_type_right} << std::endl;
}
josephinius commented 2 weeks ago

@IvanaGyro I tried to compile the code

#include <complex.h>
#include <iostream>
#include <complex>

int main() {
    double _Complex c_type_right = 123.4 + 45435.1I;
    std::complex<double> cpp_type_right{23, 23};
    std::complex<double> left{43.4, 2532.1};
    left *= (std::complex<double>)c_type_right;
    left *= (std::complex<double>)cpp_type_right;

    std::cout << std::complex<float>{c_type_right} << std::endl;
}

using Apple clang version 15.0.0 (clang-1500.3.9.4); I got the error:

complex_example.cpp:10:35: error: implicit conversion from '_Complex double' to 'double' is not permitted in C++ left *= (std::complex)c_type_right; ~ ^~~~ complex_example.cpp:13:38: error: implicit conversion from '_Complex double' to 'float' is not permitted in C++ std::cout << std::complex{c_type_right} << std::endl;


2 errors generated.
IvanaGyro commented 3 days ago

It seems that #461 has resolve this issue. Apple Clang missed some features. We may consider not to support Apple Clang.

kaihsin commented 3 days ago

Which c++ version are we targeting? I would suggest target C++24 (don't use anything that is too new)

And If to possible please write the code that could cover most of the compilers ( specifically clang has more restrictions compared to g++, so I suggest to target clang when developing).

pcchen commented 2 days ago

Also. Apple's clang (Apple clang) is different from the typical clang. The behavior is different from the clang one installs on Mac via homebrew.......