asdf/core/datatype.h - ndarray datatypes

Implementation of the core/datatype-1.0.0 schema

Types

enum asdf_scalar_datatype_t

Enum for basic ndarray scalar datatypes

The special datatype ASDF_DATATYPE_STRUCTURED is reserved for the case where the datatype is a structured record (not yet supported beyond setting this datatype).

See asdf_datatype_t which represents a full datatype (including compound/structured datatypes).

This should not be confused with asdf_value_t which are the scalar value types supported for YAML tree values.

enumerator ASDF_DATATYPE_UNKNOWN = 0

Reserved for invalid/unsupported datatypes

enumerator ASDF_DATATYPE_INT8

Signed 8-bit integer

enumerator ASDF_DATATYPE_UINT8

Unsigned 8-bit integer

enumerator ASDF_DATATYPE_INT16

Signed 16-bit integer

enumerator ASDF_DATATYPE_UINT16

Unsigned 16-bit integer

enumerator ASDF_DATATYPE_INT32

Signed 32-bit integer

enumerator ASDF_DATATYPE_UINT32

Unsigned 32-bit integer

enumerator ASDF_DATATYPE_INT64

Signed 64-bit integer

enumerator ASDF_DATATYPE_UINT64

Unsigned 64-bit integer

enumerator ASDF_DATATYPE_FLOAT16

16-bit IEEE float (dependent on compiler support)

enumerator ASDF_DATATYPE_FLOAT32

32-bit IEEE float

enumerator ASDF_DATATYPE_FLOAT64

64-bit IEEE float

enumerator ASDF_DATATYPE_COMPLEX64

64-bit complex (pair of 32-bit floats; not yet fully supported)

enumerator ASDF_DATATYPE_COMPLEX128

128-bit complex (pair of 64-bit floats; not yet fully supported)

enumerator ASDF_DATATYPE_BOOL8

8-bit boolean

enumerator ASDF_DATATYPE_ASCII

ASCII text datatype

enumerator ASDF_DATATYPE_UCS4

UCS4 Unicode datatype

When using this datatype in asdf_datatype_t make sure to set the .size field to 4 * the string field length in characters.

enumerator ASDF_DATATYPE_STRUCTURED

Indicates that a datatype is non-scalar / is a compound-type/structured array

ASDF_DATATYPE_SOURCE

Alias for ASDF_DATATYPE_UNKNOWN

This is used primarily in the asdf_ndarray_read_tile_ndim family of functions indicating that the destination data type is the same as the source datatype. This alias is clearer in intent than ASDF_DATATYPE_UNKNOWN in this context.

enum asdf_byteorder_t

Struct representing the byte order/endianness of elements in an ndarray or field in a structured datatype

enumerator ASDF_BYTEORDER_INVALID = -1

Sentinel value for an invalid byte order

enumerator ASDF_BYTEORDER_DEFAULT = 0

Sentinel value for user-defined datatypes indicating that the byteorder should not be explicitly written (just use the default)

enumerator ASDF_BYTEORDER_BIG = 62

Big-endian

enumerator ASDF_BYTEORDER_LITTLE = 60

Little-endian

type asdf_datatype_t

Struct representing an ndarray datatype

String conversion

asdf_scalar_datatype_t asdf_scalar_datatype_from_string(const char *dtype)

Parse an ASDF scalar datatype and return the corresponding asdf_scalar_datatype_t

Parameters:
  • dtype – Null-terminated string

Returns:

The corresponding asdf_scalar_datatype_t or ASDF_DATATYPE_UNKNOWN

Note

Resists the urge to name this asdf_ndarray_serialize_datatype as in the long term this will be used to serialize a datatype back to YAML, and will need to also support compound datatypes.

This just provides the string representations for the common scalar datatypes.

const char *asdf_scalar_datatype_to_string(asdf_scalar_datatype_t datatype)

Convert an asdf_scalar_datatype_t to its string representation

Parameters:
Returns:

The string representation of the scalar datatype

Note

Resists the urge to name this asdf_ndarray_serialize_datatype as in the long term this will be used to serialize a datatype back to YAML, and will need to also support compound datatypes.

This just provides the string representations for the common scalar datatypes.

Datatype sizes

uint64_t asdf_datatype_size(asdf_datatype_t *datatype)

Get the size of an asdf_datatype_t in bytes

This is equivalent to looking up the public field asdf_datatype_t.size. However, the difference is that for user-defined datatypes it is not required to set the size explicitly–in that case this computes, sets, and returns asdf_datatype_t.size.

The exception is that for string datatypes (ASDF_DATATYPE_ASCII and ASDF_DATATYPE_UCS4) the user must provide the correct size, and a size of 0 is taken to mean “0-length string”.

Parameters:
Returns:

The size in bytes of the datatype

static inline size_t asdf_scalar_datatype_size(asdf_scalar_datatype_t type)

Get the size in bytes of a scalar (numeric) ndarray element for a given asdf_scalar_datatype_t

Parameters:
Returns:

Size in bytes of a single element of that datatype, or -1 for non-scalar datatypes (for the present purposes strings are not considered scalars, only numeric datatypes)