| 156 | */ |
| 157 | template <class Handle> |
| 158 | class ArrayElemCorrState { |
| 159 | |
| 160 | template <class OtherHandle> |
| 161 | friend class ArrayElemCorrState; |
| 162 | |
| 163 | public: |
| 164 | ArrayElemCorrState(const AnyType &inArray) |
| 165 | : mStorage(inArray.getAs<Handle>()) { |
| 166 | |
| 167 | rebind(static_cast<uint16_t>(mStorage[1])); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @brief Convert to backend representation |
| 172 | * |
| 173 | * We define this function so that we can use TransitionState in the argument |
| 174 | * list and as a return type. */ |
| 175 | inline operator AnyType() const { |
| 176 | return mStorage; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @brief Initialize the transition state. Only called for first row. |
| 181 | * |
| 182 | * @param inAllocator Allocator for the memory transition state. Must fill |
| 183 | * the memory block with zeros. |
| 184 | * @param inWidthOfX Number of independent variables. The first row of data |
| 185 | * determines the size of the transition state. This size is a quadratic |
| 186 | * function of inWidthOfX. |
| 187 | */ |
| 188 | inline void initialize(const Allocator &inAllocator, uint16_t inWidthOfX) { |
| 189 | mStorage = inAllocator.allocateArray<double, dbal::AggregateContext, |
| 190 | dbal::DoZero, |
| 191 | dbal::ThrowBadAlloc>(arraySize(inWidthOfX)); |
| 192 | rebind(inWidthOfX); |
| 193 | widthOfX = inWidthOfX; |
| 194 | this->reset(); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @brief We need to support assigning the previous state |
| 199 | */ |
| 200 | template <class OtherHandle> |
| 201 | ArrayElemCorrState &operator=( |
| 202 | const ArrayElemCorrState<OtherHandle> &inOtherState) { |
| 203 | for (size_t i = 0; i < mStorage.size(); i++) |
| 204 | mStorage[i] = inOtherState.mStorage[i]; |
| 205 | return *this; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @brief Merge with another State object by copying the intra-iteration |
| 210 | * fields |
| 211 | */ |
| 212 | template <class OtherHandle> |
| 213 | ArrayElemCorrState &operator+=( |
| 214 | const ArrayElemCorrState<OtherHandle> &inOtherState) { |
| 215 | |