Halide
Lambda.h
Go to the documentation of this file.
1 #ifndef HALIDE_LAMBDA_H
2 #define HALIDE_LAMBDA_H
3 
4 #include "Func.h"
5 #include "Var.h"
6 
7 /** \file
8  * Convenience functions for creating small anonymous Halide
9  * functions. See test/lambda.cpp for example usage. */
10 
11 namespace Halide {
12 
13 /** Create a zero-dimensional halide function that returns the given
14  * expression. The function may have more dimensions if the expression
15  * contains implicit arguments. */
16 inline Func lambda(const Expr &e) {
17  Func f("lambda" + Internal::unique_name('_'));
18  f(_) = e;
19  return f;
20 }
21 
22 /** Create a 1-D halide function in the first argument that returns
23  * the second argument. The function may have more dimensions if the
24  * expression contains implicit arguments and the list of Var
25  * arguments contains a placeholder ("_"). */
26 inline Func lambda(const Var &x, const Expr &e) {
27  Func f("lambda" + Internal::unique_name('_'));
28  f(x) = e;
29  return f;
30 }
31 
32 /** Create a 2-D halide function in the first two arguments that
33  * returns the last argument. The function may have more dimensions if
34  * the expression contains implicit arguments and the list of Var
35  * arguments contains a placeholder ("_"). */
36 inline Func lambda(const Var &x, const Var &y, const Expr &e) {
37  Func f("lambda" + Internal::unique_name('_'));
38  f(x, y) = e;
39  return f;
40 }
41 
42 /** Create a 3-D halide function in the first three arguments that
43  * returns the last argument. The function may have more dimensions
44  * if the expression contains implicit arguments and the list of Var
45  * arguments contains a placeholder ("_"). */
46 inline Func lambda(const Var &x, const Var &y, const Var &z, const Expr &e) {
47  Func f("lambda" + Internal::unique_name('_'));
48  f(x, y, z) = e;
49  return f;
50 }
51 
52 /** Create a 4-D halide function in the first four arguments that
53  * returns the last argument. The function may have more dimensions if
54  * the expression contains implicit arguments and the list of Var
55  * arguments contains a placeholder ("_"). */
56 inline Func lambda(const Var &x, const Var &y, const Var &z, const Var &w, const Expr &e) {
57  Func f("lambda" + Internal::unique_name('_'));
58  f(x, y, z, w) = e;
59  return f;
60 }
61 
62 /** Create a 5-D halide function in the first five arguments that
63  * returns the last argument. The function may have more dimensions if
64  * the expression contains implicit arguments and the list of Var
65  * arguments contains a placeholder ("_"). */
66 inline Func lambda(const Var &x, const Var &y, const Var &z, const Var &w, const Var &v, const Expr &e) {
67  Func f("lambda" + Internal::unique_name('_'));
68  f(x, y, z, w, v) = e;
69  return f;
70 }
71 
72 } // namespace Halide
73 
74 #endif //HALIDE_LAMBDA_H
Halide::Var
A Halide variable, to be used when defining functions.
Definition: Var.h:19
Var.h
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::lambda
Func lambda(const Expr &e)
Create a zero-dimensional halide function that returns the given expression.
Definition: Lambda.h:16
Func.h
Halide::Func
A halide function.
Definition: Func.h:667
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Internal::unique_name
std::string unique_name(char prefix)
Generate a unique name starting with the given prefix.