Helper: allocate Mathcad array and copy a vector-of-vectors into its real part
| 116 | |
| 117 | // Helper: allocate Mathcad array and copy a vector-of-vectors into its real part |
| 118 | static LRESULT AllocateToMathcadArray(LPCOMPLEXARRAY dest, const std::vector<std::vector<double>>& Vec) { |
| 119 | // Expect Vec to be non-empty (caller checks ValidNumber(Vec[0][0]) earlier) |
| 120 | const size_t rows = Vec.size(); |
| 121 | const size_t cols = (rows > 0) ? Vec[0].size() : 0; |
| 122 | |
| 123 | // Make sure dest is an actual pointer before trying to allocate memory for it |
| 124 | if (dest == nullptr) { |
| 125 | return MAKELRESULT(INSUFFICIENT_MEMORY, 0); // Return error if dest is not a valid pointer |
| 126 | } |
| 127 | |
| 128 | // Allocate Mathcad array memory (real part only) |
| 129 | if (!MathcadArrayAllocate(dest, |
| 130 | static_cast<int>(rows), // rows = number of output variables |
| 131 | static_cast<int>(cols), // cols = number of input values |
| 132 | TRUE, // allocate memory for the real part |
| 133 | FALSE)) // do not allocate memory for the imaginary part |
| 134 | { |
| 135 | return MAKELRESULT(INSUFFICIENT_MEMORY, 1); |
| 136 | } |
| 137 | |
| 138 | // Copy contents into the allocated real matrix |
| 139 | for (size_t irow = 0; irow < rows; ++irow) { |
| 140 | const auto& row = Vec[irow]; |
| 141 | // Assume each inner vector has 'cols' elements (consistent with PropsSImulti contract) |
| 142 | for (size_t icol = 0; icol < cols; ++icol) { |
| 143 | dest->hReal[icol][irow] = row[icol]; // Note the indexing order for Mathcad arrays: hReal[column][row] |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | // Helper: Get IEEE 754 double precision NaN value for returning in case of errors in array outputs |
| 151 | static double get_nan() { |
no test coverage detected