-
#include "tensorstore/data_type.h"
- class tensorstore::DataType;
Run-time representation of a C++ type used as the element type for a multi-dimensional array.
This is a Regular type that is inexpensive to copy (equivalent to a pointer).
In generic code, StaticDataType can be used as a drop-in replacement when the type is known at compile time.
This permits array operations, such as allocation, zero initialization, copying/moving, printing to a string, and comparison to be performed on arrays whose element type is specified at compile time.
Except when allocating new memory, an
DataType
value is typically paired with avoid*
pointer to an element of the corresponding type (this pairing is implemented by the ElementPointer class).A
DataType
instance corresponding to a type known at compile time may be obtained usingdtype_v
.Constructors¶
- constexpr DataType();
Initializes to an invalid data type.
Methods¶
- constexpr bool valid() const;
Returns
true
if this represents a valid data type.
- constexpr std::string_view name() const;
Returns the data type name, e.g.
"bool"
or"uint32"
.
Friend functions¶
- friend constexpr bool operator==(DataType a, DataType b);
- friend constexpr bool operator!=(DataType a, DataType b);
-
friend constexpr bool
operator==(DataType r, const std::type_info& type); -
friend constexpr bool
operator!=(DataType r, const std::type_info& type); -
friend constexpr bool
operator==(const std::type_info& type, DataType r); -
friend constexpr bool
operator!=(const std::type_info& type, DataType r); Comparison operators.
- friend std::ostream& operator<<(std::ostream& os, DataType r);
Prints
name()
ifvalid() == true
, otherwise prints"<unspecified>"
.
Related Types¶
- using tensorstore::CanonicalElementType<T>;
Metafunction that maps an unqualified type
T
to the equivalent canonical element type, if there is one.
- enum class tensorstore::DataTypeConversionFlags;
Specifies traits for the conversion from one data type to another.
- enum class tensorstore::EqualityComparisonKind;
Specifies an equality comparison method.
- class tensorstore::StaticDataType<T>;
Empty/monostate type that represents a statically known element type.
-
using tensorstore::dtype_t<T> = std::conditional_t<
std::is_void_v<T>,
DataType,
StaticDataType<CanonicalElementType<std::remove_cv_t<T>>>>; Alias for the
StaticDataType
representingT
ifT
is notvoid
, orDataType
ifT
isvoid
.
Related Constants¶
-
constexpr bool tensorstore::IsElementType<T> =
(!std::is_volatile_v<T> && !std::is_reference_v<T> &&
!std::is_function_v<std::remove_const_t<T>> &&
!std::is_array_v<std::remove_const_t<T>>); An ElementType is any optionally
const
-qualified fundamental type (includingvoid
), pointer type, member pointer type, class/union type, or enumeration type. A type ofvoid
orconst void
indicates a type-erased element type.
- constexpr auto tensorstore::dtype_v<T> = dtype_t<T>();
Data type object representing the data type for
T
, convertible toDataType
.
-
constexpr bool tensorstore::
IsDataTypeConversionSupported<From, To, AdditionalFlags>; bool
-valued metafunction that specifies whether a conversion is allowed from a compile-time data type ofFrom
to a compile-time data type ofTo
.
Allocation¶
- enum class tensorstore::ElementInitialization;
Specifies the form of initialization to use when allocating an array.
-
void* tensorstore::AllocateAndConstruct(
ptrdiff_t n,
ElementInitialization initialization,
DataType r); Allocates and initializes a contiguous 1-dimensional array of
n
elements of typer
specified at run time.
- void tensorstore::DestroyAndFree(ptrdiff_t n, DataType r, void* ptr);
Frees memory allocated by AllocateAndConsruct.
-
std::shared_ptr<T> tensorstore::AllocateAndConstructShared(
ptrdiff_t n,
ElementInitialization initialization = default_init,
dtype_t<T> r = dtype_v<T>); Returns a shared_ptr that manages the memory returned by
AllocateAndConstruct
.
Related Functions¶
- bool tensorstore::IsPossiblySameDataType(DataType a, DataType b);
-
constexpr bool
tensorstore::IsPossiblySameDataType(StaticDataType<T> a,
StaticDataType<U> b); Checks if both data types are equal or at least one is unspecified.
- DataType tensorstore::GetDataType(std::string_view id);