libpressio 0.93.0
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
pressio_data.h File Reference

an abstraction for a contagious memory region of a specified type More...

#include <stddef.h>
#include <stdbool.h>
#include "pressio_dtype.h"
Include dependency graph for pressio_data.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* pressio_data_delete_fn) (void *data, void *metadata)
 

Functions

void pressio_data_libc_free_fn (void *data, void *metadata)
 
struct pressio_datapressio_data_new_nonowning (const enum pressio_dtype dtype, void *data, size_t const num_dimensions, size_t const dimensions[])
 
struct pressio_datapressio_data_new_clone (const struct pressio_data *src)
 
struct pressio_datapressio_data_new_copy (const enum pressio_dtype dtype, void *src, size_t const num_dimensions, size_t const dimensions[])
 
struct pressio_datapressio_data_new_owning (const enum pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[])
 
struct pressio_datapressio_data_new_empty (const enum pressio_dtype dtype, size_t const num_dimensions, size_t const dimensions[])
 
struct pressio_datapressio_data_new_move (const enum pressio_dtype dtype, void *data, size_t const num_dimensions, size_t const dimensions[], pressio_data_delete_fn deleter, void *metadata)
 
struct pressio_datapressio_data_cast (const struct pressio_data *data, const enum pressio_dtype dtype)
 
void pressio_data_free (struct pressio_data *data)
 
void * pressio_data_copy (struct pressio_data const *data, size_t *out_bytes)
 
void * pressio_data_ptr (struct pressio_data const *data, size_t *out_bytes)
 
struct pressio_datapressio_data_select (struct pressio_data const *data, const size_t *start, const size_t *stride, const size_t *count, const size_t *block)
 
struct pressio_datapressio_data_transpose (struct pressio_data const *data, const size_t *axis)
 
int pressio_data_reshape (struct pressio_data *data, size_t const num_dimensions, size_t const dimensions[])
 
enum pressio_dtype pressio_data_dtype (struct pressio_data const *data)
 
bool pressio_data_has_data (struct pressio_data const *data)
 
size_t pressio_data_num_dimensions (struct pressio_data const *data)
 
size_t pressio_data_get_dimension (struct pressio_data const *data, size_t const dimension)
 
size_t pressio_data_get_bytes (struct pressio_data const *data)
 
size_t pressio_data_get_capacity_in_bytes (struct pressio_data const *data)
 
size_t pressio_data_num_elements (struct pressio_data const *data)
 

Detailed Description

an abstraction for a contagious memory region of a specified type

Typedef Documentation

◆ pressio_data_delete_fn

typedef void(* pressio_data_delete_fn) (void *data, void *metadata)

signature for a custom deleter for pressio_data

Parameters
[in]datato be deallocated
[in]metadatametadata passed to pressio_data_new_move, if allocated, it too should be freed
See also
pressio_data_new_move

Function Documentation

◆ pressio_data_cast()

struct pressio_data * pressio_data_cast ( const struct pressio_data data,
const enum pressio_dtype  dtype 
)

Creates a data buffer with the specified type from an existing buffer

Parameters
[in]datathe data to cast
[in]dtypethe datatype to cast to
Returns
a new owning data structure with data corresponding to each element casted to the appropriate type

◆ pressio_data_copy()

void * pressio_data_copy ( struct pressio_data const *  data,
size_t *  out_bytes 
)

allocates a buffer and then copies the underlying memory to the new buffer

Parameters
[in]datathe pressio data to copy from
[out]out_bytesthe number of bytes that were copied

◆ pressio_data_dtype()

enum pressio_dtype pressio_data_dtype ( struct pressio_data const *  data)
Parameters
[in]datathe pressio data to query
Returns
an integer code corresponding to the data-type

◆ pressio_data_free()

void pressio_data_free ( struct pressio_data data)

frees a pressio_data structure, but not the underlying data

Parameters
[in]datadata structure to free

◆ pressio_data_get_bytes()

size_t pressio_data_get_bytes ( struct pressio_data const *  data)

returns the number of bytes to represent the data

Parameters
[in]datathe pressio data to query
Returns
the number of bytes to represent the data

◆ pressio_data_get_capacity_in_bytes()

size_t pressio_data_get_capacity_in_bytes ( struct pressio_data const *  data)

returns the number of bytes of capacity

Parameters
[in]datathe pressio data to query
Returns
the number of bytes to represent the data

◆ pressio_data_get_dimension()

size_t pressio_data_get_dimension ( struct pressio_data const *  data,
size_t const  dimension 
)

returns the value of a given dimension.

Parameters
[in]datathe pressio data to query
[in]dimensionzero indexed dimension
Returns
the dimension or 0 If the dimension requested exceeds num_dimensions

◆ pressio_data_has_data()

bool pressio_data_has_data ( struct pressio_data const *  data)
Parameters
[in]datathe pressio data to query
Returns
an integer code corresponding to the data-type

◆ pressio_data_libc_free_fn()

void pressio_data_libc_free_fn ( void *  data,
void *  metadata 
)

a custom deleter that uses libc's free and ignores the metadata

Parameters
[in]datato be deallocated with free()
[in]metadataignored

◆ pressio_data_new_clone()

struct pressio_data * pressio_data_new_clone ( const struct pressio_data src)

allocates a new pressio_data structure and corresponding data and copies data from provided data structure

Parameters
[in]srcthe pressio_data structure to be cloned
Returns
the newly allocated copy

◆ pressio_data_new_copy()

struct pressio_data * pressio_data_new_copy ( const enum pressio_dtype  dtype,
void *  src,
size_t const  num_dimensions,
size_t const  dimensions[] 
)

allocates a new pressio_data structure and corresponding data and copies data in from the specified source use this function when the underlying data pointer may be deleted

Parameters
[in]dtypetype of the data stored by the pointer
[in]srcthe data to be copied into the data structure
[in]num_dimensionsthe number of dimensions; must match the length of dimensions
[in]dimensionsan array corresponding to the dimensions of the data, a copy is made of this on construction

◆ pressio_data_new_empty()

struct pressio_data * pressio_data_new_empty ( const enum pressio_dtype  dtype,
size_t const  num_dimensions,
size_t const  dimensions[] 
)

allocates a new pressio_data without data.

Parameters
[in]dtypetype of the data stored by the pointer
[in]num_dimensionsthe number of dimensions; must match the length of dimensions
[in]dimensionsan array corresponding to the dimensions of the data, a copy is made of this on construction
See also
pressio_compressor_compress to provide output buffer meta data.
pressio_compressor_decompress to provide output buffer meta data.

◆ pressio_data_new_move()

struct pressio_data * pressio_data_new_move ( const enum pressio_dtype  dtype,
void *  data,
size_t const  num_dimensions,
size_t const  dimensions[],
pressio_data_delete_fn  deleter,
void *  metadata 
)

allocates a new pressio_data structure using data that was already allocated. data referenced by this structure will be deallocated using the function deleter when the pressio_data structure is freed.

Parameters
[in]dtypethe type of the data to store
[in]datathe pointer to be "moved" into the pressio_data structure
[in]num_dimensionsthe number of dimensions; must match the length of dimensions
[in]dimensionsan array corresponding to the dimensions of the data, a copy is made of this on construction
[in]deleterthe function to be called when pressio_data_free is called on this structure
[in]metadatapassed to the deleter function when pressio_data_free is called, it may be null if unneeded

◆ pressio_data_new_nonowning()

struct pressio_data * pressio_data_new_nonowning ( const enum pressio_dtype  dtype,
void *  data,
size_t const  num_dimensions,
size_t const  dimensions[] 
)

allocates a new pressio_data structure, it does NOT take ownership of data.

Parameters
[in]dtypetype of the data stored by the pointer
[in]datathe actual data to be represented
[in]num_dimensionsthe number of dimensions; must match the length of dimensions
[in]dimensionsan array corresponding to the dimensions of the data, a copy is made of this on construction

◆ pressio_data_new_owning()

struct pressio_data * pressio_data_new_owning ( const enum pressio_dtype  dtype,
size_t const  num_dimensions,
size_t const  dimensions[] 
)

allocates a new pressio_data structure and corresponding data. The corresponding data is uninitialized

Parameters
[in]dtypetype of the data stored by the pointer
[in]num_dimensionsthe number of dimensions; must match the length of dimensions
[in]dimensionsan array corresponding to the dimensions of the data, a copy is made of this on construction
See also
pressio_data_ptr to access the allocated data

◆ pressio_data_num_dimensions()

size_t pressio_data_num_dimensions ( struct pressio_data const *  data)
Parameters
[in]datathe pressio data to query
Returns
the number of dimensions contained in the object

◆ pressio_data_num_elements()

size_t pressio_data_num_elements ( struct pressio_data const *  data)

returns the total number of elements to represent the data

Parameters
[in]datathe pressio data to query
Returns
the total number of elements to represent the data

◆ pressio_data_ptr()

void * pressio_data_ptr ( struct pressio_data const *  data,
size_t *  out_bytes 
)

non-owning access to the first element of the raw data

Parameters
[in]datathe pressio data to query
[out]out_bytesthe number of bytes that follow this pointer (ignored if NULL is passed)
Returns
a non-owning type-pruned pointer to the first element of the raw data
See also
pressio_data_dtype to get the data-type

◆ pressio_data_reshape()

int pressio_data_reshape ( struct pressio_data data,
size_t const  num_dimensions,
size_t const  dimensions[] 
)

modifies the dimensions of a pressio_data structure inplace.

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

Parameters
[in]datathe data structure to modify
[in]num_dimensionsthe size of the new dimensions
[in]dimensionsthe new dimensions to use
Returns
0 if the resize was successful, negative values on warnings (i.e. dimensions mismatch), positive values on errors

◆ pressio_data_select()

struct pressio_data * pressio_data_select ( struct pressio_data const *  data,
const size_t *  start,
const size_t *  stride,
const size_t *  count,
const size_t *  block 
)

Copies a possibly strided subset of from the data pointer

Parameters
[in]datathe data to copy from
[in]startthe coordinate to start at; must have the same dimension as data or null. if null is chosen the zero vector of size N is used.
[in]stridehow many elements from the first element in each block to skip in each directions before the next block if null is chosen the one vector of size N is used.
[in]counthow many blocks to copy in each direction. if null is chosen the one vector of size N is used.
[in]blockthe dimentions of each block to copy if null is chosen the one vector of size N is used.
Returns
a new pressio data structure containing a copy of the memory described if an error occurs, an new empty structure is returned instead.

◆ pressio_data_transpose()

struct pressio_data * pressio_data_transpose ( struct pressio_data const *  data,
const size_t *  axis 
)

Transposes a data-buffer

Parameters
[in]datathe data to copy from
[in]axisthe order of the dimensions if null is chosen the dimensions are reversed
Returns
a new pressio data structure containing a transposed copy if an error occurs, an new empty structure is returned instead.