Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Namespaces | Functions
reductions.hpp File Reference

Tensor sums, inner products, and Euclidean norms with explicit result residency. More...

#include <uni20/common/trace.hpp>
#include <uni20/core/scalar_concepts.hpp>
#include <uni20/linalg/backend_selector.hpp>
#include <uni20/linalg/backends/cpu/reductions.hpp>
#include <uni20/linalg/dispatch.hpp>
#include <uni20/linalg/operation_tags.hpp>
#include <uni20/mdspan/concepts.hpp>
#include <uni20/storage/host_storage.hpp>
#include <uni20/tensor/concepts.hpp>
#include <uni20/tensor/tensor.hpp>
#include <cstddef>
#include <type_traits>
#include <utility>
Include dependency graph for tensor/reductions.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  uni20
 

Functions

template<class BackendSelector , class LhsTensor , class RhsTensor >
requires (!TensorView<BackendSelector>) && detail::CompatibleInnerProductTensors<LhsTensor, RhsTensor> && detail::ReductionResultAvailable<tensor_element_t<LhsTensor>, LhsTensor, RhsTensor>
auto uni20::inner_product (BackendSelector &&selector, LhsTensor const &lhs, RhsTensor const &rhs)
 Return a storage-preserving rank-zero Tensor inner product.
 
template<class BackendSelector , MutableRankedMdspanLike< 0 > OutputSpan, class LhsSpan , class RhsSpan >
requires detail::CompatibleInnerProductSpans<LhsSpan, RhsSpan> && std::same_as<typename std::remove_cvref_t<OutputSpan>::value_type, typename std::remove_cvref_t<LhsSpan>::value_type>
void uni20::inner_product (BackendSelector &&selector, OutputSpan &&output, LhsSpan &&lhs, RhsSpan &&rhs)
 Compute an mdspan inner product into a rank-zero output.
 
template<class BackendSelector , MutableScalarTensorView OutputTensor, class LhsTensor , class RhsTensor >
requires detail::CompatibleInnerProductTensors<LhsTensor, RhsTensor> && std::same_as<tensor_element_t<OutputTensor>, tensor_element_t<LhsTensor>>
void uni20::inner_product (BackendSelector &&selector, OutputTensor &&output, LhsTensor const &lhs, RhsTensor const &rhs)
 Compute a tensor view inner product into an existing scalar tensor.
 
template<class LhsTensor , class RhsTensor >
requires detail::CompatibleInnerProductTensors<LhsTensor, RhsTensor> && detail::ReductionResultAvailable<tensor_element_t<LhsTensor>, LhsTensor, RhsTensor>
auto uni20::inner_product (LhsTensor const &lhs, RhsTensor const &rhs)
 Return a storage-preserving rank-zero Tensor inner product using storage policy.
 
template<MutableScalarTensorView OutputTensor, class LhsTensor , class RhsTensor >
requires detail::CompatibleInnerProductTensors<LhsTensor, RhsTensor> && std::same_as<tensor_element_t<OutputTensor>, tensor_element_t<LhsTensor>>
void uni20::inner_product (OutputTensor &&output, LhsTensor const &lhs, RhsTensor const &rhs)
 Compute a tensor view inner product into an existing scalar tensor using storage policy.
 
template<class BackendSelector , class LhsSpan , class RhsSpan >
requires detail::CompatibleInnerProductSpans<LhsSpan, RhsSpan>
auto uni20::inner_product_host (BackendSelector &&selector, LhsSpan &&lhs, RhsSpan &&rhs) -> typename std::remove_cvref_t< LhsSpan >::value_type
 Return an mdspan inner product as a host C++ scalar.
 
template<class BackendSelector , class LhsTensor , class RhsTensor >
requires detail::CompatibleInnerProductTensors<LhsTensor, RhsTensor>
auto uni20::inner_product_host (BackendSelector &&selector, LhsTensor const &lhs, RhsTensor const &rhs) -> tensor_element_t< LhsTensor >
 Return a Tensor inner product as a host C++ scalar through an explicit selector.
 
template<class LhsTensor , class RhsTensor >
requires detail::CompatibleInnerProductTensors<LhsTensor, RhsTensor>
auto uni20::inner_product_host (LhsTensor const &lhs, RhsTensor const &rhs) -> tensor_element_t< LhsTensor >
 Return a Tensor inner product as a host C++ scalar using storage policy.
 
template<class BackendSelector , TensorView InputTensor>
requires (!TensorView<BackendSelector>) && RealOrComplex<tensor_element_t<InputTensor>> && detail::ReductionResultAvailable<make_real_t<tensor_element_t<InputTensor>>, InputTensor>
auto uni20::norm (BackendSelector &&selector, InputTensor const &input)
 Return a storage-preserving real rank-zero Tensor Euclidean norm.
 
template<class BackendSelector , MutableRankedMdspanLike< 0 > OutputSpan, MdspanLike InputSpan>
requires RealOrComplex<typename std::remove_cvref_t<InputSpan>::value_type> && std::same_as<typename std::remove_cvref_t<OutputSpan>::value_type, make_real_t<typename std::remove_cvref_t<InputSpan>::value_type>>
void uni20::norm (BackendSelector &&selector, OutputSpan &&output, InputSpan &&input)
 Compute an mdspan Euclidean norm into a real rank-zero output.
 
template<class BackendSelector , MutableScalarTensorView OutputTensor, TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && std::same_as<tensor_element_t<OutputTensor>, make_real_t<tensor_element_t<InputTensor>>>
void uni20::norm (BackendSelector &&selector, OutputTensor &&output, InputTensor const &input)
 Compute a tensor view Euclidean norm into an existing real scalar tensor.
 
template<TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && detail::ReductionResultAvailable<make_real_t<tensor_element_t<InputTensor>>, InputTensor>
auto uni20::norm (InputTensor const &input)
 Return a storage-preserving real rank-zero Tensor Euclidean norm using storage policy.
 
template<MutableScalarTensorView OutputTensor, TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && std::same_as<tensor_element_t<OutputTensor>, make_real_t<tensor_element_t<InputTensor>>>
void uni20::norm (OutputTensor &&output, InputTensor const &input)
 Compute a tensor view Euclidean norm into an existing real scalar tensor using storage policy.
 
template<class BackendSelector , MdspanLike InputSpan>
requires RealOrComplex<typename std::remove_cvref_t<InputSpan>::value_type>
auto uni20::norm_host (BackendSelector &&selector, InputSpan &&input) -> make_real_t< typename std::remove_cvref_t< InputSpan >::value_type >
 Return an mdspan Euclidean norm as a host C++ scalar.
 
template<class BackendSelector , TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>>
auto uni20::norm_host (BackendSelector &&selector, InputTensor const &input) -> make_real_t< tensor_element_t< InputTensor > >
 Return a Tensor Euclidean norm as a host C++ scalar through an explicit selector.
 
template<TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>>
auto uni20::norm_host (InputTensor const &input) -> make_real_t< tensor_element_t< InputTensor > >
 Return a Tensor Euclidean norm as a host C++ scalar using storage policy.
 
template<linalg::KernelBackendSelector BackendSelector, TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && detail::ReductionResultAvailable<tensor_element_t<InputTensor>, InputTensor>
auto uni20::sum (BackendSelector &&selector, InputTensor const &input)
 Return a storage-preserving full Tensor sum.
 
template<linalg::KernelBackendSelector BackendSelector, TensorView InputTensor, linalg::ReductionAxis FirstAxis, linalg::ReductionAxis... RestAxes>
requires RealOrComplex<tensor_element_t<InputTensor>> && (1 + sizeof...(RestAxes) <= tensor_mdspec_t<InputTensor>::rank()) && detail::ReductionResultAvailable<tensor_element_t<InputTensor>, InputTensor>
auto uni20::sum (BackendSelector &&selector, InputTensor const &input, FirstAxis first_axis, RestAxes... rest_axes)
 Return a storage-preserving Tensor sum over selected axes.
 
template<linalg::KernelBackendSelector BackendSelector, MutableRankedMdspanLike< 0 > OutputSpan, MdspanLike InputSpan>
requires RealOrComplex<typename std::remove_cvref_t<InputSpan>::value_type> && std::same_as<typename std::remove_cvref_t<OutputSpan>::value_type, typename std::remove_cvref_t<InputSpan>::value_type>
void uni20::sum (BackendSelector &&selector, OutputSpan &&output, InputSpan &&input)
 Sum every element of an mdspan into a rank-zero output.
 
template<linalg::KernelBackendSelector BackendSelector, MutableMdspanLike OutputSpan, MdspanLike InputSpan, linalg::ReductionAxis FirstAxis, linalg::ReductionAxis... RestAxes>
requires RealOrComplex<typename std::remove_cvref_t<InputSpan>::value_type> && std::same_as<typename std::remove_cvref_t<OutputSpan>::value_type, typename std::remove_cvref_t<InputSpan>::value_type> && (1 + sizeof...(RestAxes) <= std::remove_cvref_t<InputSpan>::rank()) && (std::remove_cvref_t<OutputSpan>::rank() + 1 + sizeof...(RestAxes) == std::remove_cvref_t<InputSpan>::rank())
void uni20::sum (BackendSelector &&selector, OutputSpan &&output, InputSpan &&input, FirstAxis first_axis, RestAxes... rest_axes)
 Sum selected mdspan axes into an existing lower-rank output.
 
template<linalg::KernelBackendSelector BackendSelector, MutableScalarTensorView OutputTensor, TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && std::same_as<tensor_element_t<OutputTensor>, tensor_element_t<InputTensor>>
void uni20::sum (BackendSelector &&selector, OutputTensor &&output, InputTensor const &input)
 Sum every element of a tensor view into an existing scalar tensor.
 
template<linalg::KernelBackendSelector BackendSelector, MutableTensorView OutputTensor, TensorView InputTensor, linalg::ReductionAxis FirstAxis, linalg::ReductionAxis... RestAxes>
requires RealOrComplex<tensor_element_t<InputTensor>> && std::same_as<tensor_element_t<OutputTensor>, tensor_element_t<InputTensor>> && (1 + sizeof...(RestAxes) <= tensor_mdspec_t<InputTensor>::rank()) && (tensor_mdspec_t<OutputTensor>::rank() + 1 + sizeof...(RestAxes) == tensor_mdspec_t<InputTensor>::rank())
void uni20::sum (BackendSelector &&selector, OutputTensor &&output, InputTensor const &input, FirstAxis first_axis, RestAxes... rest_axes)
 Sum selected device tensor axes into an existing lower-rank tensor.
 
template<TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && detail::ReductionResultAvailable<tensor_element_t<InputTensor>, InputTensor>
auto uni20::sum (InputTensor const &input)
 Return a storage-preserving full Tensor sum using storage policy.
 
template<TensorView InputTensor, linalg::ReductionAxis FirstAxis, linalg::ReductionAxis... RestAxes>
requires RealOrComplex<tensor_element_t<InputTensor>> && (1 + sizeof...(RestAxes) <= tensor_mdspec_t<InputTensor>::rank()) && detail::ReductionResultAvailable<tensor_element_t<InputTensor>, InputTensor>
auto uni20::sum (InputTensor const &input, FirstAxis first_axis, RestAxes... rest_axes)
 Return a storage-preserving Tensor sum over selected axes using storage policy.
 
template<MutableScalarTensorView OutputTensor, TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>> && std::same_as<tensor_element_t<OutputTensor>, tensor_element_t<InputTensor>>
void uni20::sum (OutputTensor &&output, InputTensor const &input)
 Sum every tensor view element into an existing scalar tensor using storage policy.
 
template<MutableTensorView OutputTensor, TensorView InputTensor, linalg::ReductionAxis FirstAxis, linalg::ReductionAxis... RestAxes>
requires RealOrComplex<tensor_element_t<InputTensor>> && std::same_as<tensor_element_t<OutputTensor>, tensor_element_t<InputTensor>> && (1 + sizeof...(RestAxes) <= tensor_mdspec_t<InputTensor>::rank()) && (tensor_mdspec_t<OutputTensor>::rank() + 1 + sizeof...(RestAxes) == tensor_mdspec_t<InputTensor>::rank())
void uni20::sum (OutputTensor &&output, InputTensor const &input, FirstAxis first_axis, RestAxes... rest_axes)
 Sum selected device tensor axes into an existing output using storage policy.
 
template<linalg::KernelBackendSelector BackendSelector, MdspanLike InputSpan>
requires RealOrComplex<typename std::remove_cvref_t<InputSpan>::value_type>
auto uni20::sum_host (BackendSelector &&selector, InputSpan &&input) -> typename std::remove_cvref_t< InputSpan >::value_type
 Return the full mdspan sum as a host C++ scalar.
 
template<linalg::KernelBackendSelector BackendSelector, TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>>
auto uni20::sum_host (BackendSelector &&selector, InputTensor const &input) -> tensor_element_t< InputTensor >
 Return a full Tensor sum as a host C++ scalar through an explicit selector.
 
template<TensorView InputTensor>
requires RealOrComplex<tensor_element_t<InputTensor>>
auto uni20::sum_host (InputTensor const &input) -> tensor_element_t< InputTensor >
 Return a full Tensor sum as a host C++ scalar using storage policy.
 

Detailed Description

Tensor sums, inner products, and Euclidean norms with explicit result residency.