libpressio 0.93.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
pressio_data Struct Reference

#include <data.h>

Public Member Functions

pressio_dataoperator= (pressio_data const &rhs)
 
 pressio_data (pressio_data const &rhs)
 
 pressio_data (pressio_data &&rhs) noexcept
 
pressio_dataoperator= (pressio_data &&rhs) noexcept
 
template<class T >
 pressio_data (std::initializer_list< T > il)
 
void * data () const
 
bool has_data () const
 
pressio_dtype dtype () const
 
void set_dtype (pressio_dtype dtype)
 
pressio_data cast (pressio_dtype dtype) const
 
size_t num_dimensions () const
 
std::vector< size_t > const & dimensions () const
 
std::vector< size_t > normalized_dims (compat::optional< size_t > n={}, size_t fill=0) const
 
size_t set_dimensions (std::vector< size_t > &&dims)
 
size_t get_dimension (size_t idx) const
 
size_t size_in_bytes () const
 
size_t capacity_in_bytes () const
 
size_t num_elements () const
 
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
 
int reshape (std::vector< size_t > const &new_dimensions)
 
template<class T >
std::vector< T > to_vector () const
 
template<class ForwardIt >
 pressio_data (ForwardIt begin, ForwardIt end)
 
pressio_data transpose (std::vector< size_t > const &axis={}) const
 
bool operator== (pressio_data const &rhs) const
 

Static Public Member Functions

static pressio_data empty (const pressio_dtype dtype, std::vector< size_t > const &dimensions)
 
static pressio_data nonowning (const pressio_dtype dtype, void *data, std::vector< size_t > const &dimensions)
 
static pressio_data copy (const enum pressio_dtype dtype, const void *src, std::vector< size_t > const &dimensions)
 
static pressio_data owning (const pressio_dtype dtype, std::vector< size_t > const &dimensions)
 
static pressio_data move (const pressio_dtype dtype, void *data, std::vector< size_t > const &dimensions, pressio_data_delete_fn deleter, void *metadata)
 
static pressio_data empty (const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[])
 
static pressio_data nonowning (const pressio_dtype dtype, void *data, size_t const num_dimensions, size_t const dimensions[])
 
static pressio_data copy (const enum pressio_dtype dtype, const void *src, size_t const num_dimensions, size_t const dimensions[])
 
static pressio_data owning (const pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[])
 
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)
 
static pressio_data clone (pressio_data const &src)
 

Detailed Description

represents a data buffer that may or may not be owned by the class

Constructor & Destructor Documentation

◆ pressio_data() [1/4]

pressio_data::pressio_data ( pressio_data const &  rhs)
inline

copy-constructor, clones the data

Parameters
[in]rhsthe data to clone
See also
pressio_data::clone

◆ pressio_data() [2/4]

pressio_data::pressio_data ( pressio_data &&  rhs)
inlinenoexcept

move-constructor

Parameters
[in]rhsthe data buffer to move from
Returns
a reference to the object moved into

◆ pressio_data() [3/4]

template<class T >
pressio_data::pressio_data ( std::initializer_list< T >  il)
inline

construct a literal pressio_data object from a initializer list

Parameters
[in]ilinitializer list to use to create the data object

◆ pressio_data() [4/4]

template<class ForwardIt >
pressio_data::pressio_data ( ForwardIt  begin,
ForwardIt  end 
)
inline

convert a iterable type into a pressio_data object

Parameters
[in]beginiterator to the beginning of the data
[in]enditerator to the end of the data
Returns
a new 1d pressio_data object or matching type

Member Function Documentation

◆ capacity_in_bytes()

size_t pressio_data::capacity_in_bytes ( ) const
inline
Returns
the capacity of the buffer in bytes

◆ cast()

pressio_data pressio_data::cast ( pressio_dtype  dtype) const
Parameters
[in]dtypethe new datatype to assign
Returns
a new pressio_data structure based on the current structure with the new type

◆ clone()

static pressio_data pressio_data::clone ( pressio_data const &  src)
inlinestatic

clones a existing data buffer

Does not use the copy constructor to enforce strict semantics around copies

Parameters
[in]srcthe object
Returns
a new data structure

◆ copy() [1/2]

static pressio_data pressio_data::copy ( const enum pressio_dtype  dtype,
const void *  src,
size_t const  num_dimensions,
size_t const  dimensions[] 
)
inlinestatic

creates a copy of a data buffer

Parameters
[in]dtypethe type of the buffer
[in]srcthe buffer to copy
[in]num_dimensionsthe number of entries in dimensions
[in]dimensionsthe dimensions of the data
Returns
an owning copy of the data object
See also
pressio_data_new_copy

◆ copy() [2/2]

static pressio_data pressio_data::copy ( const enum pressio_dtype  dtype,
const void *  src,
std::vector< size_t > const &  dimensions 
)
inlinestatic

creates a copy of a data buffer

Parameters
[in]dtypethe type of the buffer
[in]srcthe buffer to copy
[in]dimensionsthe dimensions of the buffer
Returns
an owning copy of the data object
See also
pressio_data_new_copy

◆ data()

void * pressio_data::data ( ) const
inline
Returns
a non-owning pointer to the data

◆ dimensions()

std::vector< size_t > const & pressio_data::dimensions ( ) const
inline
Returns
a copy of the vector of dimensions

◆ dtype()

pressio_dtype pressio_data::dtype ( ) const
inline
Returns
the data type of the buffer

◆ empty() [1/2]

static pressio_data pressio_data::empty ( const pressio_dtype  dtype,
size_t const  num_dimensions,
size_t const  dimensions[] 
)
inlinestatic

allocates a new empty data buffer

Parameters
[in]dtypethe type the buffer will contain
[in]num_dimensionsthe length of dimensions
[in]dimensionsthe dimensions of the expected buffer
Returns
an empty data object (i.e. has no data)
See also
pressio_data_new_empty

◆ empty() [2/2]

static pressio_data pressio_data::empty ( const pressio_dtype  dtype,
std::vector< size_t > const &  dimensions 
)
inlinestatic

allocates a new empty data buffer

Parameters
[in]dtypethe type the buffer will contain
[in]dimensionsthe dimensions of the expected buffer
Returns
an empty data object (i.e. has no data)
See also
pressio_data_new_empty

◆ get_dimension()

size_t pressio_data::get_dimension ( size_t  idx) const
inline
Parameters
idxthe specific index to query
Returns
a specific dimension of the buffer of zero if the index exceeds dimensions()

◆ has_data()

bool pressio_data::has_data ( ) const
inline
Returns
true if the structure has has data

◆ move() [1/2]

static pressio_data 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 
)
inlinestatic

takes ownership of an existing data buffer

Parameters
[in]dtypethe type of the buffer
[in]datathe buffer
[in]num_dimensionsthe number of entries in dimensions
[in]dimensionsthe dimensions of the data
[in]deleterthe method to call to free the buffer or null to not free the data
[in]metadatathe metadata passed to the deleter function
Returns
an owning data object with uninitialized memory
See also
pressio_data_new_move

◆ move() [2/2]

static pressio_data pressio_data::move ( const pressio_dtype  dtype,
void *  data,
std::vector< size_t > const &  dimensions,
pressio_data_delete_fn  deleter,
void *  metadata 
)
inlinestatic

takes ownership of an existing data buffer

Parameters
[in]dtypethe type of the buffer
[in]datathe buffer
[in]dimensionsthe dimensions of the buffer
[in]deleterthe method to call to free the buffer or null to not free the data
[in]metadatathe metadata passed to the deleter function
Returns
an owning data object with uninitialized memory
See also
pressio_data_new_move

◆ nonowning() [1/2]

static pressio_data pressio_data::nonowning ( const pressio_dtype  dtype,
void *  data,
size_t const  num_dimensions,
size_t const  dimensions[] 
)
inlinestatic

creates a non-owning reference to data

Parameters
[in]dtypethe type of the buffer
[in]datathe buffer
[in]num_dimensionsthe number of entries in dimensions
[in]dimensionsthe dimensions of the data
Returns
an non-owning data object (i.e. calling pressio_data_free will not deallocate this memory)
See also
pressio_data_new_nonowning

◆ nonowning() [2/2]

static pressio_data pressio_data::nonowning ( const pressio_dtype  dtype,
void *  data,
std::vector< size_t > const &  dimensions 
)
inlinestatic

creates a non-owning reference to data

Parameters
[in]dtypethe type of the buffer
[in]datathe buffer
[in]dimensionsthe dimensions of the buffer
Returns
an non-owning data object (i.e. calling pressio_data_free will not deallocate this memory)
See also
pressio_data_new_nonowning

◆ normalized_dims()

std::vector< size_t > pressio_data::normalized_dims ( compat::optional< size_t >  n = {},
size_t  fill = 0 
) const

returns the dimensions normalized to remove 1's

◆ num_dimensions()

size_t pressio_data::num_dimensions ( ) const
inline
Returns
the number of dimensions

◆ num_elements()

size_t pressio_data::num_elements ( ) const
inline
Returns
the size of the buffer in elements

◆ operator=() [1/2]

pressio_data & pressio_data::operator= ( pressio_data &&  rhs)
inlinenoexcept

move-assignment operator

Parameters
[in]rhsthe data buffer to move from
Returns
a l-value reference to the object moved into

◆ operator=() [2/2]

pressio_data & pressio_data::operator= ( pressio_data const &  rhs)
inline

copy-assignment, clones the data

Parameters
[in]rhsthe data to clone
See also
pressio_data::clone

◆ operator==()

bool pressio_data::operator== ( pressio_data const &  rhs) const
Parameters
[in]rhsthe object to compare against
Returns
true if the options are equal

◆ owning() [1/2]

static pressio_data pressio_data::owning ( const pressio_dtype  dtype,
size_t const  num_dimensions,
size_t const  dimensions[] 
)
inlinestatic

creates a copy of a data buffer

Parameters
[in]dtypethe type of the buffer
[in]num_dimensionsthe number of entries in dimensions
[in]dimensionsthe dimensions of the data
Returns
an owning data object with uninitialized memory
See also
pressio_data_new_owning

◆ owning() [2/2]

static pressio_data pressio_data::owning ( const pressio_dtype  dtype,
std::vector< size_t > const &  dimensions 
)
inlinestatic

creates a copy of a data buffer

Parameters
[in]dtypethe type of the buffer
[in]dimensionsthe dimensions of the buffer
Returns
an owning data object with uninitialized memory
See also
pressio_data_new_owning

◆ reshape()

int pressio_data::reshape ( std::vector< size_t > const &  new_dimensions)
inline

modifies the dimensions of this pressio_data structure in-place.

This API does not change the size of the underlying buffer. A future version of this API may change this.

Parameters
[in]new_dimensionsthe new dimensions to use
Returns
0 if the resize was successful, negative values on warnings (i.e. dimensions mismatch), positive values on errors

◆ select()

pressio_data 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

Copies a set of blocks of data from the data stream to a new pressio_data structure

Parameters
[in]startthe position in the array to start iterating, start[i]>=0
[in]stridethe number of blocks to skip in each direction, stride[i] >=1
[in]countthe number of blocks to copy, count[i] >= 1
[in]blockthe dimensions of the block to copy, block[i] >= 1
Returns
the copied blocks, or an empty structure if an error occurs

◆ set_dimensions()

size_t pressio_data::set_dimensions ( std::vector< size_t > &&  dims)
inline

changes the dimensions of the size of the memory if the resulting buffer is smaller than the current buffer capacity in bytes, nothing else is done if the resulting buffer is larger than the current buffer capacity in bytes, a realloc-like operation is performed

Parameters
[in]dimsthe new dimensions to use
Returns
the size of the new buffer in bytes, returns 0 if malloc fails

◆ set_dtype()

void pressio_data::set_dtype ( pressio_dtype  dtype)
inline
Parameters
[in]dtypethe data type for the buffer

◆ size_in_bytes()

size_t pressio_data::size_in_bytes ( ) const
inline
Returns
the size of the buffer in bytes

◆ to_vector()

template<class T >
std::vector< T > pressio_data::to_vector ( ) const
inline

convert a pressio_data structure into a 1d c++ standard vector. If the type doesn't match, it will be casted first

Returns
the vector containing the data
See also
pressio_data::cast

◆ transpose()

pressio_data pressio_data::transpose ( std::vector< size_t > const &  axis = {}) const

Permutes the dimensions of an array

Parameters
[in]axisby default reverses the axis, otherwise permutes the axes according to the dimensions
Returns
the data with its axes permuted

The documentation for this struct was generated from the following file: