Halide 22.0.0 Halide compiler and libraries

Tuple.h
Go to the documentation of this file.
1#ifndef HALIDE_TUPLE_H
2#define HALIDE_TUPLE_H
3
4/** \file
5 *
6 * Defines Tuple - the front-end handle on small arrays of expressions.
7 */
8#include <vector>
9
10#include "Expr.h"
11
12 namespace Halide {
13
14 class FuncRef;
15
16/** Create a small array of Exprs for defining and calling functions
17 * with multiple outputs. */
18 class Tuple {
19 private:
20 std::vector<Expr> exprs;
21
22 public:
23 /** The number of elements in the tuple. */
24 size_t size() const {
25 return exprs.size();
26 }
27
28 /** Get a reference to an element. */
29 Expr &operator[](size_t x) {
30 user_assert(x < exprs.size()) << "Tuple access out of bounds\n";
31 return exprs[x];
32 }
33
34 /** Get a copy of an element. */
35 Expr operator[](size_t x) const {
36 user_assert(x < exprs.size()) << "Tuple access out of bounds\n";
37 return exprs[x];
38 }
39
40 /** Construct a Tuple of a single Expr */
41 explicit Tuple(Expr e) {
42 exprs.emplace_back(std::move(e));
43 }
44
45 /** Construct a Tuple from some Exprs. */
46 //@{
47 template<typename... Args>
48 Tuple(const Expr &a, const Expr &b, Args &&...args) {
49 exprs = std::vector<Expr>{a, b, std::forward<Args>(args)...};
50 }
51 //@}
52
53 /** Construct a Tuple from a vector of Exprs */
54 explicit HALIDE_NO_USER_CODE_INLINE Tuple(const std::vector<Expr> &e)
55 : exprs(e) {
56 user_assert(!e.empty()) << "Tuples must have at least one element\n";
57 }
58
59 /** Construct a Tuple from a function reference. */
60 Tuple(const FuncRef &);
61
62 /** Treat the tuple as a vector of Exprs */
63 const std::vector<Expr> &as_vector() const {
64 return exprs;
65 }
66};
67
68} // namespace Halide
69
70#endif
user_assert
#define user_assert(c)
Definition: Error.h:233
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
HALIDE_NO_USER_CODE_INLINE
#define HALIDE_NO_USER_CODE_INLINE
Definition: Util.h:47
Halide::FuncRef
A fragment of front-end syntax of the form f(x, y, z), where x, y, z are Vars or Exprs.
Definition: Func.h:494
Halide::Tuple
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition: Tuple.h:18
Halide::Tuple::as_vector
const std::vector< Expr > & as_vector() const
Treat the tuple as a vector of Exprs.
Definition: Tuple.h:63
Halide::Tuple::Tuple
Tuple(const Expr &a, const Expr &b, Args &&...args)
Construct a Tuple from some Exprs.
Definition: Tuple.h:48
Halide::Tuple::operator[]
Expr & operator[](size_t x)
Get a reference to an element.
Definition: Tuple.h:29
Halide::Tuple::Tuple
Tuple(const FuncRef &)
Construct a Tuple from a function reference.
Halide::Tuple::Tuple
Tuple(Expr e)
Construct a Tuple of a single Expr.
Definition: Tuple.h:41
Halide::Tuple::Tuple
HALIDE_NO_USER_CODE_INLINE Tuple(const std::vector< Expr > &e)
Construct a Tuple from a vector of Exprs.
Definition: Tuple.h:54
Halide::Tuple::operator[]
Expr operator[](size_t x) const
Get a copy of an element.
Definition: Tuple.h:35
Halide::Tuple::size
size_t size() const
The number of elements in the tuple.
Definition: Tuple.h:24
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:258