Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
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
12namespace Halide {
13
14class FuncRef;
15
16/** Create a small array of Exprs for defining and calling functions
17 * with multiple outputs. */
18class Tuple {
19private:
20 std::vector<Expr> exprs;
21
22public:
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
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
#define HALIDE_NO_USER_CODE_INLINE
Definition Util.h:47
A fragment of front-end syntax of the form f(x, y, z), where x, y, z are Vars or Exprs.
Definition Func.h:491
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition Tuple.h:18
const std::vector< Expr > & as_vector() const
Treat the tuple as a vector of Exprs.
Definition Tuple.h:63
Tuple(const Expr &a, const Expr &b, Args &&...args)
Construct a Tuple from some Exprs.
Definition Tuple.h:48
Expr & operator[](size_t x)
Get a reference to an element.
Definition Tuple.h:29
Tuple(const FuncRef &)
Construct a Tuple from a function reference.
Tuple(Expr e)
Construct a Tuple of a single Expr.
Definition Tuple.h:41
HALIDE_NO_USER_CODE_INLINE Tuple(const std::vector< Expr > &e)
Construct a Tuple from a vector of Exprs.
Definition Tuple.h:54
Expr operator[](size_t x) const
Get a copy of an element.
Definition Tuple.h:35
size_t size() const
The number of elements in the tuple.
Definition Tuple.h:24
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
A fragment of Halide syntax.
Definition Expr.h:258
#define user_assert(c)
Definition test.h:10