libpressio 0.93.0
Loading...
Searching...
No Matches
data.h
Go to the documentation of this file.
1#ifndef PRESSIO_DATA_CPP_H
2#define PRESSIO_DATA_CPP_H
3
4
5
6#include <stdexcept>
7#include <vector>
8#include <cstdlib>
9#include <cstring>
10#include <utility>
11#include <algorithm>
12#include "pressio_data.h"
14#include "std_compat/utility.h"
15#include "std_compat/optional.h"
16
25template <class T>
27 return [](void* data, void*){
28 T* data_t = static_cast<T*>(data);
29 delete[] data_t;
30 };
31}
32
33
39size_t data_size_in_elements(size_t dimensions, size_t const dims[]);
46size_t data_size_in_bytes(pressio_dtype type, size_t const dimensions, size_t const dims[]);
47
48
53
62 static pressio_data empty(const pressio_dtype dtype, std::vector<size_t> const& dimensions) {
63 return pressio_data(dtype, nullptr, nullptr, nullptr, dimensions.size(), dimensions.data());
64 }
74 static pressio_data nonowning(const pressio_dtype dtype, void* data, std::vector<size_t> const& dimensions) {
76 }
82 static pressio_data copy(const enum pressio_dtype dtype, const void* src, std::vector<size_t> const& dimensions) {
83 return pressio_data::copy(dtype, src, dimensions.size(), dimensions.data());
84 }
93 static pressio_data owning(const pressio_dtype dtype, std::vector<size_t> const& dimensions) {
94 return pressio_data::owning(dtype, dimensions.size(), dimensions.data());
95 }
108 void* data,
109 std::vector<size_t> const& dimensions,
111 void* metadata) {
112 return pressio_data::move(dtype, data, dimensions.size(), dimensions.data(), deleter, metadata);
113 }
114
124 static pressio_data empty(const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[]) {
125 return pressio_data(dtype, nullptr, nullptr, nullptr, num_dimensions, dimensions);
126 }
127
138 static pressio_data nonowning(const pressio_dtype dtype, void* data, size_t const num_dimensions, size_t const dimensions[]) {
139 return pressio_data(dtype, data, nullptr, nullptr, num_dimensions, dimensions);
140 }
141
152 static pressio_data copy(const enum pressio_dtype dtype, const void* src, size_t const num_dimensions, size_t const dimensions[]) {
154 void* data = nullptr;
155 if(bytes != 0) {
156 data = malloc(bytes);
157 memcpy(data, src, bytes);
158 }
160 }
161
171 static pressio_data owning(const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[]) {
173 void* data = nullptr;
174 if(bytes != 0) data = malloc(bytes);
176 }
177
178
192 void* data,
193 size_t const num_dimensions,
194 size_t const dimensions[],
196 void* metadata) {
197 return pressio_data(dtype, data, metadata, deleter, num_dimensions, dimensions);
198 }
199
209 static pressio_data clone(pressio_data const& src){
210 size_t bytes = src.size_in_bytes();
211 unsigned char* data = nullptr;
212 if(bytes != 0 && src.data() != nullptr) {
213 data = static_cast<unsigned char*>(malloc(bytes));
214 memcpy(data, src.data(), src.size_in_bytes());
215 }
216 return pressio_data(src.dtype(),
217 data,
218 nullptr,
220 src.num_dimensions(),
221 src.dimensions().data()
222 );
223 }
224
225 pressio_data() :
226 data_dtype(pressio_byte_dtype),
227 data_ptr(nullptr),
228 metadata_ptr(nullptr),
229 deleter(nullptr),
230 dims(),
231 capacity(0)
232 {}
233
234 ~pressio_data() {
235 if(deleter!=nullptr) deleter(data_ptr,metadata_ptr);
236 };
237
243 if(this == &rhs) return *this;
244 data_dtype = rhs.data_dtype;
245 if(rhs.has_data() && rhs.size_in_bytes() > 0) {
246 if(deleter != nullptr) deleter(data_ptr, metadata_ptr);
247 data_ptr = malloc(rhs.size_in_bytes());
248 memcpy(data_ptr, rhs.data_ptr, rhs.size_in_bytes());
249 } else {
250 data_ptr = nullptr;
251 }
252 metadata_ptr = nullptr;
254 dims = rhs.dims;
255 capacity = data_size_in_bytes(rhs.dtype(), rhs.dims.size(), rhs.dims.data()); //we only malloc size_in_bytes()
256 return *this;
257 }
263 data_dtype(rhs.data_dtype),
264 data_ptr((rhs.has_data())? malloc(rhs.size_in_bytes()) : nullptr),
265 metadata_ptr(nullptr),
267 dims(rhs.dims),
268 capacity(data_size_in_bytes(rhs.dtype(), rhs.dims.size(), rhs.dims.data())) //we only malloc size_in_bytes
269 {
270 if(rhs.has_data() && rhs.size_in_bytes() > 0) {
271 memcpy(data_ptr, rhs.data_ptr, rhs.size_in_bytes());
272 }
273 }
280 pressio_data(pressio_data&& rhs) noexcept:
281 data_dtype(rhs.data_dtype),
282 data_ptr(compat::exchange(rhs.data_ptr, nullptr)),
283 metadata_ptr(compat::exchange(rhs.metadata_ptr, nullptr)),
284 deleter(compat::exchange(rhs.deleter, nullptr)),
285 dims(compat::exchange(rhs.dims, {})),
286 capacity(compat::exchange(rhs.capacity, 0)) //we take ownership, so take everything
287 {}
288
296 if(this==&rhs) return *this;
297 if(deleter!=nullptr) deleter(data_ptr,metadata_ptr);
298 data_dtype = rhs.data_dtype,
299 data_ptr = compat::exchange(rhs.data_ptr, nullptr),
300 metadata_ptr = compat::exchange(rhs.metadata_ptr, nullptr),
301 deleter = compat::exchange(rhs.deleter, nullptr),
302 dims = compat::exchange(rhs.dims, {});
303 capacity = compat::exchange(rhs.capacity, 0);
304 return *this;
305 }
306
312 template <class T>
313 pressio_data(std::initializer_list<T> il):
314 data_dtype(pressio_dtype_from_type<T>()),
315 data_ptr((il.size() == 0)? nullptr:malloc(il.size() * sizeof(T))),
316 metadata_ptr(nullptr),
318 dims({il.size()})
319 {
320 std::copy(std::begin(il), std::end(il), static_cast<T*>(data_ptr));
321 }
322
323
327 void* data() const {
328 return data_ptr;
329 }
330
334 bool has_data() const {
335 return data_ptr != nullptr && size_in_bytes() > 0;
336 }
337
342 return data_dtype;
343 }
344
349 data_dtype = dtype;
350 }
351
360 size_t num_dimensions() const {
361 return dims.size();
362 }
363
367 std::vector<size_t> const& dimensions() const {
368 return dims;
369 }
370
374 std::vector<size_t> normalized_dims(compat::optional<size_t> n={}, size_t fill=0) const;
375
376
386 size_t set_dimensions(std::vector<size_t>&& dims) {
387 size_t new_size = data_size_in_bytes(data_dtype, dims.size(), dims.data());
388 if(capacity_in_bytes() < new_size) {
389 void* tmp = malloc(new_size);
390 if(tmp == nullptr) {
391 return 0;
392 } else {
393 memcpy(tmp, data_ptr, size_in_bytes());
394 if(deleter!=nullptr) deleter(data_ptr,metadata_ptr);
395
396 data_ptr = tmp;
398 metadata_ptr = nullptr;
399 capacity = new_size;
400 }
401 }
402 this->dims = std::move(dims);
403 return size_in_bytes();
404 }
405
410 size_t get_dimension(size_t idx) const {
411 if(idx >= num_dimensions()) return 0;
412 else return dims[idx];
413 }
414
418 size_t size_in_bytes() const {
419 return data_size_in_bytes(data_dtype, num_dimensions(), dims.data());
420 }
421
425 size_t capacity_in_bytes() const {
426 return capacity;
427 }
428
432 size_t num_elements() const {
433 return data_size_in_elements(num_dimensions(), dims.data());
434 }
435
436
447 pressio_data select(std::vector<size_t> const& start = {},
448 std::vector<size_t> const& stride = {},
449 std::vector<size_t> const& count = {},
450 std::vector<size_t> const& block = {}) const;
451
452
463 int reshape(std::vector<size_t> const& new_dimensions) {
464 const size_t old_size = data_size_in_elements(num_dimensions(), dims.data());
465 const size_t new_size = data_size_in_elements(new_dimensions.size(), new_dimensions.data());
466
467 dims = new_dimensions;
468
469 if(old_size == new_size) {
470 return 0;
471 } else if (old_size > new_size){
472 return -1;
473 } else {
474 return 1;
475 }
476 }
477
483 template <class T>
484 std::vector<T> to_vector() const {
485 if(pressio_dtype_from_type<T>() == dtype()) {
486 return std::vector<T>(static_cast<T*>(data()), static_cast<T*>(data()) + num_elements());
487 } else {
488 auto casted = cast(pressio_dtype_from_type<T>());
489 return std::vector<T>(static_cast<T*>(casted.data()), static_cast<T*>(casted.data()) + casted.num_elements());
490 }
491 }
492
499 template <class ForwardIt>
500 pressio_data(ForwardIt begin, ForwardIt end):
501 data_dtype(pressio_dtype_from_type<typename std::iterator_traits<ForwardIt>::value_type>()),
502 data_ptr(malloc(std::distance(begin, end)*pressio_dtype_size(data_dtype))),
503 metadata_ptr(nullptr),
505 dims({static_cast<size_t>(std::distance(begin, end))})
506 {
507 using out_t = typename std::add_pointer<typename std::decay<
508 typename std::iterator_traits<ForwardIt>::value_type>::type>::type;
509
510 std::copy(begin, end, static_cast<out_t>(data_ptr));
511 }
512
519 pressio_data transpose(std::vector<size_t> const& axis = {}) const;
520
524 bool operator==(pressio_data const& rhs) const;
525
526 private:
536 void* data,
537 void* metadata,
538 void (*deleter)(void*, void*),
539 size_t const num_dimensions,
540 size_t const dimensions[]
541 ):
542 data_dtype(dtype),
543 data_ptr(data),
544 metadata_ptr(metadata),
545 deleter(deleter),
548 {}
559 void* data,
560 void* metadata,
561 void (*deleter)(void*, void*),
562 size_t const num_dimensions,
563 size_t const dimensions[],
564 size_t capacity
565 ):
566 data_dtype(dtype),
567 data_ptr(data),
568 metadata_ptr(metadata),
569 deleter(deleter),
571 capacity(capacity)
572 {}
573 pressio_dtype data_dtype;
574 void* data_ptr;
575 void* metadata_ptr;
576 void (*deleter)(void*, void*);
577 std::vector<size_t> dims;
578 size_t capacity;
579};
580
588template <class ReturnType, class Function>
589ReturnType pressio_data_for_each(pressio_data const& data, Function&& f)
590{
591 switch(data.dtype())
592 {
594 return std::forward<Function>(f)(
595 static_cast<double*>(data.data()),
596 static_cast<double*>(data.data()) + data.num_elements()
597 );
599 return std::forward<Function>(f)(
600 static_cast<float*>(data.data()),
601 static_cast<float*>(data.data()) + data.num_elements()
602 );
604 return std::forward<Function>(f)(
605 static_cast<uint8_t*>(data.data()),
606 static_cast<uint8_t*>(data.data()) + data.num_elements()
607 );
609 return std::forward<Function>(f)(
610 static_cast<uint16_t*>(data.data()),
611 static_cast<uint16_t*>(data.data()) + data.num_elements()
612 );
614 return std::forward<Function>(f)(
615 static_cast<uint32_t*>(data.data()),
616 static_cast<uint32_t*>(data.data()) + data.num_elements()
617 );
619 return std::forward<Function>(f)(
620 static_cast<uint64_t*>(data.data()),
621 static_cast<uint64_t*>(data.data()) + data.num_elements()
622 );
624 return std::forward<Function>(f)(
625 static_cast<int8_t*>(data.data()),
626 static_cast<int8_t*>(data.data()) + data.num_elements()
627 );
629 return std::forward<Function>(f)(
630 static_cast<int16_t*>(data.data()),
631 static_cast<int16_t*>(data.data()) + data.num_elements()
632 );
634 return std::forward<Function>(f)(
635 static_cast<int32_t*>(data.data()),
636 static_cast<int32_t*>(data.data()) + data.num_elements()
637 );
639 return std::forward<Function>(f)(
640 static_cast<int64_t*>(data.data()),
641 static_cast<int64_t*>(data.data()) + data.num_elements()
642 );
644 default:
645 return std::forward<Function>(f)(
646 static_cast<unsigned char*>(data.data()),
647 static_cast<unsigned char*>(data.data()) + data.size_in_bytes()
648 );
649 }
650}
651
659template <class ReturnType, class Function>
660ReturnType pressio_data_for_each(pressio_data& data, Function&& f)
661{
662 switch(data.dtype())
663 {
665 return std::forward<Function>(f)(
666 static_cast<double*>(data.data()),
667 static_cast<double*>(data.data()) + data.num_elements()
668 );
670 return std::forward<Function>(f)(
671 static_cast<float*>(data.data()),
672 static_cast<float*>(data.data()) + data.num_elements()
673 );
675 return std::forward<Function>(f)(
676 static_cast<uint8_t*>(data.data()),
677 static_cast<uint8_t*>(data.data()) + data.num_elements()
678 );
680 return std::forward<Function>(f)(
681 static_cast<uint16_t*>(data.data()),
682 static_cast<uint16_t*>(data.data()) + data.num_elements()
683 );
685 return std::forward<Function>(f)(
686 static_cast<uint32_t*>(data.data()),
687 static_cast<uint32_t*>(data.data()) + data.num_elements()
688 );
690 return std::forward<Function>(f)(
691 static_cast<uint64_t*>(data.data()),
692 static_cast<uint64_t*>(data.data()) + data.num_elements()
693 );
695 return std::forward<Function>(f)(
696 static_cast<int8_t*>(data.data()),
697 static_cast<int8_t*>(data.data()) + data.num_elements()
698 );
700 return std::forward<Function>(f)(
701 static_cast<int16_t*>(data.data()),
702 static_cast<int16_t*>(data.data()) + data.num_elements()
703 );
705 return std::forward<Function>(f)(
706 static_cast<int32_t*>(data.data()),
707 static_cast<int32_t*>(data.data()) + data.num_elements()
708 );
710 return std::forward<Function>(f)(
711 static_cast<int64_t*>(data.data()),
712 static_cast<int64_t*>(data.data()) + data.num_elements()
713 );
715 default:
716 return std::forward<Function>(f)(
717 static_cast<unsigned char*>(data.data()),
718 static_cast<unsigned char*>(data.data()) + data.size_in_bytes()
719 );
720 }
721}
722
723namespace {
724 template <class ReturnType, class Function, class Type1, class Type2>
725 ReturnType pressio_data_for_each_call(pressio_data const& data, pressio_data const& data2, Function&& f) {
726 return std::forward<Function>(f)(
727 static_cast<Type1*>(data.data()),
728 static_cast<Type1*>(data.data()) + data.num_elements(),
729 static_cast<Type2*>(data2.data()),
730 static_cast<Type2*>(data2.data()) + data2.num_elements()
731 );
732 }
733 template <class ReturnType, class Function, class Type1>
734 ReturnType pressio_data_for_each_type2_switch(pressio_data const& data, pressio_data const& data2, Function&& f) {
735 switch(data2.dtype()) {
737 return pressio_data_for_each_call<ReturnType, Function, Type1, double>(data, data2, std::forward<Function>(f));
739 return pressio_data_for_each_call<ReturnType, Function, Type1, float>(data, data2, std::forward<Function>(f));
741 return pressio_data_for_each_call<ReturnType, Function, Type1, uint8_t>(data, data2, std::forward<Function>(f));
743 return pressio_data_for_each_call<ReturnType, Function, Type1, uint16_t>(data, data2, std::forward<Function>(f));
745 return pressio_data_for_each_call<ReturnType, Function, Type1, uint32_t>(data, data2, std::forward<Function>(f));
747 return pressio_data_for_each_call<ReturnType, Function, Type1, uint64_t>(data, data2, std::forward<Function>(f));
749 return pressio_data_for_each_call<ReturnType, Function, Type1, int8_t>(data, data2, std::forward<Function>(f));
751 return pressio_data_for_each_call<ReturnType, Function, Type1, int16_t>(data, data2, std::forward<Function>(f));
753 return pressio_data_for_each_call<ReturnType, Function, Type1, int32_t>(data, data2, std::forward<Function>(f));
755 return pressio_data_for_each_call<ReturnType, Function, Type1, int64_t>(data, data2, std::forward<Function>(f));
756 default:
757 return pressio_data_for_each_call<ReturnType, Function, Type1, char>(data, data2, std::forward<Function>(f));
758 }
759 }
760 template <class ReturnType, class Function, class Type1, class Type2>
761 ReturnType pressio_data_for_each_call(pressio_data& data, pressio_data& data2, Function&& f) {
762 return std::forward<Function>(f)(
763 static_cast<Type1*>(data.data()),
764 static_cast<Type1*>(data.data()) + data.num_elements(),
765 static_cast<Type2*>(data2.data())
766 );
767 }
768 template <class ReturnType, class Function, class Type1>
769 ReturnType pressio_data_for_each_type2_switch(pressio_data& data, pressio_data& data2, Function&& f) {
770 switch(data2.dtype()) {
772 return pressio_data_for_each_call<ReturnType, Function, Type1, double>(data, data2, std::forward<Function>(f));
774 return pressio_data_for_each_call<ReturnType, Function, Type1, float>(data, data2, std::forward<Function>(f));
776 return pressio_data_for_each_call<ReturnType, Function, Type1, uint8_t>(data, data2, std::forward<Function>(f));
778 return pressio_data_for_each_call<ReturnType, Function, Type1, uint16_t>(data, data2, std::forward<Function>(f));
780 return pressio_data_for_each_call<ReturnType, Function, Type1, uint32_t>(data, data2, std::forward<Function>(f));
782 return pressio_data_for_each_call<ReturnType, Function, Type1, uint64_t>(data, data2, std::forward<Function>(f));
784 return pressio_data_for_each_call<ReturnType, Function, Type1, int8_t>(data, data2, std::forward<Function>(f));
786 return pressio_data_for_each_call<ReturnType, Function, Type1, int16_t>(data, data2, std::forward<Function>(f));
788 return pressio_data_for_each_call<ReturnType, Function, Type1, int32_t>(data, data2, std::forward<Function>(f));
790 return pressio_data_for_each_call<ReturnType, Function, Type1, int64_t>(data, data2, std::forward<Function>(f));
791 default:
792 return pressio_data_for_each_call<ReturnType, Function, Type1, char>(data, data2, std::forward<Function>(f));
793 }
794 }
795}
796
797
806template <class ReturnType, class Function>
807ReturnType pressio_data_for_each(pressio_data const& data, pressio_data const& data2, Function&& f)
808{
809 switch(data.dtype()) {
811 return pressio_data_for_each_type2_switch<ReturnType, Function, double>(data, data2, std::forward<Function>(f));
813 return pressio_data_for_each_type2_switch<ReturnType, Function, float>(data, data2, std::forward<Function>(f));
815 return pressio_data_for_each_type2_switch<ReturnType, Function, uint8_t>(data, data2, std::forward<Function>(f));
817 return pressio_data_for_each_type2_switch<ReturnType, Function, uint16_t>(data, data2, std::forward<Function>(f));
819 return pressio_data_for_each_type2_switch<ReturnType, Function, uint32_t>(data, data2, std::forward<Function>(f));
821 return pressio_data_for_each_type2_switch<ReturnType, Function, uint64_t>(data, data2, std::forward<Function>(f));
823 return pressio_data_for_each_type2_switch<ReturnType, Function, int8_t>(data, data2, std::forward<Function>(f));
825 return pressio_data_for_each_type2_switch<ReturnType, Function, int16_t>(data, data2, std::forward<Function>(f));
827 return pressio_data_for_each_type2_switch<ReturnType, Function, int32_t>(data, data2, std::forward<Function>(f));
829 return pressio_data_for_each_type2_switch<ReturnType, Function, int64_t>(data, data2, std::forward<Function>(f));
830 default:
831 return pressio_data_for_each_type2_switch<ReturnType, Function, char>(data, data2, std::forward<Function>(f));
832 }
833}
842template <class ReturnType, class Function>
843ReturnType pressio_data_for_each(pressio_data& data, pressio_data& data2, Function&& f)
844{
845 switch(data.dtype()) {
847 return pressio_data_for_each_type2_switch<ReturnType, Function, double>(data, data2, std::forward<Function>(f));
849 return pressio_data_for_each_type2_switch<ReturnType, Function, float>(data, data2, std::forward<Function>(f));
851 return pressio_data_for_each_type2_switch<ReturnType, Function, uint8_t>(data, data2, std::forward<Function>(f));
853 return pressio_data_for_each_type2_switch<ReturnType, Function, uint16_t>(data, data2, std::forward<Function>(f));
855 return pressio_data_for_each_type2_switch<ReturnType, Function, uint32_t>(data, data2, std::forward<Function>(f));
857 return pressio_data_for_each_type2_switch<ReturnType, Function, uint64_t>(data, data2, std::forward<Function>(f));
859 return pressio_data_for_each_type2_switch<ReturnType, Function, int8_t>(data, data2, std::forward<Function>(f));
861 return pressio_data_for_each_type2_switch<ReturnType, Function, int16_t>(data, data2, std::forward<Function>(f));
863 return pressio_data_for_each_type2_switch<ReturnType, Function, int32_t>(data, data2, std::forward<Function>(f));
865 return pressio_data_for_each_type2_switch<ReturnType, Function, int64_t>(data, data2, std::forward<Function>(f));
866 default:
867 return pressio_data_for_each_type2_switch<ReturnType, Function, char>(data, data2, std::forward<Function>(f));
868 }
869}
870
871#endif /* end of include guard: PRESSIO_DATA_CPP_H */
size_t data_size_in_bytes(pressio_dtype type, size_t const dimensions, size_t const dims[])
pressio_data_delete_fn pressio_new_free_fn()
Definition: data.h:26
ReturnType pressio_data_for_each(pressio_data const &data, Function &&f)
Definition: data.h:589
size_t data_size_in_elements(size_t dimensions, size_t const dims[])
C++ interface to data types.
constexpr pressio_dtype pressio_dtype_from_type()
Definition: dtype.h:42
an abstraction for a contagious memory region of a specified type
void pressio_data_libc_free_fn(void *data, void *metadata)
void(* pressio_data_delete_fn)(void *data, void *metadata)
Definition: pressio_data.h:26
pressio_dtype
Definition: pressio_dtype.h:16
@ pressio_byte_dtype
Definition: pressio_dtype.h:27
@ pressio_double_dtype
Definition: pressio_dtype.h:17
@ pressio_int16_dtype
Definition: pressio_dtype.h:24
@ pressio_uint64_dtype
Definition: pressio_dtype.h:22
@ pressio_float_dtype
Definition: pressio_dtype.h:18
@ pressio_uint16_dtype
Definition: pressio_dtype.h:20
@ pressio_int64_dtype
Definition: pressio_dtype.h:26
@ pressio_int8_dtype
Definition: pressio_dtype.h:23
@ pressio_uint8_dtype
Definition: pressio_dtype.h:19
@ pressio_uint32_dtype
Definition: pressio_dtype.h:21
@ pressio_int32_dtype
Definition: pressio_dtype.h:25
int pressio_dtype_size(enum pressio_dtype dtype)
Definition: data.h:52
static pressio_data nonowning(const pressio_dtype dtype, void *data, size_t const num_dimensions, size_t const dimensions[])
Definition: data.h:138
static pressio_data nonowning(const pressio_dtype dtype, void *data, std::vector< size_t > const &dimensions)
Definition: data.h:74
static pressio_data owning(const pressio_dtype dtype, std::vector< size_t > const &dimensions)
Definition: data.h:93
std::vector< T > to_vector() const
Definition: data.h:484
void * data() const
Definition: data.h:327
static pressio_data clone(pressio_data const &src)
Definition: data.h:209
size_t capacity_in_bytes() const
Definition: data.h:425
static pressio_data move(const pressio_dtype dtype, void *data, size_t const num_dimensions, size_t const dimensions[], pressio_data_delete_fn deleter, void *metadata)
Definition: data.h:191
pressio_data(pressio_data &&rhs) noexcept
Definition: data.h:280
bool has_data() const
Definition: data.h:334
int reshape(std::vector< size_t > const &new_dimensions)
Definition: data.h:463
pressio_dtype dtype() const
Definition: data.h:341
static pressio_data empty(const pressio_dtype dtype, std::vector< size_t > const &dimensions)
Definition: data.h:62
pressio_data transpose(std::vector< size_t > const &axis={}) const
size_t num_dimensions() const
Definition: data.h:360
size_t size_in_bytes() const
Definition: data.h:418
bool operator==(pressio_data const &rhs) const
size_t num_elements() const
Definition: data.h:432
pressio_data(ForwardIt begin, ForwardIt end)
Definition: data.h:500
void set_dtype(pressio_dtype dtype)
Definition: data.h:348
size_t set_dimensions(std::vector< size_t > &&dims)
Definition: data.h:386
std::vector< size_t > normalized_dims(compat::optional< size_t > n={}, size_t fill=0) const
pressio_data(pressio_data const &rhs)
Definition: data.h:262
std::vector< size_t > const & dimensions() const
Definition: data.h:367
pressio_data cast(pressio_dtype dtype) const
static pressio_data empty(const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[])
Definition: data.h:124
size_t get_dimension(size_t idx) const
Definition: data.h:410
static pressio_data copy(const enum pressio_dtype dtype, const void *src, std::vector< size_t > const &dimensions)
Definition: data.h:82
pressio_data(std::initializer_list< T > il)
Definition: data.h:313
pressio_data & operator=(pressio_data const &rhs)
Definition: data.h:242
static pressio_data move(const pressio_dtype dtype, void *data, std::vector< size_t > const &dimensions, pressio_data_delete_fn deleter, void *metadata)
Definition: data.h:107
pressio_data & operator=(pressio_data &&rhs) noexcept
Definition: data.h:295
pressio_data select(std::vector< size_t > const &start={}, std::vector< size_t > const &stride={}, std::vector< size_t > const &count={}, std::vector< size_t > const &block={}) const
static pressio_data owning(const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[])
Definition: data.h:171
static pressio_data copy(const enum pressio_dtype dtype, const void *src, size_t const num_dimensions, size_t const dimensions[])
Definition: data.h:152