Operator parameter mode examples
Parameters allow operators to be invoked differently in order to yield different results. The parameter mode specifies what should be provided as a value to the parameter when invoking an operator.
The following examples show how to define the parameter mode, how it is used within the operator, and how to provide a value for the parameter when an operator is invoked.
attribute
The attribute parameter mode provides the ability to pass an attribute from the input tuple.
type MyInType = int32 i, int32 j;
type MyOutType = int32 y, int32 z ;
public composite SampleOp(input In0 ; output Out0)
{
param
attribute $inputAttr;
graph
(stream<MyOutType> Out0) as Functor_1 = Functor(In0)
{
output
Out0 : y = $inputAttr + 10, z = $inputAttr * 10 ;
}
}
composite Main
{
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 =
SampleOp(Beacon_2_out0)
{
// Specify which attribute (i or j) should be the inputAttr
// Switching these will yield a different result
param
inputAttr : i ;
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}
15,50
15,50
15,50
15,50
15,50
expression
The expression parameter modes allows for passing a value or an expression to be evaluated to the operator. The first example demonstrates passing a single value to an operator. The second example demonstrates how to pass an expression to be evaluated. When passing either a single value or an expression to be evaluated.
type MyInType = int32 i, int32 j;
type MyOutType = int32 y, int32 z ;
public composite SampleOp(input In0 ; output Out0)
{
param
expression $inputExp;
graph
(stream<MyOutType> Out0) as Functor_1 = Functor(In0)
{
output
Out0 : y = $inputExp + 10, z = $inputExp * 10 ;
}
}
composite Main
{
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 =
SampleOp(Beacon_2_out0)
{
param
inputExp : 100; // single value being passed
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}
110,1000
110,1000
110,1000
110,1000
110,1000
type MyInType = int32 i, int32 j;
type MyOutType = int32 y, int32 z ;
public composite SampleOp(input In0 ; output Out0)
{
param
expression $inputExp;
graph
(stream<MyOutType> Out0) as Functor_1 = Functor(In0)
{
output
Out0 : y = $inputExp + 10, z = $inputExp * 10 ;
}
}
composite Main
{
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 =
SampleOp(Beacon_2_out0)
{
param
inputExp : i + 100 - j;
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}
115,1050
115,1050
115,1050
115,1050
115,1050
function
The function parameter mode allows for passing a function to an operator.
type MyInType = int32 i, int32 j;
type MyOutType = int32 y, int32 z ;
int32 adder(int32 value) {
return value + 10;
}
int32 multiplier(int32 value) {
return value * 10;
}
public composite SampleOp(input In0 ; output Out0)
{
param
function $addFunc;
function $multFunc;
expression $inputExp;
graph
(stream<MyOutType> Out0) as Functor_1 = Functor(In0)
{
output
Out0 : y = $addFunc($inputExp), z = $multFunc($inputExp);
}
}
composite Main
{
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 =
SampleOp(Beacon_2_out0)
{
param
inputExp : i;
addFunc : adder;
multFunc : multiplier;
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}
15,50
15,50
15,50
15,50
15,50
operator
Custom
operator is being passed to the
SampleOp
operator.namespace application ;
type MyInType = int32 i, int32 j;
type MyOutType = int32 y, int32 z ;
public composite SampleOp(input In0 ; output Out0)
{
param
operator $OP;
graph
(stream<MyOutType> Out0) as ParamOp = $OP(In0) {}
}
composite Main
{
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 =
SampleOp(Beacon_2_out0)
{
param
OP: Custom; // Custom operator
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}
type
The type parameter mode allows for passing a type to the operator.
namespace application ;
type MyInType = int32 i, int32 j ;
type MyOutType = int32 y, int32 z ;
public composite SampleOp(input In0 ; output Out0)
{
param
type $paramType ;
graph
(stream<MyOutType> Out0) as ParamOp = Custom(In0)
{
logic
state : $paramType val = 0 ;
}
}
composite Main
{
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 = SampleOp(Beacon_2_out0)
{
param
paramType : int32 ;
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}
namespace application ;
type MyInType = int32 i, int32 j ;
type MyOutType = int32 y, int32 z ;
public composite SampleOp(input In0 ; output Out0)
{
param
type $paramType ;
graph
(stream<MyOutType> Out0) as ParamOp = Custom(In0)
{
logic
state : $paramType val = 0 ;
}
}
composite Main
{
type T = uint64;
graph
(stream<MyInType> Beacon_2_out0) as Beacon_2 = Beacon()
{
param
iterations : 5u ;
output
Beacon_2_out0 : i = 5, j = 0 ;
}
(stream<MyOutType> SampleOp_3_out0) as SampleOp_3 = SampleOp(Beacon_2_out0)
{
param
paramType : T ;
}
() as FileSink_4 = FileSink(SampleOp_3_out0)
{
param
file : "out.txt" ;
}
}