xtensor Logo

INSTALLATION

  • Installation
  • Changelog

USAGE

  • Getting started
  • Expressions and lazy evaluation
  • Arrays and tensors
  • Scalars and 0-D expressions
  • Adapting 1-D containers
  • Operators and functions
  • Views
  • Indices
  • Expression builders
  • Missing values
  • Histogram
  • Random
  • Tensor Rank
  • File input and output
  • Build and configuration
  • Common pitfalls

QUICK REFERENCE

  • Basics
  • Builders
  • Operators
  • Mathematical functions
  • Reductions
  • Views
  • Iterators
  • Manipulation
  • Chunked arrays

API REFERENCE

  • Expressions and semantic
  • Containers and views
  • Iterators
  • Functions and generators
  • IO Operations
  • Mathematical functions
    • Operators and related functions
    • Index related functions
    • Basic functions
    • Exponential functions
    • Power functions
    • Trigonometric functions
    • Hyperbolic functions
    • Error and gamma functions
    • Nearest integer floating point operations
    • Classification functions
    • Reducing functions
    • Accumulating functions
    • NaN functions
  • xshape

DEVELOPER ZONE

  • Compiler workarounds
  • Build and configuration
  • Internals of xtensor
  • Extending xtensor
  • Releasing xtensor

MISCELLANEOUS

  • From numpy to xtensor
  • Notable differences with numpy
  • Closure semantics
  • Related projects
  • Designing language bindings with xtensor
xtensor
  • »
  • Mathematical functions »
  • Operators and related functions
  • View page source

Operators and related functions¶

Defined in xtensor/xmath.hpp and xtensor/xoperation.hpp

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator+” with arguments ((E&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class E1, class E2> auto operator+(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::plus, E1, E2>
- template<class E> auto operator+(E &&e) noexcept -> detail::xfunction_type_t<detail::identity, E>

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator-” with arguments ((E&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- difference_type operator-(const self_type &rhs) const
- difference_type operator-(const self_type &rhs) const noexcept
- difference_type operator-(xfunctor_iterator rhs) const
- template<class E1, class E2> auto operator-(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::minus, E1, E2>
- template<class E> auto operator-(E &&e) noexcept -> detail::xfunction_type_t<detail::negate, E>

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator+” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class E1, class E2> auto operator+(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::plus, E1, E2>
- template<class E> auto operator+(E &&e) noexcept -> detail::xfunction_type_t<detail::identity, E>

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator-” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- difference_type operator-(const self_type &rhs) const
- difference_type operator-(const self_type &rhs) const noexcept
- difference_type operator-(xfunctor_iterator rhs) const
- template<class E1, class E2> auto operator-(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::minus, E1, E2>
- template<class E> auto operator-(E &&e) noexcept -> detail::xfunction_type_t<detail::negate, E>

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator*” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- decltype(auto) operator*() const
- reference operator*() const
- reference operator*() const noexcept
- template<class E1, class E2> auto operator*(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::multiplies, E1, E2>
- value_type operator*() const
template<class E1, class E2>
auto xt::operator/(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::divides, E1, E2>¶

Division.

Returns an xfunction for the element-wise division of e1 by e2.

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
auto xt::operator||(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::logical_or, E1, E2>¶

Or.

Returns an xfunction for the element-wise or of e1 and e2.

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
auto xt::operator&&(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::logical_and, E1, E2>¶

And.

Returns an xfunction for the element-wise and of e1 and e2.

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E>
auto xt::operator!(E &&e) noexcept -> detail::xfunction_type_t<detail::logical_not, E>¶

Not.

Returns an xfunction for the element-wise not of e.

Return

an xfunction

Parameters
  • e: an xexpression

Warning

doxygenfunction: Unable to resolve multiple matches for function “where” with arguments ((E1&&, E2&&, E3&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class E1, class E2, class E3> auto where(E1 &&e1, E2 &&e2, E3 &&e3) noexcept -> detail::xfunction_type_t<detail::conditional_ternary, E1, E2, E3>
- template<class T> auto where(const T &condition)
template<class E>
bool xt::any(E &&e)¶

Any.

Returns true if any of the values of e is truthy, false otherwise.

Return

a boolean

Parameters
  • e: an xexpression

template<class E>
bool xt::all(E &&e)¶

Any.

Returns true if all of the values of e are truthy, false otherwise.

Return

a boolean

Parameters
  • e: an xexpression

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator<” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- bool operator<(const self_type &rhs) const
- template<bool is_const, class CT> bool operator<(const xdummy_iterator<is_const, CT> &lhs, const xdummy_iterator<is_const, CT> &rhs) noexcept
- template<class D> bool operator<(const xbuffer_adaptor_base<D> &lhs, const xbuffer_adaptor_base<D> &rhs)
- template<class E1, class E2> auto operator<(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::less, E1, E2>
- template<class F, class ...CT> bool operator<(const xfunction_iterator<F, CT...> &it1, const xfunction_iterator<F, CT...> &it2)
- template<class F, class IT> bool operator<(const xfunctor_iterator<F, IT> &lhs, const xfunctor_iterator<F, IT> &rhs)
- template<class It, class BIt> bool operator<(const xbounded_iterator<It, BIt> &lhs, const xbounded_iterator<It, BIt> &rhs)
- template<class St, class S, layout_type L> bool operator<(const xiterator<St, S, L> &lhs, const xiterator<St, S, L> &rhs)
- template<class T, class A> bool operator<(const uvector<T, A> &lhs, const uvector<T, A> &rhs)
- template<class T, std::size_t N, class A, bool Init> bool operator<(const svector<T, N, A, Init> &lhs, const svector<T, N, A, Init> &rhs)
- template<class T, std::size_t N> bool operator<(const const_array<T, N> &lhs, const const_array<T, N> &rhs)
- template<class VE, class FE> bool operator<(const xoptional_assembly_storage<VE, FE> &lhs, const xoptional_assembly_storage<VE, FE> &rhs)

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator<=” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class D> bool operator<=(const xbuffer_adaptor_base<D> &lhs, const xbuffer_adaptor_base<D> &rhs)
- template<class E1, class E2> auto operator<=(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::less_equal, E1, E2>
- template<class T, class A> bool operator<=(const uvector<T, A> &lhs, const uvector<T, A> &rhs)
- template<class T, std::size_t N, class A, bool Init> bool operator<=(const svector<T, N, A, Init> &lhs, const svector<T, N, A, Init> &rhs)
- template<class T, std::size_t N> bool operator<=(const const_array<T, N> &lhs, const const_array<T, N> &rhs)
- template<class VE, class FE> bool operator<=(const xoptional_assembly_storage<VE, FE> &lhs, const xoptional_assembly_storage<VE, FE> &rhs)

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator>” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class D> bool operator>(const xbuffer_adaptor_base<D> &lhs, const xbuffer_adaptor_base<D> &rhs)
- template<class E1, class E2> auto operator>(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::greater, E1, E2>
- template<class T, class A> bool operator>(const uvector<T, A> &lhs, const uvector<T, A> &rhs)
- template<class T, std::size_t N, class A, bool Init> bool operator>(const svector<T, N, A, Init> &lhs, const svector<T, N, A, Init> &rhs)
- template<class T, std::size_t N> bool operator>(const const_array<T, N> &lhs, const const_array<T, N> &rhs)
- template<class VE, class FE> bool operator>(const xoptional_assembly_storage<VE, FE> &lhs, const xoptional_assembly_storage<VE, FE> &rhs)

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator>=” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class D> bool operator>=(const xbuffer_adaptor_base<D> &lhs, const xbuffer_adaptor_base<D> &rhs)
- template<class E1, class E2> auto operator>=(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::greater_equal, E1, E2>
- template<class T, class A> bool operator>=(const uvector<T, A> &lhs, const uvector<T, A> &rhs)
- template<class T, std::size_t N, class A, bool Init> bool operator>=(const svector<T, N, A, Init> &lhs, const svector<T, N, A, Init> &rhs)
- template<class T, std::size_t N> bool operator>=(const const_array<T, N> &lhs, const const_array<T, N> &rhs)
- template<class VE, class FE> bool operator>=(const xoptional_assembly_storage<VE, FE> &lhs, const xoptional_assembly_storage<VE, FE> &rhs)
template<class E1, class E2>
std::enable_if_t<xoptional_comparable<E1, E2>::value, bool> xt::operator==(const xexpression<E1> &e1, const xexpression<E2> &e2)¶

Equality.

Returns true if e1 and e2 have the same shape and hold the same values. Unlike other comparison operators, this does not return an xfunction.

Return

a boolean

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
bool xt::operator!=(const xexpression<E1> &e1, const xexpression<E2> &e2)¶

Inequality.

Returns true if e1 and e2 have different shapes or hold the different values. Unlike other comparison operators, this does not return an xfunction.

Return

a boolean

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

Warning

doxygenfunction: Unable to resolve multiple matches for function “equal” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- bool equal(const self_type &rhs) const
- bool equal(const self_type &rhs) const noexcept
- bool equal(const xfunctor_iterator &rhs) const
- bool equal(const xiterator &rhs) const
- template<class E1, class E2> auto equal(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::equal_to, E1, E2>
template<class E1, class E2>
auto xt::not_equal(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::not_equal_to, E1, E2>¶

Element-wise inequality.

Returns an xfunction for the element-wise inequality of e1 and e2.

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
auto xt::less(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) < std::forward<E2>(e2))¶

Lesser than.

Returns an xfunction for the element-wise lesser than comparison of e1 and e2. This function is equivalent to operator<(E1&&, E2&&).

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
auto xt::less_equal(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) <= std::forward<E2>(e2))¶

Lesser or equal.

Returns an xfunction for the element-wise lesser or equal comparison of e1 and e2. This function is equivalent to operator<=(E1&&, E2&&).

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
auto xt::greater(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) > std::forward<E2>(e2))¶

Greater than.

Returns an xfunction for the element-wise greater than comparison of e1 and e2. This function is equivalent to operator>(E1&&, E2&&).

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E1, class E2>
auto xt::greater_equal(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) >= std::forward<E2>(e2))¶

Greater or equal.

Returns an xfunction for the element-wise greater or equal comparison of e1 and e2. This function is equivalent to operator>=(E1&&, E2&&).

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator&” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class E1, class E2> auto operator&(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::bitwise_and, E1, E2>
- xtl::xclosure_pointer<const self_type&> operator&() const &
- xtl::xclosure_pointer<self_type&> operator&() &
- xtl::xclosure_pointer<self_type> operator&() &&

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator|” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class ...OA> auto operator|(const rangemaker<OA...> &rng, const std::ptrdiff_t &t)
- template<class ...OA> auto operator|(const rangemaker<OA...> &rng, const xt::placeholders::xtuph&)
- template<class E1, class E2> auto operator|(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::bitwise_or, E1, E2>
- template<template<class...> class A, class ...AX, class X, xtl::check_concept<is_evaluation_strategy<AX>..., is_evaluation_strategy<X>> = 0> auto operator|(const A<AX...> &args, const A<X> &rhs)
template<class E1, class E2>
auto xt::operator^(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::bitwise_xor, E1, E2>¶

Bitwise xor.

Returns an xfunction for the element-wise bitwise xor of e1 and e2.

Return

an xfunction

Parameters
  • e1: an xexpression or a scalar

  • e2: an xexpression or a scalar

template<class E>
auto xt::operator~(E &&e) noexcept -> detail::xfunction_type_t<detail::bitwise_not, E>¶

Bitwise not.

Returns an xfunction for the element-wise bitwise not of e.

Return

an xfunction

Parameters
  • e: an xexpression

template<class E1, class E2>
auto xt::left_shift(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::left_shift, E1, E2>¶

Bitwise left shift.

Returns an xfunction for the element-wise bitwise left shift of e1 by e2.

Return

an xfunction

Parameters
  • e1: an xexpression

  • e2: an xexpression

template<class E1, class E2>
auto xt::right_shift(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::right_shift, E1, E2>¶

Bitwise left shift.

Returns an xfunction for the element-wise bitwise left shift of e1 by e2.

Return

an xfunction

Parameters
  • e1: an xexpression

  • e2: an xexpression

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments ((E1&&, E2&&)) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- std::ostream &operator<<(std::ostream &out, const edge_items &n)
- std::ostream &operator<<(std::ostream &out, const line_width &n)
- std::ostream &operator<<(std::ostream &out, const precision &n)
- std::ostream &operator<<(std::ostream &out, const threshold &n)
- template<class E1, class E2> auto operator<<(E1 &&e1, E2 &&e2) noexcept -> detail::shift_return_type_t<detail::left_shift, E1, E2>
- template<class E> std::ostream &operator<<(std::ostream &out, const xexpression<E> &e)
template<class E1, class E2>
auto xt::operator>>(E1 &&e1, E2 &&e2) -> detail::shift_return_type_t<detail::right_shift, E1, E2>¶

Bitwise right shift.

Returns an xfunction for the element-wise bitwise right shift of e1 by e2.

Return

an xfunction

See

right_shift

Parameters
  • e1: an xexpression

  • e2: an xexpression

template<class R, class E>
auto xt::cast(E &&e) noexcept -> detail::xfunction_type_t<typename detail::cast<R>::functor, E>¶

Element-wise static_cast.

Returns an xfunction for the element-wise static_cast of e to type R.

Return

an xfunction

Parameters
  • e: an xexpression or a scalar

Next Previous

© Copyright 2021, Johan Mabille, Sylvain Corlay and Wolf Vollprecht.

Built with Sphinx using a theme provided by Read the Docs.