| 84 | // type T can be CompMatr, DiagMatr or FullStateDiagMatr |
| 85 | template <class T> |
| 86 | void freeHeapMatrix(T matr) { |
| 87 | |
| 88 | // WARNING: this is not overwriting any freed pointers with null, |
| 89 | // since the caller's struct is not changed. This is fine here, |
| 90 | // but would be an issue if the struct contained nested pointers, |
| 91 | // since caller would not know an outer pointer was freed and |
| 92 | // ergo that it should not be enumerated (to check/free inner ptr) |
| 93 | |
| 94 | // free the 1D or 2D matrix - safe even if nullptr |
| 95 | if constexpr (util_isDenseMatrixType<T>()) { |
| 96 | cpu_deallocMatrixWrapper(matr.cpuElems); |
| 97 | cpu_deallocArray(matr.cpuElemsFlat); |
| 98 | } else |
| 99 | cpu_deallocArray(matr.cpuElems); |
| 100 | |
| 101 | // we avoid invoking a GPU function in non-GPU mode |
| 102 | auto gpuPtr = util_getGpuMemPtr(matr); |
| 103 | if (mem_isAllocated(gpuPtr)) |
| 104 | gpu_deallocArray(gpuPtr); |
| 105 | |
| 106 | // free the teeny tiny heap flags |
| 107 | util_deallocEpsilonSensitiveHeapFlag(matr.isApproxUnitary); |
| 108 | util_deallocEpsilonSensitiveHeapFlag(matr.isApproxHermitian); |
| 109 | cpu_deallocHeapFlag(matr.wasGpuSynced); |
| 110 | |
| 111 | // only diagonal matrices (which can be raised to |
| 112 | // exponents) need their negativity/zeroness checked |
| 113 | if constexpr (!util_isDenseMatrixType<T>()) { |
| 114 | util_deallocEpsilonSensitiveHeapFlag(matr.isApproxNonZero); |
| 115 | cpu_deallocHeapFlag(matr.isStrictlyNonNegative); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | |
| 120 | // type T can be CompMatr, DiagMatr or FullStateDiagMatr |
no test coverage detected