# Data types

## shape

struct migraphx::internal::shape

  Public Types

  enum type_t

    Values:

    enumerator bool_type
    enumerator half_type
    enumerator float_type
    enumerator double_type
    enumerator uint8_type
    enumerator int8_type
    enumerator uint16_type
    enumerator int16_type
    enumerator int32_type
    enumerator int64_type
    enumerator uint32_type
    enumerator uint64_type
    enumerator tuple_type

  Public Functions

  shape()
  shape( type_t t)
  shape( type_t t, std::vector<std::size_t> l)
  shape( type_t t, std::vector<std::size_t> l, std::vector<std::size_t> s)
  template<class Range>
  inline shape( type_t t, const Range &l)
  template<class Range1, class Range2>
  inline shape( type_t t, const Range1 &l, const Range2 &s)
  shape(const std::vector< shape > &subs)
  type_t type() const
  const std::vector<std::size_t> &lens() const
  const std::vector<std::size_t> &strides() const
  std::size_t elements() const
  std::size_t bytes() const
  std::size_t type_size() const
  std::size_t index(std::initializer_list<std::size_t> l) const

    Map multiple indices to space index.

  std::size_t index(const std::vector<std::size_t> &l) const

    Map multiple indices to space index.

  template<class Iterator>
  inline std::size_t index( Iterator start, Iterator last) const

    Map multiple indices from a range of iterator to a space index.

  std::size_t index(std::size_t i) const

    Map element index to space index.

  std::vector<std::size_t> multi(std::size_t i) const
  void multi_copy(std::size_t i, std::size_t *start, const std::size_t *end) const
  bool packed() const

    Returns true if the shape is packed with no padding.

  bool transposed() const

    Returns true is the shape has been transposed. That is the strides are not in descending order

  bool broadcasted() const

    Returns true if the shape is broadcasting a dimension. That is, one of the strides are zero.

  bool standard() const

    Returns true if the shape is in its standard format. That is, the shape is both packed and not transposed.

  bool scalar() const

    Returns true if all strides are equal to 0 (scalar tensor)

  shape normalize_standard() const
  shape with_lens( type_t t, const std::vector<std::size_t> &l) const
  shape with_lens(const std::vector<std::size_t> &l) const
  template<class ...Visitors>
  inline void visit_type( Visitors ... vs) const
  std::string type_string() const
  const std::vector< shape > &sub_shapes() const

  Public Static Functions

  static const std::vector< type_t > &types()
  static std::string name( type_t t)
  static std::string cpp_type( type_t t)
  static shape from_permutation( type_t t, const std::vector<std::size_t> &l, const std::vector<int64_t> &perm)
  template<class Visitor, class TupleVisitor>
  static inline void visit( type_t t, Visitor v, TupleVisitor tv)
  template<class Visitor>
  static inline void visit( type_t t, Visitor v)
  template<class Visitor>
  static inline void visit_types( Visitor v)
  static type_t parse_type(const std::string &s)

  Friends

  friend friend bool operator== (const shape &x, const shape &y)
  friend friend bool operator!= (const shape &x, const shape &y)
  friend friend std::ostream & operator<< (std::ostream &os, const shape &x)
  template<class T>
  struct as

    Public Types

    using type = std::conditional_t<std::is_same< T , bool>{}, int8_t, T >

    Public Functions

    inline type max() const
    inline type min() const
    template<class U>
    inline type operator()( U u) const
    template<class U>
    inline type *operator()( U *u) const
    template<class U>
    inline const type *operator()(const U *u) const
    inline type operator()() const
    inline std::size_t size(std::size_t n = 1) const
    template<class U>
    inline type *from( U *buffer, std::size_t n = 0) const
    template<class U>
    inline const type *from(const U *buffer, std::size_t n = 0) const
    inline type_t type_enum() const
  template<class T, class = void>
  struct get_type
  template<class T>
  struct get_type<bool, T > : public std::integral_constant< type_t , bool_type >
  template<class T>
  struct get_type<const T > : public migraphx::internal:: shape :: get_type < T >
  template<class T>
  struct get_type<double, T > : public std::integral_constant< type_t , double_type >
  template<class T>
  struct get_type<float, T > : public std::integral_constant< type_t , float_type >
  template<class T>
  struct get_type<half, T > : public std::integral_constant< type_t , half_type >
  template<class T>
  struct get_type<int16_t, T > : public std::integral_constant< type_t , int16_type >
  template<class T>
  struct get_type<int32_t, T > : public std::integral_constant< type_t , int32_type >
  template<class T>
  struct get_type<int64_t, T > : public std::integral_constant< type_t , int64_type >
  template<class T>
  struct get_type<int8_t, T > : public std::integral_constant< type_t , int8_type >
  template<class T>
  struct get_type<uint16_t, T > : public std::integral_constant< type_t , uint16_type >
  template<class T>
  struct get_type<uint32_t, T > : public std::integral_constant< type_t , uint32_type >
  template<class T>
  struct get_type<uint64_t, T > : public std::integral_constant< type_t , uint64_type >
  template<class T>
  struct get_type<uint8_t, T > : public std::integral_constant< type_t , uint8_type >

## literal

struct migraphx::internal::literal : public migraphx::internal:: raw_data < literal >

  Represents a raw literal.

  This stores the literal has a raw buffer that is owned by this class

  Public Functions

  inline literal()
  template<class U, class T = deduce< U >, shape :: type_t ShapeType = shape :: get_type < T >{}>
  inline literal( U x)
  template<class T>
  inline literal(const shape &s, const std::vector< T > &x)
  template<class T>
  inline literal(const shape &s, const std::initializer_list< T > &x)
  template<class Iterator>
  inline literal(const shape &s, Iterator start, Iterator end)
  template<class T, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<( PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<sizeof( T ) == 1>{})), int>::type = 0>
  inline literal(const shape &s, T *x)
  inline bool empty() const

    Whether data is available.

  inline const char *data() const

    Provides a raw pointer to the data.

  inline const shape &get_shape() const
  inline std::vector< literal > get_sub_objects() const
  inline argument get_argument() const

    Convert the data to an argument.

## argument

struct migraphx::internal::argument : public migraphx::internal:: raw_data < argument >

  Arguments passed to instructions.

  An `argument` can represent a raw buffer of data that either be referenced from another element or it can be owned by the argument.

  Public Functions

  argument() = default
  argument(const shape &s)
  template<class F, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<( PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<std::is_pointer<decltype(std::declval< F >()())>{}>{})), int>::type = 0>
  inline argument( shape s, F d)
  template<class T>
  inline argument( shape s, T *d)
  template<class T>
  inline argument( shape s, std::shared_ptr< T > d)
  argument( shape s, std::nullptr_t)
  argument(const std::vector< argument > &args)
  char *data() const

    Provides a raw pointer to the data.

  bool empty() const

    Whether data is available.

  const shape &get_shape() const
  argument reshape(const shape &s) const
  argument copy() const
  argument share() const

    Make copy of the argument that is always sharing the data.

  std::vector< argument > get_sub_objects() const
  argument element(std::size_t i) const

    Return the ith element.

## raw_data

template<class Derived>
struct migraphx::internal::raw_data : public migraphx::internal::raw_data_base

  Provides a base class for common operations with raw buffer.

  For classes that handle a raw buffer of data, this will provide common operations such as equals, printing, and visitors. To use this class the derived class needs to provide a `data()` method to retrieve a raw pointer to the data, and `get_shape` method that provides the shape of the data.

  Public Functions

  template<class Visitor>
  inline void visit_at( Visitor v, std::size_t n = 0) const

    Visits a single data element at a certain index.

    Parameters

      - v – A function which will be called with the type of data

      - n – The index to read from

  template<class Visitor, class TupleVisitor>
  inline void visit( Visitor v, TupleVisitor tv) const
  template<class Visitor>
  inline void visit( Visitor v) const

    Visits the data.

    This will call the visitor function with a `tensor_view<T>` based on the shape of the data.

    Parameters

      v – A function to be called with `tensor_view<T>`

  inline bool single() const

    Returns true if the raw data is only one element.

  template<class T>
  inline T at(std::size_t n = 0) const

    Retrieves a single element of data.

    Parameters

      n – The index to retrieve the data from

    Template Parameters

      T – The type of data to be retrieved

    Returns

      The element as `T`

  inline auto_cast implicit() const

    Implicit conversion of raw data pointer.

  template<class T>
  inline tensor_view < T > get() const

    Get a tensor_view to the data.

  template<class T>
  inline T *cast() const

    Cast the data pointer.

  inline std::string to_string() const

  Friends

  template<class Stream> inline friend friend Stream & operator<< (Stream &os, const Derived &d)
  struct auto_cast

    Public Types

    using is_data_ptr = bool_c<(std::is_void<T>{} or std::is_same<char, std::remove_cv_t<T>>{} or std::is_same<unsigned char, std::remove_cv_t<T>>{})>
    using get_data_type = std::conditional_t< is_data_ptr <T>{}, float, T>

    Public Functions

    template<class T>
    inline operator T ()
    template<class T>
    inline bool matches() const
    template<class T>
    inline operator T *()

    Public Members

    const Derived *self

Warning

doxygenfunction: Unable to resolve function “migraphx::internal::visit_all” with arguments None in doxygen xml output for project “proj” from directory: /code/AMDMIGraphX/build/doc/doxygen/xml. Potential matches:

    - template<class T, class ...Ts> auto visit_all(T &&x, Ts&&... xs)
    - template<class T> auto visit_all(const std::vector<T> &x)

## tensor_view

template<class T>
struct migraphx::internal::tensor_view

  Public Types

  using value_type = T
  using iterator = basic_iota_iterator<tensor_view_iterator_read< tensor_view < T >>, std::size_t>
  using const_iterator = basic_iota_iterator<tensor_view_iterator_read<const tensor_view < T >>, std::size_t>

  Public Functions

  inline tensor_view()
  inline tensor_view( shape s, T *d)
  inline const shape &get_shape() const
  inline bool empty() const
  inline std::size_t size() const
  inline T *data()
  inline const T *data() const
  template<class ...Ts, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<( PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<std::is_integral< Ts >{}...>{})), int>::type = 0>
  inline const T &operator()( Ts ... xs) const
  template<class ...Ts, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<( PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<std::is_integral< Ts >{}...>{})), int>::type = 0>
  inline T &operator()( Ts ... xs)
  template<class Iterator, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<( PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<not std::is_integral< Iterator >{}>{})), int>::type = 0>
  inline const T &operator()( Iterator start, Iterator last) const
  template<class Iterator, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<( PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<not std::is_integral< Iterator >{}>{})), int>::type = 0>
  inline T &operator()( Iterator start, Iterator last)
  inline T &operator[](std::size_t i)
  inline const T &operator[](std::size_t i) const
  inline T &front()
  inline const T &front() const
  inline T &back()
  inline const T &back() const
  inline iterator begin()
  inline iterator end()
  inline const_iterator begin() const
  inline const_iterator end() const
  template<class U = T >
  inline std::vector< U > to_vector() const

  Friends

  inline friend friend std::ostream & operator<< (std::ostream &os, const tensor_view< T > &x)