74template<
class Reducer, Expression Operand>
106 reducer.forward(source, result);
140 constexpr type
reduce(type dtype)
const {
145 if (shape.
rank() == 0)
146 throw Exception(
"Cannot reduce scalar tensors");
149 for (
size_t dim = 0; dim < shape.
rank(); ++dim) {
150 if (dim !=
static_cast<size_t>(
axis)) out.
expand(shape[dim]);
178 constexpr type
reduce(type dtype)
const {
183 if (shape.
rank() == 0)
184 throw Exception(
"Cannot reduce scalar tensors");
187 for (uint8_t dimension = 0; dimension < shape.
rank(); ++dimension) {
188 if (dimension !=
static_cast<uint8_t
>(
axis))
189 reduced.
expand(shape[dimension]);
220 constexpr type
reduce(type dtype)
const {
226 for (
size_t dim = 0; dim < shape.
rank(); ++dim) {
227 if (dim !=
static_cast<size_t>(
axis)) {
228 reduced.
expand(shape[dim]);
259 constexpr type
reduce(type dtype)
const {
260 assert(dtype == float32 | dtype == float64 &&
"Integral dtypes not supported.");
266 for (
size_t dim = 0; dim < shape.
rank(); ++dim) {
267 if (dim !=
static_cast<size_t>(
axis)) {
268 reduced.
expand(shape[dim]);
300template<Expression Source>
301constexpr auto argmax(Source&& source,
int axis,
bool keepdim =
false) {
322template<Expression Source>
323constexpr auto argmin(Source&& source,
int axis,
bool keepdim =
false) {
349template<Expression Source>
350constexpr auto sum(Source&& source,
int axis,
bool keepdim =
false) {
353 std::forward<Source>(source)
377template<Expression Source>
378constexpr auto mean(Source&& source,
int axis,
bool keepdim =
false) {
381 std::forward<Source>(source)
A simple generic exception type for the Tannic Tensor Library.
Definition: exceptions.hpp:44
Represents the shape (dimensions) of an tensor-like expression.
Definition: shape.hpp:79
constexpr rank_type rank() const noexcept
Returns the number of dimensions (rank).
Definition: shape.hpp:207
constexpr void expand(size_type size)
Expands the shape's last dimension with a given size.
Definition: shape.hpp:286
Represents the memory strides associated with a tensor shape.
Definition: strides.hpp:87
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:99
Lazy reduction expression.
Definition: reductions.hpp:75
constexpr type dtype() const
Definition: reductions.hpp:87
std::ptrdiff_t offset() const
Definition: reductions.hpp:99
Tensor forward() const
Definition: reductions.hpp:103
constexpr Reduction(Reducer reducer, typename Trait< Operand >::Reference operand)
Definition: reductions.hpp:80
constexpr Shape const & shape() const
Definition: reductions.hpp:91
Reducer reducer
Definition: reductions.hpp:77
constexpr Strides const & strides() const
Definition: reductions.hpp:95
Trait< Operand >::Reference operand
Definition: reductions.hpp:78
Defines core C++20 concepts used throughout the Tannic Tensor Library.
Utilities for index normalization and slicing ranges in the Tannic Tensor Library.
Definition: comparisons.hpp:69
constexpr auto argmax(Source &&source, int axis, bool keepdim=false)
Creates an Argmax reduction.
Definition: reductions.hpp:301
constexpr auto sum(Source &&source, int axis, bool keepdim=false)
Creates a sum reduction.
Definition: reductions.hpp:350
constexpr auto argmin(Source &&source, int axis, bool keepdim=false)
Creates an Argmin reduction.
Definition: reductions.hpp:323
constexpr auto mean(Source &&source, int axis, bool keepdim=false)
Creates a mean reduction.
Definition: reductions.hpp:378
constexpr Index normalize(Index index, Size bound)
Normalize a possibly-negative index into the valid range [0, bound).
Definition: indexing.hpp:87
Definition: buffer.hpp:41
Defines the tannic::Shape class for representing tensor dimensions.
std::decay_t< T > Reference
Definition: traits.hpp:28
Finds the indices of maximum values along an axis.
Definition: reductions.hpp:136
bool keepdim
Definition: reductions.hpp:138
constexpr Shape reduce(Shape const &shape) const
Definition: reductions.hpp:144
int axis
Definition: reductions.hpp:137
void forward(Tensor const &input, Tensor &output) const
constexpr type reduce(type dtype) const
Definition: reductions.hpp:140
Computes the mean along an axis.
Definition: reductions.hpp:255
bool keepdim
Definition: reductions.hpp:257
constexpr type reduce(type dtype) const
Definition: reductions.hpp:259
constexpr Shape reduce(Shape const &shape) const
Definition: reductions.hpp:264
int axis
Definition: reductions.hpp:256
void forward(Tensor const &input, Tensor &output) const
Finds the indexes of minimum values along an axis.
Definition: reductions.hpp:174
bool keepdim
Definition: reductions.hpp:176
void forward(Tensor const &, Tensor &) const
constexpr Shape reduce(Shape const &shape) const
Definition: reductions.hpp:182
int axis
Definition: reductions.hpp:175
constexpr type reduce(type dtype) const
Definition: reductions.hpp:178
Sums tensor values along an axis.
Definition: reductions.hpp:216
constexpr Shape reduce(Shape const &shape) const
Definition: reductions.hpp:224
bool keepdim
Definition: reductions.hpp:218
void forward(Tensor const &input, Tensor &output) const
constexpr type reduce(type dtype) const
Definition: reductions.hpp:220
int axis
Definition: reductions.hpp:217
Core multidimensional tensor class for the Tannic Tensor Library.
Core type system for the Tannic Tensor Library.