xbuilder

Defined in xtensor/xbuilder.hpp

template<class T, class S>
auto xt::ones(S shape)

Returns an xexpression containing ones of the specified shape.

Template Parameters
  • shape: the shape of the returned expression.

template<class T, class I, std::size_t L>
auto xt::ones(const I (&shape)[L])
template<class T, class S>
auto xt::zeros(S shape)

Returns an xexpression containing zeros of the specified shape.

Template Parameters
  • shape: the shape of the returned expression.

template<class T, class I, std::size_t L>
auto xt::zeros(const I (&shape)[L])
template<class T, layout_type L = xt::layout_type::row_major, class S>
xarray<T, L> xt::empty(const S &shape)

Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of with value_type T and shape.

Selects the best container match automatically from the supplied shape.

  • std::vectorxarray<T>

  • std::array or initializer_listxtensor<T, N>

  • xshape<N...>xtensor_fixed<T, xshape<N...>>

Parameters
  • shape: shape of the new xcontainer

template<class E>
auto xt::full_like(const xexpression<E> &e, typename E::value_type fill_value)

Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with fill_value and of the same shape, value type and layout as the input xexpression e.

Parameters
  • e: the xexpression from which to extract shape, value type and layout.

  • fill_value: the value used to set each element of the returned xcontainer.

template<class E>
auto xt::empty_like(const xexpression<E> &e)

Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of the same shape, value type and layout as the input xexpression e.

Parameters
  • e: the xexpression from which to extract shape, value type and layout.

template<class E>
auto xt::zeros_like(const xexpression<E> &e)

Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with zeros and of the same shape, value type and layout as the input xexpression e.

Note: contrary to zeros(shape), this function returns a non-lazy, allocated container! Use `xt::zeros<double>(e.shape()); for a lazy version.

Parameters
  • e: the xexpression from which to extract shape, value type and layout.

template<class E>
auto xt::ones_like(const xexpression<E> &e)

Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with ones and of the same shape, value type and layout as the input xexpression e.

Note: contrary to ones(shape), this function returns a non-lazy, evaluated container! Use xt::ones<double>(e.shape()); for a lazy version.

Parameters
  • e: the xexpression from which to extract shape, value type and layout.

template<class T = bool>
auto xt::eye(const std::vector<std::size_t> &shape, int k = 0)

Generates an array with ones on the diagonal.

Return

xgenerator that generates the values on access

Parameters
  • shape: shape of the resulting expression

  • k: index of the diagonal. 0 (default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.

Template Parameters
  • T: value_type of xexpression

template<class T = bool>
auto xt::eye(std::size_t n, int k = 0)

Generates a (n x n) array with ones on the diagonal.

Return

xgenerator that generates the values on access

Parameters
  • n: length of the diagonal.

  • k: index of the diagonal. 0 (default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.

Template Parameters
  • T: value_type of xexpression

template<class T, class S = T>
auto xt::arange(T start, T stop, S step = 1)

Generates numbers evenly spaced within given half-open interval [start, stop).

Return

xgenerator that generates the values on access

Parameters
  • start: start of the interval

  • stop: stop of the interval

  • step: stepsize

Template Parameters
  • T: value_type of xexpression

template<class T>
auto xt::arange(T stop)

Generate numbers evenly spaced within given half-open interval [0, stop) with a step size of 1.

Return

xgenerator that generates the values on access

Parameters
  • stop: stop of the interval

Template Parameters
  • T: value_type of xexpression

template<class T>
auto xt::linspace(T start, T stop, std::size_t num_samples = 50, bool endpoint = true)

Generates num_samples evenly spaced numbers over given interval.

Return

xgenerator that generates the values on access

Parameters
  • start: start of interval

  • stop: stop of interval

  • num_samples: number of samples (defaults to 50)

  • endpoint: if true, include endpoint (defaults to true)

Template Parameters
  • T: value_type of xexpression

template<class T>
auto xt::logspace(T start, T stop, std::size_t num_samples, T base = 10, bool endpoint = true)

Generates num_samples numbers evenly spaced on a log scale over given interval.

Return

xgenerator that generates the values on access

Parameters
  • start: start of interval (pow(base, start) is the first value).

  • stop: stop of interval (pow(base, stop) is the final value, except if endpoint = false)

  • num_samples: number of samples (defaults to 50)

  • base: the base of the log space.

  • endpoint: if true, include endpoint (defaults to true)

Template Parameters
  • T: value_type of xexpression

template<class ...CT>
auto xt::concatenate(std::tuple<CT...> &&t, std::size_t axis = 0)

Concatenates xexpressions along axis.

xt::xarray<double> a = {{1, 2, 3}};
xt::xarray<double> b = {{2, 3, 4}};
xt::xarray<double> c = xt::concatenate(xt::xtuple(a, b)); // => {{1, 2, 3},
                                                          //     {2, 3, 4}}
xt::xarray<double> d = xt::concatenate(xt::xtuple(a, b), 1); // => {{1, 2, 3, 2, 3, 4}}
Return

xgenerator evaluating to concatenated elements

Parameters
  • t: xtuple of xexpressions to concatenate

  • axis: axis along which elements are concatenated

template<class ...CT>
auto xt::stack(std::tuple<CT...> &&t, std::size_t axis = 0)

Stack xexpressions along axis.

Stacking always creates a new dimension along which elements are stacked.

xt::xarray<double> a = {1, 2, 3};
xt::xarray<double> b = {5, 6, 7};
xt::xarray<double> s = xt::stack(xt::xtuple(a, b)); // => {{1, 2, 3},
                                                    //     {5, 6, 7}}
xt::xarray<double> t = xt::stack(xt::xtuple(a, b), 1); // => {{1, 5},
                                                       //     {2, 6},
                                                       //     {3, 7}}
Return

xgenerator evaluating to stacked elements

Parameters
  • t: xtuple of xexpressions to concatenate

  • axis: axis along which elements are stacked

template<class ...CT>
auto xt::hstack(std::tuple<CT...> &&t)

Stack xexpressions in sequence horizontally (column wise).

This is equivalent to concatenation along the second axis, except for 1-D xexpressions where it concatenate along the firts axis.

Return

xgenerator evaluating to stacked elements

Parameters
  • t: xtuple of xexpressions to stack

template<class ...CT>
auto xt::vstack(std::tuple<CT...> &&t)

Stack xexpressions in sequence vertically (row wise).

This is equivalent to concatenation along the first axis after 1-D arrays of shape (N) have been reshape to (1, N).

Return

xgenerator evaluating to stacked elements

Parameters
  • t: xtuple of xexpressions to stack

template<class ...E>
auto xt::meshgrid(E&&... e)

Return coordinate tensors from coordinate vectors.

Make N-D coordinate tensor expressions for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,…, xn.

Return

tuple of xgenerator expressions.

Parameters
  • e: xexpressions to concatenate

template<class E>
auto xt::diag(E &&arr, int k = 0)

xexpression with values of arr on the diagonal, zeroes otherwise

xt::xarray<double> a = {1, 5, 9};
auto b = xt::diag(a); // => {{1, 0, 0},
                      //     {0, 5, 0},
                      //     {0, 0, 9}}
Return

xexpression function with shape n x n and arr on the diagonal

Parameters
  • arr: the 1D input array of length n

  • k: the offset of the considered diagonal

template<class E>
auto xt::diagonal(E &&arr, int offset = 0, std::size_t axis_1 = 0, std::size_t axis_2 = 1)

Returns the elements on the diagonal of arr If arr has more than two dimensions, then the axes specified by axis_1 and axis_2 are used to determine the 2-D sub-array whose diagonal is returned.

The shape of the resulting array can be determined by removing axis1 and axis2 and appending an index to the right equal to the size of the resulting diagonals.

xt::xarray<double> a = {{1, 2, 3},
                        {4, 5, 6}
                        {7, 8, 9}};
auto b = xt::diagonal(a); // => {1, 5, 9}
Return

xexpression with values of the diagonal

Parameters
  • arr: the input array

  • offset: offset of the diagonal from the main diagonal. Can be positive or negative.

  • axis_1: Axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken.

  • axis_2: Axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken.

template<class E>
auto xt::tril(E &&arr, int k = 0)

Extract lower triangular matrix from xexpression.

The parameter k selects the offset of the diagonal.

Return

xexpression containing lower triangle from arr, 0 otherwise

Parameters
  • arr: the input array

  • k: the diagonal above which to zero elements. 0 (default) selects the main diagonal, k < 0 is below the main diagonal, k > 0 above.

template<class E>
auto xt::triu(E &&arr, int k = 0)

Extract upper triangular matrix from xexpression.

The parameter k selects the offset of the diagonal.

Return

xexpression containing lower triangle from arr, 0 otherwise

Parameters
  • arr: the input array

  • k: the diagonal below which to zero elements. 0 (default) selects the main diagonal, k < 0 is below the main diagonal, k > 0 above.