What is the best way to find absolute value of each of the elements of a complex matrix in c++? In this case, I generate my complex matrix (real and imaginary) as below:
int main()
{
int i, j;
int N = 2;
complex <float> a[2][2], b[2][2];
Thank you. But how I am going to calculate absoulte value manually? What I mean is:
Absolute value of a[i][j] = sqrt(a.real*areal + a.imag*a.imag).
How I am going to seperate the real and imaginary parts so that I can fix into he equation above? I would like to do this because I faced a problem to use "abs" in Vivado HLS which is for hardware implementation.
Actually I want to compare the result of complex matrix with the reference matrix which is also a complex matrix. So, what I would like to do is to compare the absolute value of each of these matrices. From the errors, I think I should write the correct command that suit with the hardware. These are the errors that appreared when I compiled my algorithm in Vivado:
no matching function for call to 'abs(cfloat_t&)'
../../../../complexmultiplication_tb.cpp:48:17: note: candidates are:
c:\xilinx\vivado\2018.1\msys\bin\../lib/gcc/mingw32/4.6.2/../../../../include/stdlib.h:374:37: note: int abs(int)
c:\xilinx\vivado\2018.1\msys\bin\../lib/gcc/mingw32/4.6.2/../../../../include/stdlib.h:374:37: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'int'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:1219:14: note: template<int I> ap_uint<_AP_W2> hls::abs(ap_uint<_AP_W2>)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:1215:13: note: template<int I> ap_int<_AP_W2> hls::abs(ap_int<_AP_W2>)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:1211:18: note: template<int W, int I> ap_ufixed<W, I> hls::abs(ap_ufixed<W, I>)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:1207:17: note: template<int W, int I> ap_fixed<W, I> hls::abs(ap_fixed<W, I>)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:155:12: note: uint32_t hls::abs(uint32_t)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:155:12: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'uint32_t {aka unsigned int}'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:153:12: note: uint16_t hls::abs(uint16_t)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:153:12: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'uint16_t {aka short unsigned int}'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:152:11: note: int16_t hls::abs(int16_t)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:152:11: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'int16_t {aka short int}'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:151:11: note: uint8_t hls::abs(uint8_t)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:151:11: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'uint8_t {aka unsigned char}'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:150:10: note: int8_t hls::abs(int8_t)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:150:10: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'int8_t {aka signed char}'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:147:10: note: half hls::abs(half)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:147:10: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'half'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:146:10: note: float hls::abs(float)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:146:10: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'float'
C:/Xilinx/Vivado/2018.1/include/hls_math.h:145:10: note: double hls::abs(double)
C:/Xilinx/Vivado/2018.1/include/hls_math.h:145:10: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'double'
C:/Xilinx/Vivado/2018.1/include/hls/utils/x_hls_utils.h:149:14: note: long int hls::abs(long int)
C:/Xilinx/Vivado/2018.1/include/hls/utils/x_hls_utils.h:149:14: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'long int'
C:/Xilinx/Vivado/2018.1/include/hls/utils/x_hls_utils.h:145:9: note: int32_t hls::abs(int32_t)
C:/Xilinx/Vivado/2018.1/include/hls/utils/x_hls_utils.h:145:9: note: no known conversion for argument 1 from 'cfloat_t {aka hls::x_complex<float>}' to 'int32_t {aka int}'
../../../../complexmultiplication_tb.cpp:48:39: error: no matching function for call to 'abs(cfloat_t&)'
There are still errors:
1. sqrt - "Invalid argument: Candidates are - Double sqrt(double)"
2. real - "Method 'real' could not be resolved"
3. imag - "Method 'imag' could not be resolved"