| 36 | |
| 37 | template <typename T> |
| 38 | class pointer_array |
| 39 | { |
| 40 | public: |
| 41 | struct holder_t |
| 42 | { |
| 43 | explicit holder_t(T* d, std::size_t size) |
| 44 | : data_(d) |
| 45 | , shape_(size) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | explicit holder_t(T* d, std::size_t size, std::size_t size2) |
| 50 | : data_(d) |
| 51 | , shape_({size, size2}) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | T* data_; |
| 56 | icm::shape shape_; |
| 57 | }; |
| 58 | |
| 59 | public: |
| 60 | explicit pointer_array(T* value, std::size_t size) |
| 61 | : value_(std::make_shared<holder_t>(value, size)) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | explicit pointer_array(T* value, std::size_t size, std::size_t size2) |
| 66 | : value_(std::make_shared<holder_t>(value, size, size2)) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | enum nd::dtype dtype() const |
| 71 | { |
| 72 | return nd::dtype_enum_v<T>; |
| 73 | } |
| 74 | |
| 75 | std::span<const uint8_t> data() const |
| 76 | { |
| 77 | auto len = |
| 78 | value_->shape_.size() == 1 ? value_->shape_.front() : (value_->shape_.front() * value_->shape_.back()); |
| 79 | return base::span_cast<const uint8_t>(std::span<const T>(value_->data_, value_->data_ + len)); |
| 80 | } |
| 81 | |
| 82 | const auto& owner() const |
| 83 | { |
| 84 | return value_; |
| 85 | } |
| 86 | |
| 87 | icm::shape shape() const |
| 88 | { |
| 89 | return value_->shape_; |
| 90 | } |
| 91 | |
| 92 | constexpr bool is_dynamic() const noexcept |
| 93 | { |
| 94 | return false; |
| 95 | } |