| 50 | |
| 51 | |
| 52 | void demo_getCompMatr() { |
| 53 | |
| 54 | // inline literal (C++ only) |
| 55 | CompMatr1 a = getCompMatr1( {{1,2_i},{3_i+.1,-4}} ); |
| 56 | reportCompMatr1(a); |
| 57 | |
| 58 | // 2D vector (C++ only) |
| 59 | vector<vector<qcomp>> vec {{-9,-8},{-7,-6}}; |
| 60 | CompMatr1 b = getCompMatr1(vec); |
| 61 | reportCompMatr1(b); |
| 62 | |
| 63 | // 2D compile-time array |
| 64 | qcomp arr[2][2] = {{5, 4},{3, 2}}; |
| 65 | CompMatr1 c = getCompMatr1(arr); |
| 66 | reportCompMatr1(c); |
| 67 | |
| 68 | // nested pointers |
| 69 | int dim = 4; |
| 70 | qcomp** ptrs = (qcomp**) malloc(dim * sizeof *ptrs); |
| 71 | for (int i=0; i<dim; i++) { |
| 72 | ptrs[i] =(qcomp*) malloc(dim * sizeof **ptrs); |
| 73 | for (int j=0; j<dim; j++) |
| 74 | ptrs[i][j] = i + j*1i; |
| 75 | } |
| 76 | CompMatr2 d = getCompMatr2(ptrs); |
| 77 | reportCompMatr2(d); |
| 78 | |
| 79 | // array of pointers |
| 80 | qcomp* ptrArr[4]; |
| 81 | for (int i=0; i<dim; i++) |
| 82 | ptrArr[i] = ptrs[i]; |
| 83 | CompMatr2 e = getCompMatr2(ptrArr); |
| 84 | reportCompMatr2(e); |
| 85 | |
| 86 | // cleanup |
| 87 | for (int i=0; i<dim; i++) |
| 88 | free(ptrs[i]); |
| 89 | free(ptrs); |
| 90 | } |
| 91 | |
| 92 | |
| 93 |
no test coverage detected