Loading...
Searching...
No Matches
Tuple.h
Go to the documentation of this file.
#ifndef HALIDE_TUPLE_H
#define HALIDE_TUPLE_H
/** \file
*
* Defines Tuple - the front-end handle on small arrays of expressions.
*/
#include <vector>
#include "Expr.h"
namespace Halide {
class FuncRef;
/** Create a small array of Exprs for defining and calling functions
* with multiple outputs. */
class Tuple {
private:
std::vector<Expr> exprs;
public:
/** The number of elements in the tuple. */
size_t size() const {
return exprs.size();
}
/** Get a reference to an element. */
Expr &operator[](size_t x) {
user_assert(x < exprs.size()) << "Tuple access out of bounds\n";
return exprs[x];
}
/** Get a copy of an element. */
Expr operator[](size_t x) const {
user_assert(x < exprs.size()) << "Tuple access out of bounds\n";
return exprs[x];
}
/** Construct a Tuple of a single Expr */
explicit Tuple(Expr e) {
exprs.emplace_back(std::move(e));
}
/** Construct a Tuple from some Exprs. */
//@{
template<typename... Args>
Tuple(const Expr &a, const Expr &b, Args &&...args) {
exprs = std::vector<Expr>{a, b, std::forward<Args>(args)...};
}
//@}
/** Construct a Tuple from a vector of Exprs */
explicit HALIDE_NO_USER_CODE_INLINE Tuple(const std::vector<Expr> &e)
: exprs(e) {
user_assert(!e.empty()) << "Tuples must have at least one element\n";
}
/** Construct a Tuple from a function reference. */
Tuple(const FuncRef &);
/** Treat the tuple as a vector of Exprs */
const std::vector<Expr> &as_vector() const {
return exprs;
}
};
} // namespace Halide
#endif
user_assert
#define user_assert(c)
Definition Error.h:219
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::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