How to calculate ReLU function through ciphertext conversion?

I ran your code and no exception is being thrown on my side.

Nevertheless, there are many misunderstandings in your code, and it does not do what you intend to do.

  • GenerateLUTviaFunction only works for p <= 8. This is written in SCHEME_SWITCHING_CAPABILITY.md, which judging by the input x you are feeding, is not sufficient for your application.
  • You combine code from FuncViaSchemeSwitching() but replace the line auto pLWE = ccLWE->GetMaxPlaintextSpace().ConvertToInt(); // Small precision because GenerateLUTviaFunction needs p < q with pLWE from different functions that work with larger precision. You also make scaleCF 1 instead of 1/pLWE.
  • FHEW works with modular arithmetic, so every message is modulo p. This means that your condition in fp (x <= p) is always true. In modular arithmetic modulo p, positive numbers are less than p/2 and negative numbers are between p/2 and p.
  • When you print the expected result relu, you feed 0 instead of p.

To obtain the relu functionality, it is better to use the sign/compare capability using CKKS<->FHEW conversion, which returns a vector of elements encrypting zero for positive values and 1 for negative values (in real arithmetic), and then in CKKS you should multiply c1 by (1 - cTemp2). You can try to adapt the solution from Can FHE be used for comparing 2 ciphertexts? - #8 by Pavanranganath.