Dobiasd / frugally-deep

A lightweight header-only library for using Keras (TensorFlow) models in C++.
MIT License
1.07k stars 237 forks source link

Several compiler errors with Visual Studio 2022 (C++20) #395

Closed dasmysh closed 1 year ago

dasmysh commented 1 year ago

I encountered several compiler errors with your code in VS2022 and C++20. The first issue is for sure a C++20 issue, the second one might be a VS(2022) thing.

First, FunctionalPlus does not work. std::result_of was removed in favor of std::invoke_result and they are still using that. I'll write a github issue there as well but I'll also describe the fix here:

Any instance of

std::result_of<Func(Params)>

becomes

std::invoke_result<Func, Params>

Another issue is in the attention_layer.hpp and additive_attention_layer.hpp: The tanh used in one of the transform_tensor calls seems to be ambiguous. Replacing that with a tanhf fixes it.

Dobiasd commented 1 year ago

Hi, and thanks for the report. :+1:

The problem with std::result_of should be solved when switching to the latest version of FunctionalPlus. See this thread for details.

Dobiasd commented 1 year ago

Regarding std::tanh, I'm not using tanhf, because it's intended for floats. By default, however, FDEEP_FLOAT_TYPE is double, so that's why I'm using the overloaded tanh.

Can you try replacing tanh with std::tanh in attention_layer.hpp locally, and let me know if this resolves your compiler error?

Dobiasd commented 1 year ago

The above suggestion might not work. But I just pushed a commit, that should fix it.

Can you please try compiling again with the latest version from master and let me know if that helped?

dasmysh commented 1 year ago

Can you try replacing tanh with std::tanh in attention_layer.hpp locally, and let me know if this resolves your compiler error?

That is still ambiguous. But what does help is specifying the template arguments of transform_tensor by explicitly calling transform_tensor<float_type(float_type)>(tanh, [...]).

Dobiasd commented 1 year ago

And how about the latest version from master, i.e., the one with tanh_typed?

dasmysh commented 1 year ago

master also works.

dasmysh commented 1 year ago

So yes, issue is fixed. Thanks for the fast replies.

Dobiasd commented 1 year ago

Thanks for the error report, helping to make the library better, and to make the experience smoother for future users! :heart: