pytensor

template<class T, std::size_t N, layout_type L>
class pytensor : public xt::pycontainer<pytensor<T, N, L>>, public xcontainer_semantic<pytensor<T, N, L>>

Multidimensional container providing the xtensor container semantics wrapping a numpy array.

pytensor is similar to the xtensor container in that it has a static dimensionality.

Unlike the pyarray container, pytensor cannot be reshaped with a different number of dimensions and reshapes are not reflected on the Python side. However, pytensor has benefits compared to pyarray in terms of performances. pytensor shapes are stack-allocated which makes iteration upon pytensor faster than with pyarray.

See also

pyarray

Template Parameters:

T – The type of the element stored in the pyarray.

Constructors

inline pytensor()

Allocates an uninitialized pytensor that holds 1 element.

inline pytensor(nested_initializer_list_t<T, N> t)

Allocates a pytensor with a nested initializer list.

inline explicit pytensor(const shape_type &shape, layout_type l = layout_type::row_major)

Allocates an uninitialized pytensor with the specified shape and layout.

Parameters:
  • shape – the shape of the pytensor

  • l – the layout_type of the pytensor

inline explicit pytensor(const shape_type &shape, const_reference value, layout_type l = layout_type::row_major)

Allocates a pytensor with the specified shape and layout.

Elements are initialized to the specified value.

Parameters:
  • shape – the shape of the pytensor

  • value – the value of the elements

  • l – the layout_type of the pytensor

inline explicit pytensor(const shape_type &shape, const strides_type &strides, const_reference value)

Allocates an uninitialized pytensor with the specified shape and strides.

Elements are initialized to the specified value.

Parameters:
  • shape – the shape of the pytensor

  • strides – the strides of the pytensor

  • value – the value of the elements

inline explicit pytensor(const shape_type &shape, const strides_type &strides)

Allocates an uninitialized pytensor with the specified shape and strides.

Parameters:
  • shape – the shape of the pytensor

  • strides – the strides of the pytensor

template<class S>
inline pytensor<T, N, L> from_shape(S &&shape)

Allocates and returns an pytensor with the specified shape.

Parameters:

shape – the shape of the pytensor

Copy semantic

inline pytensor(const self_type &rhs)

The copy constructor.

inline self_type &operator=(const self_type &rhs)

The assignment operator.

Extended copy semantic

template<class E>
inline pytensor(const xexpression<E> &e)

The extended copy constructor.

template<class E>
inline auto operator=(const xexpression<E> &e) -> self_type&

The extended assignment operator.