| 247 | // compute the (data-dataBase), store the non-zero data items |
| 248 | template <typename T> |
| 249 | size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, unsigned int numCompsOut, void *&outputNZDiff, void *&outputNZIdx) { |
| 250 | std::vector<T> vNZDiff; |
| 251 | std::vector<unsigned short> vNZIdx; |
| 252 | size_t totalComps = count * numCompsIn; |
| 253 | T *bufferData_ptr = static_cast<T *>(data); |
| 254 | T *bufferData_end = bufferData_ptr + totalComps; |
| 255 | T *bufferBase_ptr = static_cast<T *>(dataBase); |
| 256 | |
| 257 | // Search and set extreme values. |
| 258 | for (short idx = 0; bufferData_ptr < bufferData_end; idx += 1, bufferData_ptr += numCompsIn) { |
| 259 | bool bNonZero = false; |
| 260 | |
| 261 | // for the data, check any component Non Zero |
| 262 | for (unsigned int j = 0; j < numCompsOut; j++) { |
| 263 | double valueData = bufferData_ptr[j]; |
| 264 | double valueBase = bufferBase_ptr ? bufferBase_ptr[j] : 0; |
| 265 | if ((valueData - valueBase) != 0) { |
| 266 | bNonZero = true; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // all zeros, continue |
| 272 | if (!bNonZero) |
| 273 | continue; |
| 274 | |
| 275 | // non zero, store the data |
| 276 | for (unsigned int j = 0; j < numCompsOut; j++) { |
| 277 | T valueData = bufferData_ptr[j]; |
| 278 | T valueBase = bufferBase_ptr ? bufferBase_ptr[j] : 0; |
| 279 | vNZDiff.push_back(valueData - valueBase); |
| 280 | } |
| 281 | vNZIdx.push_back(idx); |
| 282 | } |
| 283 | |
| 284 | // avoid all-0, put 1 item |
| 285 | if (vNZDiff.size() == 0) { |
| 286 | for (unsigned int j = 0; j < numCompsOut; j++) |
| 287 | vNZDiff.push_back(0); |
| 288 | vNZIdx.push_back(0); |
| 289 | } |
| 290 | |
| 291 | // process data |
| 292 | outputNZDiff = new T[vNZDiff.size()]; |
| 293 | memcpy(outputNZDiff, vNZDiff.data(), vNZDiff.size() * sizeof(T)); |
| 294 | |
| 295 | outputNZIdx = new unsigned short[vNZIdx.size()]; |
| 296 | memcpy(outputNZIdx, vNZIdx.data(), vNZIdx.size() * sizeof(unsigned short)); |
| 297 | return vNZIdx.size(); |
| 298 | } |
| 299 | |
| 300 | inline size_t NZDiff(ComponentType compType, void *data, void *dataBase, size_t count, unsigned int numCompsIn, unsigned int numCompsOut, void *&nzDiff, void *&nzIdx) { |
| 301 | switch (compType) { |
no test coverage detected