| 659 | |
| 660 | template<typename T> |
| 661 | void Array<T>::resetAuxiliary(const std::vector<int>& sizes, T* const dataPtr) |
| 662 | { |
| 663 | try |
| 664 | { |
| 665 | if (!sizes.empty()) |
| 666 | { |
| 667 | // New size & volume |
| 668 | mSize = sizes; |
| 669 | mVolume = {std::accumulate(sizes.begin(), sizes.end(), std::size_t(1), std::multiplies<size_t>())}; |
| 670 | // Prepare shared_ptr |
| 671 | if (dataPtr == nullptr) |
| 672 | { |
| 673 | #ifdef WITH_AVX |
| 674 | spData = aligned_shared_ptr<T>(mVolume); |
| 675 | #else |
| 676 | spData.reset(new T[mVolume], std::default_delete<T[]>()); |
| 677 | #endif |
| 678 | pData = spData.get(); |
| 679 | // Sanity check |
| 680 | if (pData == nullptr) |
| 681 | error("Shared pointer could not be allocated for Array data storage.", |
| 682 | __LINE__, __FUNCTION__, __FILE__); |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | spData.reset(); |
| 687 | pData = dataPtr; |
| 688 | } |
| 689 | setCvMatFromPtr(mCvMatData, pData, mSize); // spData.get() |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | mSize = {}; |
| 694 | mVolume = 0ul; |
| 695 | spData.reset(); |
| 696 | pData = nullptr; |
| 697 | // Matrix available but empty |
| 698 | mCvMatData = std::make_pair(true, Matrix()); |
| 699 | } |
| 700 | } |
| 701 | catch (const std::exception& e) |
| 702 | { |
| 703 | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | COMPILE_TEMPLATE_BASIC_TYPES_CLASS(Array); |
| 708 | } |