| 120 | // type T can be CompMatr, DiagMatr or FullStateDiagMatr |
| 121 | template <class T> |
| 122 | bool didAnyLocalAllocsFail(T matr) { |
| 123 | |
| 124 | // god help us if these single-integer malloc failed |
| 125 | if (!mem_isAllocated(matr.isApproxUnitary)) return true; |
| 126 | if (!mem_isAllocated(matr.isApproxHermitian)) return true; |
| 127 | if (!mem_isAllocated(matr.wasGpuSynced)) return true; |
| 128 | |
| 129 | // only diagonal matrices (which can be raised to |
| 130 | // exponents) have these addtional fields |
| 131 | if constexpr (!util_isDenseMatrixType<T>()) { |
| 132 | if (!mem_isAllocated(matr.isApproxNonZero)) return true; |
| 133 | if (!mem_isAllocated(matr.isStrictlyNonNegative)) return true; |
| 134 | } |
| 135 | |
| 136 | // outer CPU memory should always be allocated |
| 137 | if constexpr (util_isDenseMatrixType<T>()) { |
| 138 | if (!mem_isAllocated(matr.cpuElemsFlat)) return true; |
| 139 | if (!mem_isOuterAllocated(matr.cpuElems)) return true; |
| 140 | } else |
| 141 | if (!mem_isAllocated(matr.cpuElems)) return true; |
| 142 | |
| 143 | // if GPU memory is not allocated in a GPU environment... |
| 144 | bool isGpuAlloc = mem_isAllocated(util_getGpuMemPtr(matr)); |
| 145 | if (getQuESTEnv().isGpuAccelerated && !isGpuAlloc) { |
| 146 | |
| 147 | // then FullStateDiagMatr GPU alloc failed only if it tried... |
| 148 | if constexpr (util_isFullStateDiagMatr<T>()) { |
| 149 | if (matr.isGpuAccelerated) |
| 150 | return true; |
| 151 | |
| 152 | // but all other matrices always try to alloc, so must have failed |
| 153 | } else |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | // otherwise, all pointers were non-NULL and ergo all allocs were successful |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | // type T can be CompMatr, DiagMatr or FullStateDiagMatr |
no test coverage detected